AqibJLCPCB
Published

Relay Module interfacing with Arduino – Arduino Relay Module

In this article, we are going to control an Arduino relay module. We will control two different devices using it.

BeginnerFull instructions provided1 hour12,604
Relay Module interfacing with Arduino – Arduino Relay Module

Things used in this project

Hardware components

JLCPCB Customized PCB
JLCPCB Customized PCB
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Kicad

Story

Read more

Schematics

relay_arduio_ac_device_Yqij7heqbE.png

Code

Code snippet #1

Plain text
int relay_pin = 8;
int led_pin = 13;

void setup(){ 
  pinMode(relay_pin,OUTPUT);
  pinMode(led_pin,OUTPUT);  
digitalWrite(led_pin,HIGH);}

void loop(){
  digitalWrite(relay_pin,HIGH);
  delay(5000);
  digitalWrite(relay_pin,LOW);
  delay(5000);
}

Code snippet #2

Plain text
int relay_pin = 8;

void setup(){ 
  pinMode(relay_pin,OUTPUT);
}

void loop(){
  digitalWrite(relay_pin,HIGH);
  delay(5000);
  digitalWrite(relay_pin,LOW);
  delay(5000);
}

Code snippet #3

Plain text
int relay1_pin = 6;
int relay2_pin = 7;
int relay3_pin = 8;
int relay4_pin = 9;

void setup() {
  pinMode(relay1_pin, OUTPUT);
  pinMode(relay2_pin, OUTPUT);
  pinMode(relay3_pin, OUTPUT);
  pinMode(relay4_pin, OUTPUT);

  digitalWrite(relay1_pin, LOW);
  digitalWrite(relay2_pin, LOW);
  digitalWrite(relay3_pin, LOW);
  digitalWrite(relay4_pin, LOW);
}

void loop() {
  digitalWrite(relay1_pin, HIGH);
  delay(1000);
  digitalWrite(relay2_pin, HIGH);
  delay(1000);
  digitalWrite(relay3_pin, HIGH);
  delay(1000);
  digitalWrite(relay4_pin, HIGH);
  delay(1000);
  
  digitalWrite(relay4_pin, LOW);
  delay(1000);
  digitalWrite(relay3_pin, LOW);
  delay(1000);
  digitalWrite(relay2_pin, LOW);
  delay(1000);
  digitalWrite(relay1_pin, LOW);
  delay(1000);
}

Credits

Aqib

Aqib

21 projects • 276 followers
JLCPCB

JLCPCB

73 projects • 42 followers
JLCPCB, is the largest PCB and PCB Assembly prototype enterprise in Asia. Coupon code "JLCPCBcom" for all and permanantly available.

Comments