Introduction: Controlling AC Light Using Arduino With Relay Module

Picture of 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

Picture of Components Needed

1) Arduino UNO

2)5V Relay module 220v

3)Ac light

Step 2: Connections

Picture of 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

Picture of 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

Picture of 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

Picture of 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");


Step 7: Watch


yAsk4u (author)2017-11-07

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?

IzamL (author)2017-10-12

i want keep light on for 1 hour and off for 15 min. what sentence i need to change or add?

Hey.Its_RJ (author)IzamL2017-10-28

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

redkcir (author)2017-07-09

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


digitalWrite(2, LOW); // Light turns off


digitalWrite(4, HIGH); // 2nd Yellow light on 1/2 second


digitalWrite(4, LOW); // Light turns off


digitalWrite(6, HIGH); // 3rd Yellow Light on for 1/2 second


digitalWrite(6, LOW); // Light turns off


digitalWrite(8, HIGH); // Green Light on for 4 sec


digitalWrite(8, LOW); // Light turns off


//digitalWrite(10, HIGH); // Solenoid on for 4 seconds


//digitalWrite(10, LOW); // Solenoid turns off


exit(0); //Stop Loop command


deskripta (author)redkcir2017-07-18

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...

redkcir (author)deskripta2017-07-19

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.

alma_t made it! (author)2017-07-19

nice tutorial. helped me to be one step closer to understanding what I need for my project. Thank you

JohanM55 (author)2017-06-04

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!

Yes you can use a single relay. I'm guessing he just happened to have a dual module laying around, but he's only using one relay.

BrookM2 (author)2017-05-30

Thank you, your drawings really helped me put everything together correctly.

SonalU (author)2017-02-03

Hello sir i tried this instructions but it is not working.....please check the connection...arduino to relay board works i suppose since the led of respective relay is working...
And if the wire connected to NO is connected to NC the bulb switches on....but does not blink...please help me as soon as possible.!!!

RajendraS8 (author)SonalU2017-05-16

Were you able to get this to work? If not then do the following:-

1. Connect the COM connection to the live pin.

2. Connect the NO to the end of the plug which will eventually go to the neutral when you plug in the socket.

3. Switch on.

4. Now move your hand or make some movement , this will trigger the PIR sensor to send the DC to NO, which will acts as an electromagnet and this will attract the COM pin to complete the circuit and light should switch it on,,

WaelE13 (author)SonalU2017-02-28

Check your code, leave the wire connected to NO since we want the Arduino to trigger it on when it sends current to the relay. I assume its a problem with the code or your relay maybe damaged

ArduinoElectronics (author)2017-05-05

Hello, thanks for the information but I wanted some help. The voltage in my country UAE ranges from 220v -240v. But the sockets here that we have are 3 pin british sockets while the one which you used is the two pin. I wanted to use the relay module with the water heater coil. Please help me in this project.

Connect the COM connection to the live pin, this will be next to your neutral pin.

Neutral pin can be found out using connector socket by inserting into the pin hole , if it lights up then that is neutral. The one above is the earth pin.

RajendraS8 (author)2017-05-15

I successfully made this, however now I want to connect it directly in my house light . In the above case we used a plug and then kept the mechanical switch manually turned on. But now I don't want to use a plug and not a mechanical switch. Can you tell me how I can do it.

According to me , the COM connection should go directly to the wire coming out of the mains for the house light and the NO connection can remain as shown above.

Let me know whether my understanding is correct.

DanijelK4 (author)2017-05-04

I've made prototype of A/C for my old car with Arduino Nano. I have started learning arduino development yesterday and today I've completed my prototype with temperature info on OLED screen and button interraction. I want to make temperature adjuster for that A/C, but some other time, when I learn more about arduino.

Thanks for this instructable and sorry for bad english ! :D

adil hamid (author)DanijelK42017-05-15

I am confuse send me complete video of the connection 03405439979

adil hamid (author)2017-05-15

How I control on laptop

adil hamid (author)2017-05-10

Send me complete video 03405439979

adil hamid (author)2017-05-09

I want to made it but how

MayankP41 (author)2017-04-19

I have uno r3 card and realay card also i done all connection , but how and from where i operate in pc , is any softare required for it if yes then suggest me fast.

MiretazamC (author)2017-04-16

Why did you need two relays? Can it be done by 1?

YaroslavS8 (author)2017-03-18

Do you switch relay when AC voltage is crossing "0" ?

lokanath mishra (author)2017-02-04

hello sir i have an arduino r3,12v 4 channel relay and a 840 point bread board.i want to connect 2 ceeling fans and 2 tube lights.can u plzzzzzzzz guide me.plzzzz give me the circuit diagram and method how to connect all these.plzzzzz sir.THANK U

WaelE13 (author)lokanath mishra2017-02-28

I might be able to help with that how do you prefer me to send you the directions and steps

SharynelA (author)2017-02-16

What if yo u connect it to normally close? Would it turn the bulb on if the code is digitalwrite(pinx,high)..?

lokanath mishra (author)2017-02-01

sir i am a begineer.i want to connect 2 tube lights and 2 seeling fans using arduino.can u plzzz guide me. i am having arduino uno r3 and all things needed.but dont have idea how to connect with can you please give some of your valuable time?plzz sent me all the idea how to email is please help me.THANK YOU

TimC211 (author)lokanath mishra2017-02-02


lokanath mishra (author)TimC2112017-02-02

no sir im not using translator.

actually i want to make arduino control i need your help.plzzzz sent me all about that project.i want to connect 2 tube lights and 2 seeling fans using arduino.plzzzz sent me the steps and mail id is

thank u sir for your help

TimC211 (author)lokanath mishra2017-02-02

are you using a translater?

SurenderS10 (author)2017-01-19

Helllo, I have a four channel realy. The output of all 4 channels should be connected to the same load. However, I will output only one channel at a time. Thanks in advance.

Jasmeeet Singh (author)2016-06-16

I wanted to connect a ceiling fan and aan AC light with the relay. I have a 2 channel relay module. Can you please tell me what should be connected to the COM pin of relay of the fan? I want to be able to control the fan and light separately.

simply connect the positive trminal of ACsupply to the common and positive side of fan to the NO and negative with the AC Supply


JoeyG34 (author)Joe MontanaR2016-11-18

This is not true. You need to connect one wire to the NO, and the other to the neutral wire of your main supply. It can be done as you describe but then you have two wires in you COM port, one of the main supply and one of the fan. This is not ideal, especially not with higher loads.


christophern59 (author)2017-01-13

Hi! I was looking for some advice in my project. can i use 5V relay module 220V to automatically dim the light instead of SCR. thank you

annamcg (author)2016-11-17

My apologies if it's obvious, but I'm not clear how to connect the light and relay to the wall mains (AC supply). Thank you!

CarstenH3 made it! (author)2016-10-25

Very cool project, simple and easy to follow instructions! Thank you very much! :-)

SpikePlayz. (author)2016-10-24
Hi, I was looking for some advice on my relay project. I can't seem to get it to work, and here's what I can see is happening:

I have the relay module connected through a breadboard to an Arduino MKR1000, which is running a simple wifi web server page that turns an onboard led on and off. From everything I can see, I have it all connected correctly, with 5v on relay to 5v on arduino, gnd to gnd, and the other pin to pin 7. The arduino is clearly giving power to the relay, which is connected to a mains lamp, turning it on. When I take one of the connected pins out, the relay (on COM and NO) switches off, thereby turning the lamp off. So, what I can tell is that it will work, I just can't change the state of the relay through the arduino's code.

Thanks Ostin,


ClaudioO17 (author)2016-10-18

Hey, great post !

Quick question, I have seen that the relay module has 2 outcome ports, is it possible to connect another lamp that will work independently from the first one?

thnsk !

jorgemsp (author)ClaudioO172016-10-22

Hi Claudio,

the happy answer for you is yes you can!

If you look to the relay PCB picture (1st pic.) you will see that there are three red wires connected (VCC, GND, IN1) and one pin left without wire (IN2). So as far as you connect both relays in parallel you can switch the lights independently.

Joseph Baguma (author)2016-08-25

Hello I am Baguma Joseph from Uganda , but we use 240v AC and I love your projects what do I do with our high Voltage reply me

MUHDS8 (author)Joseph Baguma2016-10-14

All you need to do is buy a relay with 240v AC. End of the story

DonP51 (author)Joseph Baguma2016-08-27

220 and 240 is practically the same voltage. The voltage goes up and down through the day and it's more like two ways to call the same thing.

nathanwech (author)2016-09-16

great project i am doing it as my final eee project how ever i would love to control 3 separate lamp using a third party android blue tooth software any advice ?

MUHDS8 (author)nathanwech2016-10-14

Bluetooth? Are sure with that? I think you should better use ir receiver .It is more cheaper

JamesG33 (author)nathanwech2016-09-27

Bluetooth or wifi module boards are both available add ons you can buy that work with Arduino, and it's as simple as this project, just adding one more control module, code, etc. Here's a link to one of many Instructables I found when I googled your question... Which i really need to point out can answer questions for you a lot faster than asking it here or forums... like for real.. i REALLY wonder why people, not just yourself, waste time asking stuff online that have plausable answers to them, when they can just as easily Google it. Hmmmm....

JamesG33 (author)JamesG332016-09-27

I forgot to mention that their are apps you can get that work with both of these modules. Happy Project

About This Instructable




Bio: Hello I'm Ostin.A tyro techie living in India. I love messing around with electronics,Gadgets.
More by ostin jos:Controlling AC appliances through sms-Using Arduino remotely control fan and lightControlling AC light using Arduino with relay moduleDesk lamp hack - DIY  - A Penny Saved!
Add instructable to: