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

Software Preparation

  • Development Tool: Arduino IDE (version unspecified). Download link: Arduino IDE

Wiring Diagram

DFR0457 Gravity: MOSFET Power Controller Connection 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?

TOP