Example Code for Arduino-Lamp Control
Last revision 2026/01/06
This article offers an in-depth guide on controlling a lamp using Arduino, featuring hardware preparation, wiring diagrams, and sample code, allowing users to seamlessly integrate and operate the lamp with the Arduino system.
Hardware Preparation
- DFR0457 Gravity: MOSFET Power Controller (SKU:DFR0457 x 1)
- DFRduino UNO R3 with IO Expansion Shield and USB Cable A-B (SKU:DFR0216-2 x 1)
- 24V DC Lamp x1
- DC power supply x1
- M-M/F-M/F-F Jumper wires
Software Preparation
- Development Tool: Arduino IDE (version unspecified). Download link: Arduino IDE
Wiring Diagram

Sample Code
/*
* @DFRobot
* @author Hudianjiang
* @version V1.0
* @date 2016-8-30
*/
const int LampControl=3; //define var
void setup() {
pinMode(LampControl,OUTPUT); // Set pinMode
}
void loop() {
digitalWrite(LampControl,HIGH);//Light up lamp 2s
delay(2000);
digitalWrite(LampControl,LOW);//Turn off lamp 2s
delay(2000);
}
Result
The lamp will blink like an led (This is a demo, we do not suggest you operate your lamp like this continually, since it will reduce the service life.)
Was this article helpful?
