Contents
- 1 Preparation
- 2 Steps
- 2.1 HC SR501—void setup()
- 2.2 Connect the power pin of the hc sr501 PIR Sensor board to the Arduino 5V and the GND pin to the Arduino ground pin.
- 2.3 HC SR501—The Arduino pin 3 should be connected to the IN pin of the 5V relay channel.
- 2.4 Having made all these connections right, power your circuit again.
Preparation
In addition to this, you will also need a 5V DC voltage source to power the Arduino and a light source, which is the normal bulb for your house lights.
First, we need to program our Arduino to give the actuating signal whenever a human being makes some movement. The working sequence is simple. The PIR Sensor stays on 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 with 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 off. To keep this all working as it should, one must include some timing between the Arduino program to ensure 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 hc sr501 PIR Sensor PCB; | ||
int |
pir = |
2; //PIR at pin |
2 |
int |
relay |
= 3; //Relay at |
pin 3 |
Steps
HC SR501—void setup()
{Serial.begin(9600); pinMode(hc sr501 pir, INPUT); pinMode(relay, OUTPUT); digitalWrite(relay, LOW);delay(5*1000); //Wait for the PIR to settle}
Connect the power pin of the hc sr501 PIR Sensor board to the Arduino 5V and the GND pin to the Arduino ground pin.
The output pin of the sensor should be connected to the Arduino pin 2. You could change this to suit your program. Note that in this, when connecting, you may need male-to-female jumper wires. In most cases, 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.
HC SR501—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 be connected to the 5V source and common ground. Normally, the other side of the relay channel has Open (NO) contacts and Normally Closed (NC) contacts. We will use the NO contacts so that the circuit shall be on 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 hazardous and should only be performed by or with a responsible licensed electrician; unless you know what you are doing.
Having made all these connections right, power your circuit again.
Give the sensor some time for it to settle. Now wave your hand in front 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.
Partner: Sam