Controlling AC Light Using Arduino With Relay Module




Introduction: Controlling AC Light Using Arduino With Relay Module

About: Hello I'm Ostin.A tyro techie living in India. I love messing around with electronics,Gadgets.

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


Step 7: Watch

3 People Made This Project!


  • Water Contest

    Water Contest
  • Tiny Home Contest

    Tiny Home Contest
  • Creative Misuse Contest

    Creative Misuse Contest

194 Discussions

this circuit can apply with push button ?

What if the relay didn't work properly and there is a short r we gonna protect our arduino then

1 more answer

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


10 months ago

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

2 replies

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

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


Question 5 months 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


9 months 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?

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


2 replies

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

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.

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!

1 reply

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.

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


1 year ago

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

2 replies

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

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

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.

1 reply

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.