Introduction: Controlling House Lights Using HC-SR501

About: WELLPCB PTY LTD is a daughter company of Uniwell Circuits Co., Ltd www.uniwellcircuits.com, which have two modern PCB factories, founded in Shenzhen, China in April, 2007. WELLPCB is focusing on online prototy…

Controlling House Lights Using HC-SR501

Step 1: Controlling House Lights Using HC-SR501

Whether you are in a bathroom or in your study room, it makes life easier for you to automate the lighting system such that you do not have to switch every switch on or o . It is much more natural and enjoyable to let the lights behave the way you want, without having to get involved. For you to do a good job, you need to purchase some PCBs or instruct some PCB manufacturer (e.g. wellpcb.com) to do the job for you. In this tutorial, you shall use a couple Printed Circuit Boards, which can be termed as standard since they are used by almost all electronics enthusiasts and professionals. These PCBs are as listed below:

1. Arduino Nano Board

2. HC-SR501 PIR Sensor Module

3. 1 Channel 5V Controlled Relay Module

In addition to this, you will also need a 5V DC voltage source to power the Arduino and also a source of light; which is the normal bulb for your house lights.

To start with, we need to program our Arduino such that it is able to give the actuating signal whenever a human being makes some movement. The working sequence is simple. The PIR Sensor stays standby, waiting to detect any infrared signals registered from movement from a human being. When movement is registered and acknowledged by the Arduino, the Arduino issues a high signal to the relay module telling it to close contact for the light switch so that lights can go on since somebody is moving and needs some lighting. Where there is no movement recorded, lights go o . To keep this all working as it should, one has to include some timing in between the Arduino program to make sure that it waits for the right data and does not perform actions too quickly or based on erroneous data.

To get started, we shall start with a simple program using Arduino IDE. This program will be in control of our system. The program should be similar to the following:

//Control lights using PIR Sensor PCB;

int pir = 2; //PIR at pin 2

int relay = 3; //Relay at pin 3

void setup()

{

Serial.begin(9600);

pinMode(pir, INPUT);

pinMode(relay, OUTPUT);

digitalWrite(relay, LOW);

delay(5*1000); //Wait for the PIR to settle

}

void loop()

{

if (digitalRead(pir) == HIGH)

{

digitalWrite(relay, HIGH);

delay(5*1000);

digitalWrite(relay, LOW);

}

else

{

digitalWrite(relay, LOW);

}

}

Now click `verify' on the Arduino IDE to see if the program is ready download into our Arduino board. The above program was veri ed without any errors. Click `upload' to get the code into the Arduino board. Having done this, disconnect the Arduino from power and from your PC and do the necessary wiring as per the program.

Connect the power pin of the PIR Sensor board to the Arduino 5V and GND pin to Arduino ground pin. The output pin of the sensor should be connected to the Arduino pin 2, according to the program. You could change this to suit your program. Note that in this when connecting, you may need male to female jumper wires. In most case, you leave all the other sensor settings the same as the factory settings. If for some reason, the sensor behaves in an undesirable or unexpected way, you can come back and increase the sensitivity or lower the delay time.

The Arduino pin 3 should be connected to the IN pin of the 5V relay channel. The 5V and the GND pins on the 1 channel relay should connected to 5V source and to the common ground respectively. The other side of the relay channel has Normally Open (NO) contacts and the Normally Closed (NC) contacts. We are going to use the NO contacts so that the ciruit shall be o even when the system is not powered. A house light bulb has a switch. This switch has two contact points. These two contact points come together to let the current ow and power the lights. Switch o the main switch and connect these two contacts to the NO contacts of the relay board. Note that this exercise could be very dangerous and should only be performed by or with the assistant of a responsible licensed electrician; unless you know what you are doing.

Having done all these connections right, power your circuit again. Give the sensor sometime for it to settle. Now wave your hand infornt of the sensor for some time, then remove your hand and settle for some time. You should see lights go on when you wave your hand and go o when you remove your hand and settle. The project is complete! You can now go ahead and make a decent implementation of this prototype in your house.