Tutorial: Arduino Serial Control of Relay Module

On this tutorial, we will show how to use Arduino or any compatible board (Garagino in this case) to control a Relay Module using Serial communication with the PC.

Attention: You must be very careful while using relay modules connected to AC power plug. Please be careful to avoid electrical shock!

Material List:

  • 1 x Arduino or compatible board (AVR board)
  • 1 x USB/Serial Converter
  • 1 x Relay Module
  • 1 x Lamp. 127V with cable and plugs.
  • 1 x Breadboard
  • Jumpers

 

1º Cut one of the wires of AC cable. Connect one side to the C (Common) and connect the other to NO (Normally Open) from Relay Modulo (Picture 1).

Picture 1

2º Connect USB/Serial Converter 5V pin to Vcc bus on the breadboard (Prefer red jumpers);

3º Connect USB/Serial Converter GND pin to GND bus GND on the breadboard (Prefer black jumpers).

4º Connect the coupling capacitor (100nF between the USB/Serial Conversor pin DTR and the reset on the AVR board).

5º Connect breadboard Vcc bus to: AVR board Vcc, USB/Serial module CTS and Vcc pins (Prefer Red jumpers).

6º Now connect the following pins to breadboard GND: AVR board GND and Relay Module GND (Prefer Black jumpers).

7º Connect USB/Serial TX pin to AVR board RX Pin (Blue jumper on Picture 2).

8º Connect USB/Serial RX pin to AVR board TX Pin (Orange jumper on Picture 2).

Picture 2

9º For the last step, connect Relay Module input IN to Arduino's D8 pin or the correspondent on AVR board (Garagino in this case). Green Connection on Picture 3.

Picture 3

Verify all connections. Link an USB cable between PC and USB/Serial Converter and AC plug on power.

Copy and paste this Sketch in the Arduino's IDE:

char serialin;

#define relay 8
void setup() {

  //Begin Serial Comunication(configured for 9600baud)
  Serial.begin(9600);
  //pin relay as OUTPUT
  pinMode(relay, OUTPUT);
  //Relay
  digitalWrite(relay,LOW);
  }

void loop() {
  //Verify connection by serial
  while (Serial.available() > 0) {
    //Read Serial data and alocate on serialin
    serialin = Serial.read();
    //If serialin is equal as 'o' or 'O' LAMP OFF
    if (serialin == 'o' || serialin =='O'){ // Two Pipeines(||) to make a boolean OR Comparission
      digitalWrite(relay,LOW);
      }
    /*serialin is equal as 'c' or C */
    else if (serialin == 'c' || serialin =='C'){ // Two Pipeines(||) to make a boolean OR Comparission
      digitalWrite(relay,HIGH);
      }
      Serial.println(serialin);
  }
}

Configure Serial Monitor to 9600 Baud. Send by Serial Monitor letter ”c” or “C” and press Enter. The relay will be close (Lamp ON). Now send “o” or “O” and it will be open(Lamp OFF).

Thanks for following this tutorial! If you have any question, please comment.

Views: 22170

Comment by نهاد عبدالله حسين السلمان on January 17, 2013 at 12:56am

Hello - all up to us the information, programs and projects is a wonderful grandfather and wholesome

Comment by نهاد عبدالله حسين السلمان on January 17, 2013 at 1:18am

Hi - I'm the designer who designed the masterpiece known Arduino google drive  my drive  Works like a Joker, a paper multiple areas is really wonderful and thank you for the designer

Comment by نهاد عبدالله حسين السلمان on January 17, 2013 at 1:20am

Printed board

Comment

You need to be a member of GarageLab (arduino, electronics, robotics, hacking) to add comments!

Join GarageLab (arduino, electronics, robotics, hacking)

Latest Activity

m fluer is now a member of GarageLab (arduino, electronics, robotics, hacking)
Saturday
Craig P. Summers commented on GarageLab's blog post A Robot Controlling a Switch
"True automation is becoming more frequent in todays life as automated home helps home homeowners in…"
Saturday
Profile Icongeorge villaflor, Steve Kotlowski, John McClure and 1 more joined GarageLab (arduino, electronics, robotics, hacking)
Friday
Anthony M. Hagy commented on GarageLab's blog post Project Sunroof
"Great project idea. The roof is an important part of home, roof contractor plays an important role…"
Friday
Anthony M. Hagy commented on GarageLab's blog post Apple Aims to Test Self-Driving Cars at Military Base
"Nice Post. Thank you for sharing."
Friday
Profile IconMarcus Ataide, abdelrahman taher, Anthony M. Hagy and 4 more joined GarageLab (arduino, electronics, robotics, hacking)
May 16
Profile IconKeshava DEv, bryan mcfadden and babbelkwebbel joined GarageLab (arduino, electronics, robotics, hacking)
May 9
Rosa Yu is now a member of GarageLab (arduino, electronics, robotics, hacking)
May 6
Profile IconMarvin Wright and chaudhari vipin vasudev joined GarageLab (arduino, electronics, robotics, hacking)
May 4
Marcelo Rodrigues replied to Peter Davies's discussion Anyone got stock of Garagelabs automation board
"Peter, I will talk them to check if they can produce more units and make available on their…"
May 3
Brian B. Feaster commented on GarageLab's blog post Information Trade Between Cars by Wi-Fi
"I like this idea of information trade between cars by the WI-Fi . This would contribute in reducing…"
May 2
Peter Davies replied to Peter Davies's discussion Anyone got stock of Garagelabs automation board
"Hi Marcello I have bought all of Seeeds stock in two purchases - 8 units in all.  When I asked…"
May 2
Profile Icontarun patel, Enrique S. Perez Rodriguez, K Fiore and 5 more joined GarageLab (arduino, electronics, robotics, hacking)
May 2
Marcelo Rodrigues replied to Peter Davies's discussion Anyone got stock of Garagelabs automation board
"Peter, You can buy them on…"
May 2
Rob Lambert joined Marcelo Rodrigues's group
Thumbnail

Arduino

Group for the Arduino communitySee More
Apr 30
Sardar Tamoor commented on Thulana Vimukthi's blog post GPS GUIDED AUTONOMOUS ROBOT
"can you plz help me on my project !!! its basically obstacle avoidance in dynamic environment and…"
Apr 27
Sardar Tamoor commented on Thulana Vimukthi's blog post GPS GUIDED AUTONOMOUS ROBOT
"can you plz help me on my project !!! its basically obstacle avoidance in dynamic environment and…"
Apr 27
Sardar Tamoor is now a member of GarageLab (arduino, electronics, robotics, hacking)
Apr 26
Peter Davies posted a discussion

Anyone got stock of Garagelabs automation board

HiI have a requirement for 11 automation boards and have been able to source 8,  does anyone have a…See More
Apr 25
Profile IconGuilherme Barros, Rob Lambert and kevin parr joined GarageLab (arduino, electronics, robotics, hacking)
Apr 22

© 2016   Created by Marcelo Rodrigues.   Powered by

Badges  |  Report an Issue  |  Terms of Service