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

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);

delay(100);

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

set_sleep_mode(SLEEP_MODE_PWR_DOWN);

and disable ADCs

ADCSRA &= ~(1 << 7);

and disable Brown out detector used to check input voltage level

sleep_bod_disable();

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

sleep_mode();

-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

http://www.atmel.com/images/atmel-8271-8-bit-avr-microcontroller-atmega48a-48pa-88a-88pa-168a-168pa-328-328p_datasheet_complete.pdf

http://www.kevindarrah.com/download/arduino_code/LowPowerVideo.ino

Comments

author
JasonD1 made it!(author)2017-07-02

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.

http://www.atmel.com/webdoc/GUID-EAD481FD-28E6-4CD...

author
JasonD1 made it!(author)2017-07-02

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

author
tandy1 made it!(author)2017-04-03

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

author
TheElectromania made it!(author)2017-05-14

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.

author
ThomasL138 made it!(author)2016-11-30

I just set this up with a whisper node, soldering a cable to the H pad (top right in 3rd picture of step one) this way I can use it on 3.3v.

I use the lowpower library, and can get it to use 95uA in powerdown mode.

IMG_2511.JPGIMG_2513.JPGIMG_2524.JPG
author
TheElectromania made it!(author)2016-11-30

great... thanks for sharing

author
ThomasL138 made it!(author)2016-11-24

Nice instructable!

author
DanielD112 made it!(author)2016-09-23

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

author
TheElectromania made it!(author)2016-10-12

yes many hackers do that ...

About This Instructable

18,761views

47favorites

License:

Bio: A Researcher, an Engineer and an electronics enthusiast
More by TheElectromania:Quick Digital thermometer using cheap USB to TTL converter and  DS18B20 - WITHOUT Arduino or Raspberry PiDigital thermometer on OLED display using ESP8266 ESP-12E NodeMCU and DS18B20 temperature sensorPIR Motion Detector With Arduino: Operated at Lowest Power Consumption Mode
Add instructable to: