Hi, welcome to an Arduino tutorial from Robojax. my name is Ahmad Shamshiri
from Canada in this video I'm going to show you how you can
control an AC bulb using Arduino either or doing a Nano, Micro Mega any version
of Arduino to control a relay and then control an AC bulb this can work with
that low trigger and high trigger you can get the code for this by clicking at
the link below the video in the description which will take you to
www.robojax.com/learn/arduion let's get started with this.
now let me explain the module the module that you might purchase will be either
will have this type of Chinese label or English but the functionality and
everything is exactly the same as the power is written in Chinese and here it
shows PWR and SW the switch or in Chinese but actually they are the same
and as you can see we have different ready but exactly 5 volts relay 5 volts
relay and here they have written LOW level trigger and here and here they
have written low level trigger this is VCC this will be connected to 5 volts GND
this is ground or 0 volts so the two powers from your battery will be
connected to here and here and this input is the IN is the signal from your
Arduino that receives and when the power is established this light will turn ON
telling you that this module has power and when the signal comes to control
this relay this LED will turn on Green. Drive this we need a transistor we need
the resistors and also we need a freewheeling diode to protect the relay
from release of the energy from the coil so relay we have three pin one is
normally open NO this is common COM and normally closed NC the wires that you
connect one wire will be here and the other wire will be by default you would
use it here this normally open NOmeans these two wires are not connected they
are open when the relay is energized this will be connected when the it is
de-energized this will be disconnected but sometimes you might want to connect
it to normally closed NC meaning even if there is no power when you connect two wires
they're already connected like that so the two wire will be connected and your
load will be on but when it receives a signal it will be turned off so if you
want to use it that way connect your wire there but in both
cases your middle wire will not change so switch your wells either here or here so
you can get the different result but this is the main one that we will use
the relay width is 17.1 millimeters length of the module is 42.9 or 43 millimeters
depth of the module is seventeen point five millimeters and if you are
interested in weight at weighs twelve point eight grams
Wiring Explained (for UNO)
and help to briefly explain the relay relay has a winding when it receives DC
voltage this coil has a core and this will be magnetized and it will pull down
one of the contacts and in our case where they have three wires or contacts
one is at the top then bottom and there are the middle this is that's why we
call it common COM and this is normally closed NC when there is when the switch is
off there is no energy this is up and the contact is connected with the top so
this is called normally closed NC when we switch when you turn the switch on the
contact goes down and the voltage this is AC and this is a bulb will come and
pass through this and the light will be turned on so this is off and this is on
what we do is in our Arduino that instead of the battery Arduino
will send the signal and this resistor transistor and other components will
turn the relay on in the module this is an easy desktop bulb and this is a power
plug that I connected to the wall and 120/220 volts which will turn on and off now
at this point I've cut one of these two wires at this point and twisted it and
soldered so it can be connected to relay .job of relay is to connect this and the AC
bulb is on or AC load whatever fan you have and disconnected to turn it off so
I will be connecting these two to that relay and here I've connected the two
wires from AC bulb to these 2 pins common COM and normally open NO let me explain
the wiring with Arduino Uno on the module that you can see this VCC is
yellow ground is green at the middle one and then IN is blue and here yellow is
connected to 5 volts ground is connected to the ground GND of Arduino at
this pin and blue is the input to this module have been connected to pin 3
Wiring Explained for Arduino Micro
here's the wiring for Arduino micro yellow or VCC is connected to five volts
which has been labeled five volts the five is on the right side the ground has
been connected to the ground of Arduino micro and the blue is connected to pin 3 here
Pin 3 here
Wiring Explained for Arduino Nano
Here is the wiring for arduino nano the same as Arduino UNO
yellow is connected to 5 volt here the ground pin is connected to the ground GND
here and pin blue is connected to d3 or digital pin 3
Basic Code explained
Let me explain the code this is the basic code the advanced code will come after
this we define a relay pin as pin 3 any other digital pin that you wish you can
assign and this is a loop delay this when the loop runs we have some delays
you can remove this if you remove the command and the loop which I will
explain next inside the setup will you find relay pin the same pin that we have
had this as if I type 3 as an output so this assigns the pin as an output and
immediately we set the initial condition for example if you relay is LOW level
trigger then with a high you can turn it off so we use digitalWrite pin 3 and
high so this will set the initial state of a relay to be turned off. Then we initialize
the serial monitor with 9600 baud and then we print this text and we give the
user for two seconds to read the text. inside the loop digitalWrite relay
relayPin we set that a LOW this will turn the relay ON and we print the text
serial.println and then inside this double quotation we
print our text and then we give it two seconds so the relay will be on for two
seconds then we turn off the relay using digitalWrite (relayPin HIGH I will turn
it off and then you print this text and we give it two seconds for the time to
be HIGH and then we print this so we know the loop have ended and then this
is a delay that we define above one second more will be delay here and the
loop will go and repeat all the tasks over again
Demonstration with Arduino UNO
and here is a demonstration of the code is both advanced or simple one the same
demonstration will work the relay is now connected this is not connected to AC
yet and this is my AC bulb and once I connected make sure never touch here
because this is very dangerous and just leave it like that and make sure you do
not leave this on the metallic surface now this is working I'm just connecting
the AC power and as you can see here the green light is on when the green light
is on the light also turns on
and here to open the serial monitor you can click on tools' serial monitor or
you can press control shift + M or you can click on the right side on this now
we don't see anything here because the serial monitor is initialized with 9600
baud and this will not have the same as you can see here at 115200 let's change
it to 9600 baud and then the text will appear here when the relay is on it
shows this off and then the loop finished now again on off
Demonstration with Arduino Nano
Here is how you select arduino nano click on tool board and select Arduino Nano
and click on tools port and then select the port that you are using with your
device upload the code and here is a demonstration with Arduino Nano
as you can see the relay turns on and off the green light and also the AC bulb
is on and off
Demonstration with Arduino Micro
and here is how you set your Arduino with Arduino micro go to go to tool
boards and scroll down until you see all the Arduino Genuino Micro and
that's it select your port and upload the code here is a demonstration of
Arduino micro that is controlling the relay and AC bulb with the same exact
code
My other related videos
Control 4 relays with Push ON and push off
you
Control 4 AC load or AC bulb with Arduino
Control 8 channel relay with 4x3 keypad with Arduino
Turn on a bulb with Push ON and Push off. When you push, the light turns ON and say ON
Touch ON and Touch OFF bulb
I would like to thank the following Patrons supporters of mine as of August 18, 2019 on Patreon.com
This subtitle is typed and corrected on Mar 09, 2020 by Ahmad Shamshiri
thank you for watching this was how to control an AC bulb using this 5 volt
relay if you liked this video please thumb up 👍 as this will help my video in
the search algorithm of YouTube if you have comment or question posted a
comment section below I try to answer and reply and subscribe we can get
updates of my upcoming videos
you