Controlling AC Light Using Arduino With Relay Module

917K460227

Intro: 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


197 Comments

Can you please tell me what AC-Source and AC-Light you are using?
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
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
can you please upload the circuit diagram for this , it would be very helpful.
If i want more bulbs then it will parallel connection or not?? Or need more relay to control... Means one relay controls one bulb....

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

this circuit can apply with push button ?
What if the relay didn't work properly and there is a short circuit..how r we gonna protect our arduino then

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

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

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

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

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

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

}

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