How to Build a Motion Sensor Light Circuit with an Arduino

arduino motion sensor light circuit

In this project, we will go over how to build a motion sensor light circuit with an arduino. A motion sensor light circuit is a circuit in which a light turns on when motion is detected.

With a PIR motion sensor integrated with an arduino, we can detect movement and program the arduino to turn a light on for a certain period of time once this motion is detected.

For example, once motion is detected, we will turn on the light attached to the output of the PIR sensor for 1 minute. This is how most commercial motion sensor lights work. When motion is detected, the light will turn on for about 1 or 2 minutes. If the light turned on and stayed on for only the second that motion is detected, this wouldn't be very useful. When motion is detected by a motion sensor light, it will stay on for at least a period of time, on average 2 minutes, so that it can provide illumination for this time if the person that triggered the sensor stays in the area. Then, after this period of time has elapsed, it will shut off. If the person continues moving in the vicinity of the motion sensor, it will then be triggered again and stay on for 2 minutes again. This cycle will continue as long as needed. Again, this is how most commercial motion sensor lights work.

You can decide how long you want the light to stay on once detected for your circuit. You will see how to do this in the code you will write and upload to the arduino board.

Components Needed

  • Arduino Board
  • PIR motion sensor
  • LED
  • USB with type A and B connectors

The main electronic component we will use that allows us to pick up this detection is the PIR motion sensor. The PIR motion sensor is a sensor which detects movement through picking up infrared radiation. Being that a person emits infrared radiation, the detector is able to detect this and react, according to the how the circuit is designed to react. The sensor can also pick up the movement of inanimate objects as well, such a rolling ball, because as those objects move, friction acts on them, generating heat. This heat emits infrared radiation, which the PIR sensors may be able to detect if great enough.

This motion sensor can be bought at various online retailers. Probably the most reasonable price to get it is from at the following link: Amazon- PIR Motion Sensor.

The PIR motion sensor is a 3-pin device. Below is the pinout of this device:

PIR motion sensor pinout

Pin 1 is the pin which receives the positive DC voltage. The PIR motion sensor needs between 5V-9VDC of power for operation. In our case, we will use about 6V of power. This can be obtained from switching a DC power supply to 6V or using 4 'AA' batteries connected in series. We will then feed this voltage into pin 1 of the PIR module.

Pin 2 is the negative DC voltage or ground pin of the device. We connect the negative terminal of the power source to this pin, for a return path.

Pin 3 is the Output pin of the PIR module. This is where the output of the PIR will leave from. When motion is detected by the PIR, its output will go high to 3V. When no motion is detected, its output low and it gives off practically no voltage. When high you can see then how it can power the LED will we attach to this pin.

This sensor has a sensitivity range up to 20 feet (6 meters) and a 110° x 70° detection range, making it a wide lens detection sensor. This means it can measure 110° vertically (from top to bottom) and 70° horizontally (from left to right). The best way to check its sensitivity is when the circuit is built, try moving around through all of its angles. See at which angles it can detect your movement and at which angles it is not able to detect your movement, meaning your out of its angle scope. A lot of it is trial and error and experimenting. Once you know where it can and cannot detect, you can place it in an optimal place where it can detect in areas where you want it to.

Besides this sensor, we need an LED, which we will light when motion is detected.

You can use any arduino board. You will need a USB with a type A connector at one end and a type B connector at the other. The type A side connects to the computer you will be using and the type B plugs into the arduino USB slot. This way, we can program and upload software for the arduino board to follow.

Arduino Motion Sensor Light Circuit

The arduino motion sensor light circuit we will build is shown below:

Arduino motion sensor light circuit

The schematic diagram of this circuit is:

Arduino motion sensor circuit schematic

Pin 1 of the motion sensor connects to the 5V DC voltage terminal of the arduino. Pin 3 connects to the ground (GND) pin of the arduino. Pin 2, the output, connects to the digital pin D3.

With this connection, pins 1 and 3 are powered with 5V by the arduino, so it is through these pin connections that the PIR motion sensor gets the 5V that it needs to power on and operate.

And it is through pin 2 that the arduino receives output from the motion sensor. When the motion detector does not detect any motion, the output is LOW and the arduino receives no voltage signal. When the sensor detects mtoion, the output is HIGH and the arduino receives a voltage signal, which can then trigger another device to turn on, such as an LED we will use for this circuit.

The LED we will light connects pin 13 and ground of the board. The anode connects to pin 13 and the cathode connects to ground. No external resistor is necessary to limit current to the LED, because pin 13 already has built-in resistance to limit current flow.

Code for Arduino Motion Sensor Light Circuit

After we connect the USB from the arduino to the computer, we are ready to write the code that the arduino board will need uploaded to it so that it knows to light the LED when motion is detected.

The following code, or sketch, will light the LED on pin 13 when the sensor detects motion:

//code for motion sensor circuit
const int ledPin= 13;
const int inputPin= 2;

void setup(){
pinMode(ledPin, OUTPUT);
pinMode(inputPin, INPUT);

void loop(){
int value= digitalRead(inputPin);

if (value == HIGH)
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin, LOW);
digitalWrite(ledPin, LOW);

The first block of code chooses the pin for the LED, which is pin 13. The second line chooses the pin for the input pin, which represents the PIR sensor, pin 2.

The second block of code declares the LED as output and the input pin as input.

The third block of code reads the sensor value of the sensor and assigns it to the integer value.

The fourth block of code determines whether the sensor pin is HIGH or LOW. If it is HIGH, then the motion sensor has detected motion. If it is low, the sensor has not detected any motion. If the value is HIGH, it turns the LED on, signaling that motion has, in fact, been detected. The LED stays on for 60000ms, which is equal to 1 minute. After this period of 1 minute has elapsed, the LED then turns LOW (or off). Again, you can modify this code so that the LED stays on for 5 seconds after motion has been detected or any time period. All this can be done by changing the value given to the delay() function. 5 seconds would be 5000ms. 2 minute would be 120000ms. 30 seconds would be 30000ms. Customize the code to suit your circuit's needs.

To see how this circuit works in real life, see the video below.

Related Resources

Arduino LED Flasher Circuit

How to Drive a 7 Segment LED Display with an Arduno

How to Connect and Read a Keypad with an Arduino

How to Display Text on an HD44780 LCD Using an Arduino

How to Build a Hall Effect Sensor Circuit

How to Build a Vibration Detector Circuit

HTML Comment Box is loading comments...