Introduction: Controlling AC Light Using Arduino With Relay Module
Hello friends! I'm Ostin,I ll demonstrate how to control a AC light with Arduino using relay module.It is a simple project and also very dangerous as we are going to deal with high voltage 220v . Do not attempt if you are a amateur in dealing with high voltage.
I'll answer few basic questions, which hits when you are novice!
Why to use relay for controlling AC light?
AC is alternating current 220v (india) which powers the ac lights. Arduino cannot control high volt n amp, but a relay can do this job, which is the sole design of it. so we are using relay as switch to control high power devices.
What is NO NC and COM in relay?
C = Common Connection
NC = Normally Closed Connection
NO = Normally Open Connection
I have explained NO NC COM elaborately in step 3, refer it -if you feel it bit confusing.
I'm going to use NO Normally Open Connection.
Step 1: Components Needed
1) Arduino UNO
2)5V Relay module 220v
3)Ac light
Step 2: Connections
Connect pin 7 arduino to IN 1 relay module
5v to vcc of relay module
gnd to gnd of relay module
Step 3: NC COM NO of Relay
COM - Common connection--> it is the center terminal, It is hot as power to the load is connected at this terminal.
NO Normally open ---> It acts like a switch,since it is open - there will be no contact between COM and NO, When we trigger the relay module, it connects to COM by the electromagnet inside the relay and supply to the load is provided,which powers up the light.Thus the circuit is closed until we trigger the state to low in relay.
NC Normally closed---->It is always in contact with COM, even when relay is not powered.when we trigger the relay it opens the circuit, so the connection is lost. it behaves just opposite to NO.
im using NO connection,but here in this type of relay "HIGH" state in code turns off the relay(opens the circuit). "LOW" state in code turns on the relay.
Step 4: Relay Connections
We are using Normally open connection in relay. so that we can trigger on and off the light .
Hot line from supply is connected to COM
Supply line to the Ac light is connected to NO
Gnd or - or other terminal in light is connected directly.
Step 5: Circuit Diagram
Step 6: Code
digitalWrite(RELAY1,LOW); // Turns ON Relays 1
Serial.println("Light ON");
delay(2000); // Wait 2 seconds
digitalWrite(RELAY1,HIGH); // Turns Relay Off
Serial.println("Light OFF");
delay(2000);
Step 7: Watch

Participated in the
Arduino Contest
196 Comments
Question 1 year ago
Can you please tell me what AC-Source and AC-Light you are using?
Question 2 years ago on Introduction
Hello, hope you doing great.i need your help please. I need to switch on an A c bulb with wall switch (manually) and when
i forget to switch it off, It has to automatically switch off by checking the occupancy
4 years ago
PLEASE READ THIS
First of all: nice tutorial. But there are a few errors. I made the same mistakes and found out the hard way.
(1) Don't power the relay through the arduino. The arduino can't handle currents high enough to power a relay. You may be lucky if you have your power source wired up directly (i.e. it is connected to the 5V pin). However, most people use USB. In that case there are filters applied, in order to remove some of the ripple. Those filters can't handle the high currents required for the relay for long sustained periods of time. Thus, you'll be greeted with a freshly baked arduino after a few days of operation. A proper way to solve this is, is by using a transistor, which actually brings me to my second point.
(2) Ever wondered (like me) why you would need a VCC line in addition to the input line? That's because there's actually a transistor on the relay PCB. In case you connect the input line to ground, current will flow from the VCC pin to the relay and the relay will switch. In case it's not connected to ground, the opposite happens. This means that there is no power from the arduino required at all: either connect the input pin to ground, or leave it unconnected, but you shouldn't put a voltage on that pin. So how do we do this? To connect a pin to ground, use pinMode(pin, OUTPUT) and digitalWrite(pin, LOW). To disconnect a pin, you must set it to INPUT, with no pullup (i.e. LOW): pinMode(pin, INPUT), digitalWrite(pin, LOW).
Cheers
Reply 3 years ago
can you please upload the circuit diagram for this , it would be very helpful.
Question 3 years ago on Introduction
Application of this circuit
Question 4 years ago
If i want more bulbs then it will parallel connection or not?? Or need more relay to control... Means one relay controls one bulb....
Question 5 years ago on Step 5
Is your power supply to the common 220v? is it possible that i step down the voltage to 12v and connect it to 12v bulbs
Question 5 years ago on Step 7
this circuit can apply with push button ?
Question 5 years ago on Step 4
What if the relay didn't work properly and there is a short circuit..how r we gonna protect our arduino then
Answer 5 years ago
Even though there shouldn't be a problem unless there's physical harm to the relay, using a mechanical relay is not a good idea for such operations. You can use an SSR which has an opto isolator and no physical connections between the control circuit and the actual circuit. That way even if there's a problem with your relay, arduino should be safe
5 years ago
i want keep light on for 1 hour and off for 15 min. what sentence i need to change or add?
Reply 5 years ago
digitalWrite(RELAY1,LOW); // Turns ON Relays 1
Serial.println("Light ON");
delay(3600000); // Wait 1 hour
digitalWrite(RELAY1,HIGH); // Turns Relay Off
Serial.println("Light OFF");
delay(900000); // wait for 15 minutes
Reply 5 years ago
well you need to change the value inside delay();
for ON: change it to delay(3600000); //yes that much make it 1 hour to keep light ON
Tip 5 years ago on Step 4
Watch this Video to Understand how the relay works for NO & NC connections. It makes the concept more clear.
https://www.youtube.com/watch?v=1_YfuH_AcxQ
Question 5 years ago
we would like to on/off the motor 220v AC using mobile by sending a simple message to it with relay & ardunio.
is it possible?
if yes, then circuit connections and program please
5 years ago
I completed the whole setup as prescribed above. When i power my ESP32 board, the IN1 led light on the relay blinks alternatively which tells me the code works, but when I connect a 220 V bulb to the relay it doesn't switch on.
Now if i connect my NC to bulb, the bulb switches on but doesn't blink. The relay LED light is still blinking as per the code. Can you pls help understand what may be the issue?
6 years ago
I have a small problem I hope someone can help with. I have built a race tree (four lights, last light also operates a solenoid to open a gate). For the most part it works well, however when the Arduino is first turned on and when the sketch starts running all the lights and solenoid turn on. I am OK with all the lights, but the solenoid prematurely opens the gate. Right now the solenoid it tied to the last light, but I have a place in the code to add a separate relay just for it. Is there a way to add a relay that doesn't automatically run on start up, but at the end of the run when the go light turns on? I have listed the code I am using:
// Race Tree
// Controlling 4 relay board
// Relays control 110VAC lights
// button on reset restarts tree
// 10 is for optional solenoid start gate
void setup(){
// initialize the digital pin as an output.:
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
pinMode(6, OUTPUT);
pinMode(8, OUTPUT);
pinMode(10, OUTPUT);
}
void loop() {
delay(3000); // All lights turn on when Arduino powered or reset
// This delays for 3 seconds before programed
// light seq. runs.
digitalWrite(2, HIGH); // 1st Yellow Light on for 1/2 second
delay(500);
digitalWrite(2, LOW); // Light turns off
delay(500);
digitalWrite(4, HIGH); // 2nd Yellow light on 1/2 second
delay(500);
digitalWrite(4, LOW); // Light turns off
delay(500);
digitalWrite(6, HIGH); // 3rd Yellow Light on for 1/2 second
delay(500);
digitalWrite(6, LOW); // Light turns off
delay(500);
digitalWrite(8, HIGH); // Green Light on for 4 sec
delay(4000);
digitalWrite(8, LOW); // Light turns off
delay(4000);
//digitalWrite(10, HIGH); // Solenoid on for 4 seconds
//delay(4000);
//digitalWrite(10, LOW); // Solenoid turns off
//delay(3000);
exit(0); //Stop Loop command
}
Reply 6 years ago
maybe you should start with digitalWrite(2,LOW); in setup part of code. That way that pin would be set to low, and wait for the loop function to start the cycle. You coyuld do that for all the pins...
Reply 6 years ago
I actually like all the lights and the solenoid activating the first time the Arduino powers up. It's a good equipment check. Because it is a race timer though I don't want to reset the Arduino every time I start a race, but just run the loop. I have a Stop loop command and just want to re-start the loop with a button. I'm working on adding that button now.
6 years ago
Hi there,
I have a question: If you used only one relay, Why did you use a module with 2 relay? Would I use a only one relay module?
as well I want to know how many lamps Can I turn on/off with one relay module?
Thank you so much!