How to use a relay module with Arduino

 

Hello everyone, this is a tutorial on how to use a relay module with Arduino, here I used an 2 channels relay module with an Arduino Uno, you can use the same thing to control other relay modules with 4 or 6 or plus channels modules, or you can use another Arduino developpement board.

Wiring:

 

Important N.B:

Here I kept the jumper between Vcc and Jd-vcc wich mean that the optocouplers and the coils are wired together and they are powered from the arduino directly, if you are using other sensors in the same time you can have some problems, so you have to remove the jumper and wire JdVcc and the other Gnd from another power source.

Code:

//This is code is to control 2 channels relay module
//It turns on on channel for 3 seconds then turn it off and vice versa
//FB/Youtube: @SurtrTech
int in1 = 2; //Declaring pins used
int in2 = 3;
void setup() {
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
}
void loop() {
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
  delay(3000);
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);
  delay(3000);
}

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: