Example Code for Arduino-Relay Control

Last revision 2026/01/06

Hardware Preparation

Software Preparation

Wiring Diagram

Sample Code

/*
* @DFRobot
* @author Gangxiao Xue
* @version  V1.0
* @date  2019-11-27
*/
const int PIN=7;                   //define var
void setup() {
  pinMode(PIN,OUTPUT);            // Set pinMode
}
void loop() {
  digitalWrite(PIN,HIGH);//Light up lamp 2s
  delay(2000);
  digitalWrite(PIN,LOW);//Turn off lamp 2s
  delay(2000);
}     

Was this article helpful?

TOP