Introduction: Control Your Home Appliances Using Arduino and Relay

Picture of Control Your Home Appliances Using Arduino and Relay

Hello everyone, In this instructable we will be using Arduino And Relay module to control home appliances.

This instructable covers:

  1. Basics of Relays.
  2. Connecting Relays with Arduino.
  3. Controlling AC appliances using Relays.

How it works:

  • The relay uses an electromagnet to mechanically switch electric appliances.
  • A relay can be operated by a relatively small electric current that can turn on or off a much larger electric current.
  • Using relays is safe as there is no any physical contact between Arduino and AC.

Step 1: Gather the Parts

Picture of Gather the Parts

In order to Control Your Home Appliances Using Arduino and Relay we'll need:

  1. An Arduino UNO
  2. A 5V Relay module
  3. Female jumper wires

Step 2: Wiring

Picture of Wiring

Hookup all the components according to the circuit diagram shown above.

In the above wiring diagram, The pins VCC, GND and IN on the Relay module may vary depending on your Relay module. So, Refer to the data-sheet of your Relay.

For, connecting the AC bulb to the relay properly:

  • Connect live wire from AC wall outlet to Common port on relay and one terminal of AC bulb to Normally open terminal of Relay.
  • Then, Connect the other terminal of AC bulb to GND on the AC wall outlet.

Take proper precautions and care while connecting any wire to mains.

Step 3: Arduino Sketch

Picture of Arduino Sketch

Once you have hooked up everything properly upload the Relay.ino sketch to your arduino.

Unlike LEDs, Relays closes the circuit whenever the signal or input pin is connected to GND. (This may vary for other custom made relay modules.)

So, "digitalWrite(13, LOW);" turns on the bulb. While, "digitalWrite(13, HIGH);" turns off the bulb.

void setup() {
  pinMode(13, OUTPUT);
void loop() {
  delay(5000);              // wait for 5 seconds
  delay(5000);              // wait for 5 seconds

The above code turns on the bulb for 5 sec and turns it off for the next 5 sec.

Step 4: Done

Picture of Done

Now just power up your Arduino and the Relay to see your AC bulb turning on and off.

Thanks for viewing.


devansh_vyas (author)2017-12-19

if i want to control my home appliance with app and normal switch also then what can i do?

SanathK9 (author)2017-06-16

Using this concept if i wish to turn on and off a pump ..... What all precautions i should take ...... should i have to add any isolation between high voltage supply and low voltage arduino..... Thank you

luksj (author)2017-04-21

Hello guys.Im new to arduino and im about to purchase arduino uno r3 and a breadboard so i wanted to know what program do i use to write the code.

Dr_Eric (author)luksj2017-05-01

the software is available for free at

clazman (author)2016-09-05

I'd like to see a power ramp up routine for incandescent lights. The main failure for incandescent lights is the inrush of current at startup. This is more of a problem as the light ages. To reduce this current a ramp up of voltage over a one second interval needs to be implemented. To do this the the relay will need to be very rapidly turned on and off with increasing duty cycle over the one second. However, the mechanical relay will need to be replaced with a solid state relay. to handle the much faster cycling.


kturpin (author)clazman2016-11-14

Just curious, how does PWM interact with AC current this way? I don't expect it'll be a problem per se but it seems like it might mean some kind of flicker effect or something as the PWM drops in and out of phase with the AC switching.

kqutter12 (author)2016-10-22

Oh sorry that's the correct one

kqutter12 (author)2016-10-22

Oops wrong one

kqutter12 made it! (author)2016-10-22

I made it

kqutter12 (author)2016-10-22

I tried with outlet it works thank you so much

jʎɐɹ-ɾ (author)2016-10-14

This is JUST what I needed! thanks =)

suryar25 (author)2016-09-17


rupertrussell (author)2016-09-14

If you want to control AC mains current with a microcontroller I would recommend that you use a device with an Opto-isolator. See:

The job of the Opto-isolator is to physically isolate the high voltage circuit from your low voltage microcontroller. One such device is made by this is much safer than simply using a relay as shown in these instructions. I have used PowerSSR Tail Kit for 200-240vac mains they require assembly but they work well. Keep safe!

john711 (author)2016-09-04

Do not use pin 13. Use any other pin, such as pin 12. If oyu like to experiment, try both pins, one at a time, without a load connected to the relay, and you'll see why.

smc wall (author)john7112016-09-06

I know exactly what you saying, I learned what happens when you connect the relay to pin 13... I had a large AC motor connected, and when the Arduino restarted, the 3 Kicks nearly shook the motor off the table... Had the motor come off the table, i would be talking to you with a broken foot.

pkmonster (author)2016-09-06

Hi !

In case

  • Connect live wire from AC wall outlet to Common port on relay and one terminal of AC bulb to Normally open terminal of Relay.
  • Then, Connect the other terminal of AC bulb to GND on the AC wall outlet.

However, my relay module will operate with LOW signal and PIR is operating at HIGH signal.

Therefore, when I connect one terminal to Normally Open. It doesn't work.

And then change Normally Open to Normally Close => It operates normally.

Is it OK with that??? Thank you

P/s: Sometimes, all system doesn't work correctly like Lamp still turns off permanently. Any suggestion?

smc wall (author)pkmonster2016-09-06

If the Lamp is not turning on or off, then it is because your relay is not operating correctly, or you have incorrectly wired up your Arduino to relay... The most likely cause of this problem is the battery you are using to power your Arduino, if the battery is a low on voltage (usually below 4V) then the Arduino does not have enough power to close the switch inside the relay. My advice is use a new 9V battery on the Arduino.

SteliosA1 (author)2016-09-06

Poli kalo OK

doctorlock (author)2016-09-04

The jumper wires you show in the pic are male jumpers. Or Maybe you need to get your into about sex ed or the bird's and the bee's. you need to explain what is going on here. If this is supposed to be for beginners it just isn't well done. If this is for advanced electronics it still is not well done. But thank you for the instucktable anyway and keep trying Thankx Gunnrunner

john711 (author)doctorlock2016-09-05

They are male to female jumpers. Male to Arduino and female to the relay (which is not solid state, which I mistakenly called them before -- you can't edit these remarks).

andrewty (author)2016-09-05

For, connecting the AC bulb to the relay properly:

  • Connect live wire from AC wall outlet to Common port on relay and one terminal of AC bulb to Normally open terminal of Relay.
  • Then, Connect the other terminal of AC bulb to GND on the AC wall outlet.

NO !!!!

  • Connect the other terminal of Mains bulb to NEUTRAL, not to GND.
billbillt (author)2016-09-04

Great job!!.. Does the relay board have an opto coupler?.. I can't tell by the photos..

PhilS43 (author)2016-09-04

What sort of lamp is it? Filament, CFL, LED?

CFL's in particular can throw out a lot of RFI/EMI when they switch, I had a lot of trouble with an Arduino being powered up on the same mains circuit as the CFL's.

The interference was triggering false digitals and got through just about every anti-interference device going - running the Arduino on a battery was trouble-free.

The only reasonable, but not totally effective method, was to fit snubbers (non-polarised class X2 0.1uF capacitor and 120R resistor in series) across the contacts switching the lamps - it can lead to a lot of wasted time de-bugging. Snubbers are always good practice when switching complex AC loads.

Your relay board looks as though it has a diode to protect the Arduino digital outputs.

AlexK134 (author)2016-09-04

It would be better if ESP 8266, PIR sensor and relay

GavinF2 (author)AlexK1342016-09-04

It would be different.
This instructable is a basic hookup and programming guide for an Arduino and relay.

IzanI (author)2016-09-02

Thank You, tutorial simple and very nice , may I share on my blog in Indonesian ?

clauculo (author)2016-08-30

Thank you! Finally a clear and simple instructable about arduino and relay and how to connect it. Well done!

kitty 1234 (author)clauculo2016-08-30

Thanks for your feedback. :)

About This Instructable




More by kitty 1234:Control Your Home Appliances Using IR RemoteControl Your Home Appliances Using Arduino And RelayHard Bond Any Paperback Book
Add instructable to: