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: 5580

Tags: Arduino, Control, Module, Relay, Serial, Tutorial:, of

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

Shannon Bradley and Marcelo Rodrigues are now friends
53 minutes ago
Terry Renner is now a member of GarageLab (arduino, electronics, robotics, hacking)
3 hours ago
Andy S posted a discussion

Arduino MEGA boolean?

Hi everyone,been banging my head against the wall a few days now.i have a small project, where i…See More
8 hours ago
Bobby Marshall posted a video

SELFIE Mirror

Meet the S.E.L.F.I.E., the "The Self Enhancing Live Feed Image Engine". Find out how it works: http://istrategylabs.com/2014/04/take-an-instant-selfie-with-t...
yesterday
GarageLab posted a blog post
yesterday
pj jones posted a status
"Designing an Home Automation Project"
yesterday
Profile Iconpj jones, Robert Kribel and Lars Goldschlager joined GarageLab (arduino, electronics, robotics, hacking)
yesterday
Fontaine Pierre commented on GarageLab's blog post Tutorial: Using GPS Shield as an Anti-Theft Device
"Hi, Is it possible to make a car tracker with this GPS + GSM shield to send a message if limits…"
Friday
GarageLab posted a blog post
Friday
Profile Iconeslam mohamed haredy, Wesley Castillo and Lise Pape joined GarageLab (arduino, electronics, robotics, hacking)
Thursday
Terry Dark left a comment for Beula Isaac
"Hi Beulah, Greetings from down under (Australia) Please tell me about yourself and your interests…"
Apr 9
Terry Dark and Beula Isaac are now friends
Apr 9
GarageLab posted blog posts
Apr 9
GarageLab posted a blog post

Festo's BionicKangaroo gets the hop on energy-efficiency

The BionicKangaroo features pneumatic actuators that provide the jumping power and at the same time…See More
Apr 7
Profile IconAnthony Parker, John Nicosia and Tom Devey joined GarageLab (arduino, electronics, robotics, hacking)
Apr 7
wani sageer posted photos
Apr 6
GarageLab posted a blog post

Using a 3D Printer to Draw Tattoos: InkD

 It’s one thing to allow a professional tattoo artist to ink your arm. It’s another thing…See More
Apr 4
GarageLab posted a blog post

Dispensing Solder Paste With A 3D Printer

There’s a strange middle ground in PCB production when it comes to making a few boards. Dispensing…See More
Apr 3
Duong Nguyen is now a member of GarageLab (arduino, electronics, robotics, hacking)
Apr 3
GarageLab posted blog posts
Apr 1

© 2014   Created by Marcelo Rodrigues.

Badges  |  Report an Issue  |  Terms of Service