Skip to content

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.



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.


//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);
  digitalWrite(in1, HIGH);
  digitalWrite(in2, LOW);


Yassine View All

Automation and Electrical Engineer, Electronics amateur trying to share my little projects.

One thought on “How to use a relay module with Arduino Leave a comment

Leave a Reply

%d bloggers like this: