Controlling AC Light Using Arduino With Relay Module

818,028

431

195

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

delay(2000);


Step 7: Watch

3 People Made This Project!

Recommendations

  • Big and Small Contest

    Big and Small Contest
  • Make it Glow Contest 2018

    Make it Glow Contest 2018
  • Toys Contest

    Toys Contest

195 Discussions

0
None
ALKIBII

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

0
None
SaifulA31

Question 4 months ago on Step 7

this circuit can apply with push button ?

1
None
sweetyk1

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

1 more answer
0
None
camelopersweetyk1

Answer 4 months 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

0
None
IzamL

1 year ago

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

2 replies
0
None
VishnuW2IzamL

Reply 6 months 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

0
None
Hey.Its_RJIzamL

Reply 1 year 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

0
None
sai01

Question 9 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

0
None
yAsk4u

1 year 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?

0
None
redkcir

1 year 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

}

2 replies
0
None
deskriptaredkcir

Reply 1 year 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...

0
None
redkcirdeskripta

Reply 1 year 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.

0
None
JohanM55

1 year 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!

1 reply
0
None
RealModelsInBottlesJohanM55

Reply 1 year ago

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.

0
None
BrookM2

1 year ago

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

0
None
SonalU

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

1486149345883-125790484.jpg1486149366838235167001.jpg
2 replies
0
None
RajendraS8SonalU

Reply 1 year ago

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

0
None
WaelE13SonalU

Reply 1 year ago

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

0
None
ArduinoElectronics

1 year ago

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.

$_103.jpg