PIR Motion Detector With Arduino: Operated at Lowest Power Consumption Mode

Introduction: PIR Motion Detector With Arduino: Operated at Lowest Power Consumption Mode

About: A Researcher, an Engineer and an electronics enthusiast

This video demonstrates quick and easy approach of reducing power consumption of ATMEGA 328P based Arduino boards by around 70-75% using PIR or PID sensors for motion detection.

This project introduces following things-

1) Interfacing Pyroelectric/Passive Infra red (PIR) motion sensor with arduino (or any microcontroller)

2) Using Interrupts of arduino boards (here Arduino NanoV 3.0 clone ) to detect output of PIR sensor

3) Extending battery life or reducing power consumption by putting arduino nano into deep sleep or hibernation when motion is not detected by PIR sensor.

Pyroelectric/Passive infrared (PIR) sensors are widely used in Automatic doors or lights, surveillance cameras, toys, night lamps, automatic cameras etc. We can easily recognize such PIR sensors around us, because these sensors mostly have typical hemispherical dome with honeycomb like small facets (Fresnel lens) all around its body.

Rattlesnakes have natural "invisible heat" or "infrared radiation" sensor on its head, It can sense extremely tiny variations in surrounding temperatures. This helps the snake to detect its prey without actually "seeing" it, just by "sensing" the warmth of the body of its prey. Electronic PIR sensors work in similar manner.

PIR sensors are used to generate electronic signal output upon detection of any human/animal movement within the vicinity of sensor's detection range. These sensors detect minute changes in surrounding temperature emitted in the form of infrared radiation (IR radiations) by our bodies. Every object above above absolute zero degree temperature ( −273.15°) emits IR radiations. Special kind of pyroelectric materials are used in these sensors which generate temporary electrical voltage depending on variations in its temperature. Therefore, PIR sensors are called passive sensors, i.e. they do not consume energy for detection purpose; but they catch energy (Infrared radiations) emitted by other bodies . This makes PIR sensors useful for applications where mechanical, magnetic or light sensors cannot be used for one or the other reason.

Step 1: Introduction: @ Operation of PIR Sensor for Motion Detection

The PIR sensor used in this project is purchased from banggood.com with detection range of 3 to 7m, possibility to adjust its output ON state duration from 5 to 200 sec and operating input voltage between 4.5 to 20 V. Predicted idle state current consumption is less than 60 micro-Amps. The output of PIR sensor is 3.3V TTL logic level making it compatible also with ESP8266, arduino Due (apart from arduino uno, nano etc) and other boards operating at 3.3V logic levels. No need of logic level converters.

Typical operation is as follows (refer attached pictures)-

1) Output remains LOW in idle state

2) Output goes HIGH (3.3V) when motion is detected by sensor i.e. if any body moves within its detection range

(Detection range or Sensitivity can be adjusted by Sx or sensitivity potentiometer)

3) Output remains HIGH for fixed time set by Tx or time setting potentiometer.

The output of sensor can be given as intput to microcontrollers, processors, logic level ICs, data acquisition systems, MOSFETs etc.

Step 2: Connection Diagram and Components

Connections are shown in attached fritzing circuit diagram. Since, we will be using hardware interrupt of arduino nano board, I have connected output of PIR sensor to pin D2 (or interrupt 0). Arduino nano has two interrupt pins, pin D2 and D3 for interrupt 0 and 1 respectively.

We will read PIR sensor output using "hardware interrupt" functionality of arduino. Interrupts help in letting our arduino do its regular job or sleep into deep hibernation mode until some signal is received at its interrupt pins. This lets us use arduino perform other tasks or remain in "nearly OFF state" while waiting for signal at interrupt pins. This helps in reducing power consumption of arduino and sensor system.

Bill of materials-

1) PIR sensor

2) 1) Arduino Nano V 3.0 board ( or other boards can be used, provided interrupt pins are selected accordingly- read more )

-For Uno, Nano, Mini, other 328-based boards- pins 2 (int 0) ,3 (int 1)

-For Mega, Mega2560, MegaADK- pins 2, 3, 18, 19, 20, 21

-For Micro, Leonardo, other 32u4-based- pins 0, 1, 2, 3, 7

-For Zero, MKR1000- all digital pins, except pin 4

-For Due- all digital pins

2) Breadboard or PCB

3) Power supply or battery with at least 5.5V since we will be powering arduino from VIN pin

4) Jumper wires at least 5

5) LED or relay to connect to output pin (here pin D13) of arduino

Step 3: Arduino Nano and PIR Sensor With Pin State Change Polling Mode (Higher Power Consumption)

Before going to main concept of using interrupt and power saving deep sleep mode, let us briefly understand power consumption using Pin state change polling sketch.

I have slightly, modified the standard sketch available in examples section, sketch .ino file is attached.

In this sketch, we are continuously checking/polling the input pin D2 to which output of PIR sensor is connected.

The arduino never goes to sleep mode, ADCs are enabled, hence continuously consumes maximum power.

The current and power consumption is as follows-

* No motion detected by PIR sensor - external LED at pin D13 is OFF:- 12.87milliAmp / 62.45 mWatt

* Motion detected by PIR sensor - external LED at pin D13 is turned ON:- 36.55 milliAmp / 175 mWatt

Considering it is continuously in OFF state, no motion detected,

A typical 9V battery considering it gives 500mAh, will last for 500/12.87 = 38 hours

a typical AA size batteries giving around 2500mAh, will last for 2500/12.87 = 195 hours or 8 days

Step 4: Sketch: Power Down and Interrupt Based Wake Up (Lower Power Consumption)

To save power/battery consumption, it would be beneficial to put arduino into lowest power consumption mode or hibernation until PIR sensor detects motion. We will achieve this using hardware interrupt and Power Down Mode of arduino board's ATMEGA328P microcontroller. Moreover, we will disable analog to digital converters (ADC) since we do not need any ADC.

"The Power-down mode saves the register contents but freezes the Oscillator, disabling all othe r chip functions until the nex t interrupt or hardware reset."

In this sketch, we are using input pin D2 or Interrupt 0 to which output of PIR sensor is connected.

Since PIR detector itself has ON state timer, we do not need any timer from arduino to keep output pin D13 ON for fixed time. The ON time can be physically adjusted using Tx potentiometer, as shown in previous step.

- Arduino on first power ON, blinks LED at pin 13 for a minute, this is just for visual indication of warm-up period required by PIR sensor to stabilize to ambient temperature.

for( int i = 1; i <= 120; i++) {
digitalWrite(LedPin, HIGH);


digitalWrite(LedPin, LOW); delay(100); }

-The Arduino is kept into Hibernation until D2 pin is LOW.

In function Hibernate();

we will put all pins to INPUT except pin 13 to which we have connected our LED or relay.

for (int i = 0; i < 20; i++) {
if(i != 13)

pinMode(i, INPUT);}

and set arduino sleep mode to lowest power consumption mode


and disable ADCs

ADCSRA &= ~(1 << 7);

and disable Brown out detector used to check input voltage level


we attach interrupt 0 of pin 2 into detect CHANGE in state of signal at pin 2

attachInterrupt(PIRsensorInterrupt,wakeUpNow, CHANGE);

finally Sleep function is called using


-When PIR sensor detects motion, PIR sensor output state changes from LOW to HIGH. This rising edge signal is picked up by interrupt 0, arduino Awakes from sleep mode, interrupts are disabled temporarily and consequently pin D13 goes HIGH.

Once, set time is passed, PIR output again reverts back to LOW from HIGH, this falling edge signal raises another interrupt, putting arduino into hibernation once again.

Step 5: Power Consumption in Hibernation Mode

The current and power consumption reduces drastically using power down mode, putting all pins to INPUT (or OUTPUT) and disabling ADCs.

* No motion detected by PIR - external LED at pin D13 is OFF (Arduino Hibernated) :- 5 milliAmp / 25 mWatt

* Motion detected by PIR - external LED at pin D13 is turned ON (Awake):- 32 milliAmp / 167mWatt

Considering it is continuously in OFF state, no motion detected,

A typical 9V battery considering giving 500mAh, will last for 500/5 = 100 hours or 4 days

a typical AA size batteries giving 2500mAh, will last for 2500/5 = 500 hours or 21 days

Note- Although, predicted current consumption in power down mode for ATMEGA 328P is in microAmp range, we are still in miliAmp range. This is because, arduino nano board has power regulators and other components that consume current. To achieve ultimate lowest current consumption, we will need bare ATMEGA chip with least possible external components. Our goal is to reduce power consumption to lowest possible level for arduino nano board.

Please suggest, if someone has more optimized code for arduino nano to further reduce power consumption.

Useful links - acknowledgements:-

http://playground.arduino.cc/Learning/ArduinoSleepCode for information about sleep.h library and sleep modes



1 Person Made This Project!


  • Electronics Contest

    Electronics Contest
  • Home and Garden Contest

    Home and Garden Contest
  • Origami Speed Challenge

    Origami Speed Challenge


Asif Badi
Asif Badi

11 months ago

I use your code in my Arduino mega 2560 and also in atmega 8l microcontroller but don't wakeup after any object movement. In sleep mode only working low level interrupt any other interrupt like high level, state change interrupt not working. so please solve my problem.


1 year ago

Hey nice tutorial! That's a real nice sourcemeter, maybe just a wee bit outside of my budget right now though ;-)


Question 2 years ago

anyone know if there is a way to add a time delay to this code to keep the relay on for given amount of time.. as the PIR sensor i have, the in built timer is not working properly. When i adjust the potentiometer on the back of the PIR sensor it either keeps the relay on forever, or for 3 seconds. no adjustment in between. any help much appreciated


Question 4 years ago on Step 4

What is the purpose of setting all other pins to INPUT?


Answer 2 years ago

Probably intended to reduce current consumption during sleep; however, it's far more effective to set unused pins as OUTPUTS to achieve this purpose, here's why:

Inputs that are left floating (not tied to VCC or GND) are prone to switching through picking up interference, this switching will draw a small amount of current, although the total amount when accounting for all the pins and having them potentially switching quite frequently could lead to an undesirable increase in current draw.

To combat this, one could tie the pins either high or low. You could use the Arduino's internal pull-up resistors; however you then have the current (I = V/R) through these resistors. Alternatively you could pull them all to ground; however, this would require external resistors.

By setting the pin as an output, you don't have a floating pin (it's either set high or cleared low) and you don't have to worry about pull-up/pull-down resistors drawing current. The only current consumption here would be pin leakage current (typically about 1uA).

Hope this can help someone :)


3 years ago on Step 4

The battery lifetime calculations are incorrect, in fact the mAh capacity is not enough to describe the energy in - energy out ratio, especially when using different input voltages at the linear regulator. Energy has to be used for these calculations, which is E=mAh*V, so ~16000J for the 9V battery (9V * 3600s * 0.5A) and ~55000J when using 4 AA batteries (1.5V * 4 * 2.5A * 3600). Then you can compute the battery lifetime by dividing your battery energy by the power consumption in W and you will get the duration of the battery in seconds (again, approximately since the battery voltage will drop during discharge). Hope this is clear. For Example in the case of 175mW of constant power and a 9V battery you will get: t = Ein/P = 16000J/0.175W= ~91000s = ~25h


4 years ago

One of the best Tutorials! Thank you, I adapted the hybernate function to my devices!


4 years ago

To do what you're doing at minimum power, there is no need for most of the circuitry on the Nano, including the oscillator (yes you will run at only 8MHz, plenty fast for detecting the interrupt and most other operations).

1) Get a bare ATMEG328p chip.

2) Load the Arduino ISP sketch onto your nano. Or, better yet, buy an ISP programmer. eBay has lots of arduino/AVR compatible ones for sale at a decent price.

3) Wire up a breadboard to program the chip. (Alternately Since OSH Park has some public designs for AVR ISP with a ZIF, build one of those.)

4) Wire up a breadboard to implement your circuit (very similar to the one with the nano)

5) Use the LowPower library to manage the power consumption, as recommended by other commenters.


Another thing to try, if you're up for the challenge, is to see if using the "watchdog" features of the chip can further reduce power consumption by ensuring it's completely off 99% of the time.

Below is the link to the official documentation on how to do it.



Reply 4 years ago

thanks. the main aim of this is to run Nano board in lowest possible power. I agree with bare ics and stripping most of circuitry we can go very low power consumption.
thanks for link.


Reply 4 years ago

Also for the link, read the parent topic. One of many things to learn: The slower the CPU speed, the lower the power consumption.


5 years ago

I can compile the sketch with a UNO and a NANO. With a MEGA 2560 I recieve the error message :

In function 'void Hibernate()':
alarm_MH.ino:49:20: error: 'sleep_bod_disable' was not declared in this scope
'sleep_bod_disable' was not declared in this scope


Reply 5 years ago

i do not have Mega so cannot give solution. but i think it has something to do with exact library for MEGA and also low level instructions to put into sleep etc.


5 years ago

Nice instructable!


5 years ago

Nice Instructable !, i've read somewhere else they desoldered the integrated LED diodes (the smd ones) , since they drawn too much curent, after all there's no need to know if the board is turned on...


Reply 5 years ago

yes many hackers do that ...