How to Build a Motion Sensor Light Circuit

Motion sensor light

In this project, we will go over how to build a motion sensor light circuit.

A motion sensor light circuit is a circuit in which a light will turn on when movement is detected near its vicinity.

Its use is to illuminate an area when a person walks by so that he or she can see better.

Many people place motion detectors in their backyards or even in their houses so that when they walk through that area, the lights will automatically turn on. Thus, motion sensor lights are very popular and being increased in use. Businesses use them all the time such as for bathrooms, when a person walks in, the lights turn on. Or many times they are used in grocery stores for when you pass through an aisle or open up a refrigerator door in the freezer aisles. The applications are numerous.

In this circuit, we will create a motion sensor light circuit that will stay on for 30 seconds minutes when motion is detected. This is just for demonstration purposes. Depending on what you use the circuit determines how long you may want the lights to stay on for. For a refrigerator application such as in a supermarket when the fridge door opens, 30 seconds would be adequate. Usually people don't stay in the fridge that long. If you're using it for a bathroom, a longer time period may be necessary such as 2-3 minutes. If the person is still in the bathroom and moving, the sensor will turn right back.

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 waves. Being that a person emits infrared waves, the detector is able to detect these waves 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.

Parts Needed for Motion Sensor Light Circuit

  • PIR motion sensor
  • Arduino
  • LED

The PIR motion sensor is, again, a sensor which can detect movement through picking up infrared radiation. Being that people naturally give off radiation, because of our generated body heat, the motion can easily detect people walking and moving through a vicinity within the sensor's range.

The motion 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.

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 is low and it gives off practically no voltage. The output pin will connect to the base of an NPN transistor. When no motion is detected, the output is LOW and no current flows from the output of the sensor. Therefore, the transistor does not get turned on. When motion is detected, the output is HIGH and current flows from the output of the sensor and turns on the transistor. The turned-on transistor then turns on the LED that is attached to output. This is the motion sensor light.

Besides the PIR sensor, the other significant component we will use is the arduino.

We will place the output of the PIR sensor into a digital pin of the arduino. The arduino will then be able to tell if the PIR sensor is outputting a LOW or HIGH signal. If it is outputting a LOW signal, this means the PIR sensor has not detected any motion. The LED we will connect to another digital pin, in this case, will not light. If the sensor is outputting a HIGH signal, this means the PIR sensor has detected motion, and the LED connected to the arduino, we will program to light in this case.

Motion Sensor Light Circuit Schematic

Below is the schematic of the motion sensor light circuit we will build.

Arduino motion detector circuit

The schematic diagram of this circuit is:

Arduino motion sensor circuit schematic

This is the complete schematic of the circuit we will build.

We connect pin 1 of the PIR sensor to +9VDC and we connect pin 3 of the sensor to ground. This gives the PIR sensor the power it needs to operate. We connect pin 2, the output pin of the PIR sensor, to digital pin D3 of the arduino. This pin will detect whether the PIR sensor is outputting current (motion detected) or not (no motion detected).

We connect to an LED to digital pin D13. We do not need to connect an external current-limiting resistor to this LED, because digital pin D13 of the arduino already has internal built-in resistance. So we do not need to worry about excess current burning out the LED. Therefore, we can just hook the anode of the LED directly to D13 and the cathode to GND of the arduino.

With this setup, we have built a motion sensor light circuit.

Program for Arduino Motion Sensor 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 detector 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 30,000ms, which is equal to 30 seconds. After this period of 30 seconds has elapsed, the LED then turns LOW. Again, you can modify this code so that the LED stays on for 1 minute after motion has been detected. You can modify it so that it stays on for 2 minutes or 3 minutes. All this can be done by changing the value given to the delay() function. 1 minute would be 60000ms. 2 minutes would be 120000ms. Customize the code to suit your circuit's needs.

This is a motion sensor light circuit that turns on when there is any motion, whether in the light or in the dark. Many times, it is only wanted for motion sensor lights to come on when it is dark. If it already bright, then many times we wouldn't need the light to turn on. To create a motion sensor light that turns on only when it's dark, we will need to modify the above circuit so that we add a photoresistor so that it only turns on when it gets dark. This is shown in the project, Arduino Night Light Circuit.

Related Resources

How to Build a Hall Effect Sensor Circuit

How to Build a Vibration Detector Circuit

HTML Comment Box is loading comments...