KEMBAR78
Arduino Project by Odira | PDF | Relay | Arduino
0% found this document useful (0 votes)
22 views21 pages

Arduino Project by Odira

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views21 pages

Arduino Project by Odira

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 21

TRADE PROJECT

TITLE: AUTOMATIC STREET LIGHT SWITCH COLLEGE: SIAYA INSTITUTE OF


TECHNOLOGY PROJECT CODE: 2601/306
INDEX NUMBER: 7051010463
PRESENTED BY: CATHERINE AKINYI OGOKO
PRESENTED TO: KENYA NATIONAL EXAMINATION COUNCIL FOR PARTIAL
FULLFILLMENT FOR AWARD OF DIPLOMA IN ELECTRICAL ENGINEERING.
CENTRE CODE: 7051010

CENTRE NAME: SIAYA INSTITUTE OF TECHNOLOGY SUPERVISOR: MR GEORGE OGEGA

CONTROLING LIGHTS BY A TEXT SMS USING ARDUINO


An electrically operated switch like a relay is used to turn ON/OFF a load by
allowing the flow of current throughout it. This relay is simply controlled by low
voltage (5V) which is generated by the pins of Arduino So, a relay module
controlling with the Arduino board is very simple. Usually, relays are very
helpful whenever you want to control an electrical circuit with a low-power
signal. There are different kinds of relays used in various applications. This
relay module is powered with 5V which is suitable to use with an Arduino.
Similarly, there are other types of relay modules available that are powered
with 3.3V which are ideal for different microcontrollers like ESP8266, ESP32,
etc. This article discusses an overview of an Arduino relay – working with
applications.

What is Arduino Relay?


Arduino relay definition is; a relay that is used with a microcontroller like the
Arduino to control either high-voltage or low-voltage devices. Actually, a relay
is a switch that is operated electrically through an electromagnet. This
electromagnet is simply triggered through a low voltage like 5V from a
microcontroller & it pulls a relay contact to connect or disconnect a high
voltage-based circuit.

Arduino Relay Circuit Diagram


The Arduino-controlled relay circuit is shown below. This circuit explains to
you how to control a relay with the help of an Arduino. The required
components to build this circuit mainly include the Arduino Board, Resistors –
1K & 10K, BC547 transistor, 6V/12V relay, 1N4007 diode & a 12V fan.
Once the button is pushed then the fan will be switched ON and until the
same button is again pushed, the fan will stay in the same condition.

Arduino
Relay Circuit
Arduino Relay Operation
This circuit works in two cases like turning on/off a load with a relay & a
button. Once the button is pushed then the Arduino board will set pin-2 in
HIGH condition, which means 5 volts on pin-2 of board. So this voltage is
mainly utilized to make the transistor ON. So this transistor will turn ON the
relay & the load-like fan will be powered using the main power supply.

Here to power up the transistor as well as the load, you cannot utilize 5V
directly from the USB because usually, the USB port delivers 100mA only. So
this is not sufficient to activate the relay & the LOAD. So external power
supply from 7V to 12V must use to provide power to the controller board, the
transistor, and the relay.

Here, the load uses its own power supply. For example, if you utilize a light
bulb or fan then you should connect from 110/220V mains otherwise any other
power source.

Arduino Relay Code


Arduino relay switch code for turning on a load with a relay & a button

/* sketch
turn on a fan using a relay and a button
*/
int pinButton = 8;
int Relay = 2;
int stateRelay = LOW;
int stateButton;
int previous = LOW;
long time = 0;
long debounce = 500;
void setup() {
pinMode(pinButton, INPUT);
pinMode(Relay, OUTPUT);
}
void loop() {
stateButton = digitalRead(pinButton);
if(stateButton == HIGH && previous == LOW && millis() – time > debounce) {
if(stateRelay == HIGH){
stateRelay = LOW;
} else {
stateRelay = HIGH;
}
time = millis();
}
digitalWrite(Relay, stateRelay);
previous == stateButton;
}

Turn OFF the relay with a delay


You can use the following code example to introduce a delay within the circuit.
So, the “stayON” variable is utilized to delay() the program execution within
the preferred amount of time. Here, once the button is pushed then the relay
will be turned ON & after five seconds the relay will be turned OFF.

Code for turning off a load with a relay & a button.


int pinButton = 8;
int Relay = 2;
int stateRelay = LOW;
int stateButton;
int previous = LOW;
long time = 0;
long debounce = 500;
int stayON = 5000; //stay on for 5000 ms
void setup() {
pinMode(pinButton, INPUT);
pinMode(Relay, OUTPUT);
}
void loop() {
stateButton = digitalRead(pinButton);
if(stateButton == HIGH && previous == LOW && millis() – time > debounce) {
if(stateRelay == HIGH){
digitalWrite(Relay, LOW);
} else {
digitalWrite(Relay, HIGH);
delay(stayON);
digitalWrite(Relay, LOW);
}
time = millis();
}
previous == stateButton;
Arduino Relay Wiring Diagram
The Arduino relay wiring with the DC motor is shown below. The main
intention of this wiring is to control a DC motor with the help of a relay and
Arduino. The required components of this wiring mainly include; Uno
Rev3, Relay Module, Dupont wire, USB cable for powering & programming,
Battery, Connector of battery, Screwdriver for connecting wires to the module,
and DC motor.
Specifications:
The Arduino relay specifications include the following.
 It is controllable with digital output.
 It is compatible with any 5V microcontroller like Arduino.
 Rated through-current is 10A for NO and 5A for NC.
 The control signal is TTL level.
 Maximum switching voltage is 250VAC or 30VDC.
 The maximum switching current is 10A.
 Its size is 43mm x 17mm x 17mm.
Arduino Relay Module
These modules are available with additional components & circuitry on a
board. These modules are mainly used due to many reasons like the
following.

 These modules are very easy to use.


 They include the required drive circuitry.
 Some relay modules come with an LED indicator to indicate the status of
the relay.
 It saves more time for prototypes.
The relay module includes different pins which are discussed below.

Relay Module Pin Diagram


 Pin1 Signal pin (Relay Trigger): This input pin is used to activate the relay.
 Pin2 (Ground): This is a ground pin.
 Pin3 (VCC): This input supply pin is used to power the relay coil.
 Pin4 (Normally Open): This is the relay’s NO (Normally open) terminal.
 Pin5 (Common): This is the relay’s common terminal.
 Pin6 (Normally Closed): This is the Normally closed (NC) terminal of the
relay.
Step1: Wiring of Arduino board & the relay board
 Take a dupont cable and one end of this cable to PIN 7 (Digital PWM)
of the controller board and connect the remaining end of the cable to
the Signal PIN of the relay module.
 Now we need to make a connection between the 5V pin of Arduino and the
relay module’s positive (+) pin.
 Connect the GND pin of Arduino to the relay module’s negative (-) pin.
 Now the connections between UNO board & relay module are completed.
Step2: Relay board wiring to the Supply & the load
 Connect the 9V battery’s positive (+ve) terminal to the Normally Open
terminal of the relay module.
 Connect the Common terminal of the Relay module to the DC motor’s
Positive (+ve) terminal.
 Connect the battery’s negative (-) terminal to the DC motor.
Step 3: Now complete How to utilize a Relay with Arduino
wiring diagram.
 When PIN 7 of the Arduino toggles, the relay switches between both the
ON & OFF conditions. The Arduino code for this wiring is given below.
 For every second, this circuit toggles the relay ON & OFF. In real-time-
based applications, this relay can be used to switch ON a light once you
detect a motion and also to switch ON the motor once the level of the water
is under a fixed range.

A
rduino Relay Wiring
Code
#define RELAY_PIN 7
void setup() {
// initialize digital pin RELAY_PIN as an output.
pinMode(RELAY_PIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(RELAY_PIN, HIGH); // turn the RELAY on
delay(1000); // wait for a second
digitalWrite(RELAY_PIN, LOW); // turn the RELAY off
delay(1000); // wait for a second
}
Now Open Arduino IDE -> Copy & paste the following Arduino code within the
Arduino Editor tab. Now Arduino board needs to connect to the PC with the
help of the USB cable and program the Arduino board.

What is Relay SPDT Arduino?


SPDT Relay is an electromagnetic switch, used to control the AC devices with
a small DC current of an Arduino board.
How Many Relays Can An Arduino Control?
An Arduino board controls up to 20 relays because a relay connected to an
Arduino is equivalent to the number of analog pins (6-pins) and digital pins
(14-pins) in an Arduino

What is a Relay Module used for?


Relay modules are capable of handling loads up to 10 Amps. These are Ideal
for different devices such as passive infrared detectors & other sensors.
These modules are used with Arduino & other microcontrollers.

What Does a Relay Do in an Electrical Circuit?


A relay is an electrically operated switch used to open & close electrical
circuits by simply getting electrical signals from external sources. Once an
electrical signal is received then it transmits to other devices by simply turning
ON & OFF the switch.

Thus, this is an overview of an Arduino relay and its working. This module
is a very convenient board to use that can be utilized mainly for controlling
high voltage and high current loads like solenoid valves, motors, AC loads &
lamps. This rely is used to interface with microcontrollers like an Arduino, PIC,
etc. Here is a question for you, what is the function of an Arduino Board?

GSM Module Sim900A and Arduino to


Control Relay Module Through SMS

Introduction: GSM Module Sim900A and


Arduino to Control Relay Module Through
SMS
Home control devices are common these days due to fast life style,
moreover it depends on the user's interest which system suits his
needs, some prefer to use GSM command control and other uses Wi-
Fi internet devices, at the end each one of us has a specific demand
for a system. GSM control systems are used for long range
communication with devices, additionally GSM network reaches most
of the public places this type of connectivity is preferred in many
cases.

However, in this topic the system will integrate GSM module sim900a
with Arduino Uno in order to control a relay module using SMS
messages. This system can be used to control any electrical or
electronic equipment in a house, farm or any business place. The
relay module has a capability to withstand certain current limit
depends on the type (note to select a proper one to your application).

Supplies

1. Power supply (12V DC adapter)


2. Arduino Uno
3. GSM Module SIM900A
4. Relay module
5. Small Bread board
6. Links

Step 1: System Block Diagram


The system block diagram shown in the figure shows the
interconnection between all units, furthermore the power source is the
12V adapter which supplies the power to the Arduino and then it
provides the 5 volt to the rest of the circuit, because SIM900 requires
sufficient power to connect to the network the power rating of the
adapter shall be in the spec (1.5 A or higher) I used 12V @ 3 Amp
adapter and worked well.

The connection between the Arduino and GSM is a soft serial pins 9
and 8 as shown in the table above, meanwhile the relay IN is
connected to pin 6. Remember that all GRD shall be shared for all
units. The TX/RX in the sim900 are positioned under 5T/5R in the
middle pins.

Step 2: Concept of Operation


The system controls the relay through SMS messages, each SMS
contains a desired request by the user, which can be ON/OFF/STATE.
After the system is powered the GSM will try to establish a connection
with the network (normally it takes less than one minute). Next the
system is ready when the GSM blinks once every two seconds, now
the system is ready. The relay changes the state once the GSM is
connected to the network, after that send SMS ON to the system the
relay will change the state to ON and contact the circuit, then send
SMS OFF to switch off the relay. Moreover, to know the state of the
system send the command STATE the system will repay with ON or
OFF. The system can be configured as normally open or normally
closed, also the SMS can be configured to add more characters to
avoid mistake reception of other SMS.

SMS commands

ON to contact the relay with HIGH

OFF to disconnect the relay with LOW

STATE to check if the system is ON or OFF

Step 3: Step One Power Connection


Initially link the 5V and GND output from Arduino and place both
connections on the breadboard lines, after that connect VIN and GND
to the reset of the components by connecting them to the breadboard
voltage and ground lines.

Step 4: Step Two Connections and SIM Card


The second step it to connect the reset of the links to the circuit, by
connecting TX and RX from the sim900a to the Arduino and connect
IN from the relay module to the Arduino. Follow the figure as the links
are specified in the table in the system block diagram section. After
that insert the SIM card in the GSM sim900, make sure the card is
properly fit in the slot and it does not have PIN number, also it shall
have enough balance to send SMS.

Step 5: Coding
The coding process starts by connecting the Arduino Uno to the
computer at this point do not connect the SIM900 power, then
download the software serial library through scrolling to sketch include
library then manage libraries after that type in Software Serial and
download the latest version. Finally copy the code below and make
the changes on the message and contact number note to include
international code.

The code is simple as its shown below, copy and past in the IDE
#include<softwareSerail.h> //software serial library for serial
communication between Arduino & sim900 GSM

SoftwareSerial mySerial(8, 9);//connect TX pin of GSM to pin 8 of


Arduino && Rx pin of GSM to pin no 9

int REY = 6; // relay output

String message;

String lampState = "HIGH";// Create a variable to store Lamp state

void setup() {

mySerial.begin(9600); // Setting the baud rate of GSM Module

delay(20000);

mySerial.println("AT+CMGF=1"); // set text mode

delay(1000);

mySerial.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a


live SMS

pinMode(REY, OUTPUT);

digitalWrite(REY, LOW);

delay(100);

void loop() {

if (mySerial.available() > 0) {

message = mySerial.readString(); }
if (message.indexOf("ON") > -1) {

digitalWrite(REY, HIGH);

lampState = "on"; }

if (message.indexOf("OFF") > -1) {

digitalWrite(REY, LOW);

lampState = "off"; }

if (message.indexOf("STATE") > -1) {

mySerial.println("AT+CMGS=\"+9XXXXXXXXX\"\r"); // replace XXX...


with your number with country code delay(1000);

mySerial.println("Relay is "+ lampState);// Message content

delay(1000);

mySerial.println((char)26);// ASCII code of CTRL+Z

delay(100); }

Step 6: Final Testing


At this stage the system is ready to be tested, first reconnect the
power back to the sim900, then use the adapter to power the Arduino.
Then power on the system and wait until the GSM pairs with the
network. First send SMS ON to the system and notice the change in
behavior on the relay module, then send SMS OFF to the system and
check out the change in the relay module. In order to check the state
of the system send SMS STATE and the system will relay by relay on
or off.

This system is easy to be configured and it is very useful to control


remotely any electric or electronic device. I hope you enjoy this topic
and if you have any issue please do not hesitate to send.

All the best

You might also like