Is there a clean way for an Arduino to cut its own power?
I’m hacking into an existing circuit that is battery-powered, and I would like to be able to, say, reset the microcontroller, which then waits for some kind of input from the hacked device, and then when it’s done processing, it turns itself off (to save batteries on the host circuit).
Absolutely! And its quite easy to do when you use some of the lower level functionally of the Arduino’s AVR. Most micro controllers contain a piece of hardware called a Watchdog Timer which, when enabled, will perform either a hard or soft reset of the device. The cool thing about utilizing the watchdog on the newer Arduinos (ATMEGA168/328) is that you can actually execute a function after each reset (ATMEGA8s can only perform a hard reset). There are two things you need to do to properly utilize the watchdog. First, when you initialize it, you set the quantity of time the micro controller waits before performing the reset, set in “setup_watchdog(X);.” You can set X to 0=16ms, 1=32ms, 2=64ms, 3=128ms, 4=250ms, 5=500ms, 6=1024m, 7=2048ms, 8=4096ms or 9=8192ms. The second thing you need to do is “pet” the watchdog in order to prevent unwanted resets. By periodically adding “wdt_reset()” to your code, you reset the watchdog’s timer and preventing the reset. This is also a good way of adding stability to your code. If you software hangs, the watchdog with reset the device.
With regards to power consumption, you are in luck. If properly utilized, the Arduino can draw mere micro-amps when put to sleep. This sleep function, when paired with the watchdog, can result in a very low power and stable device. There are approximately 5 sleep modes that dictate which functions are put to sleep and are detailed in the AVR doc. When I set my Arduino to POWER_DOWN mode, I measured only 20.7uA at 3.3V :-).
There is a good page on Arduino’s site that demos the sleep functions.
Check out Nathan Nawrath’s Nightingale project, which gives a very good example as to using the watchdog and sleep functions.
You might also want to check out the Narcolpetic library for Arduino, which makes putting Arduino to sleep super easy!
I hope this answered your question and good luck with your sleepy Arduino!
Next up is Hal with a question about teaching future EEs!
Don’t forget, everyone is invited to ask a question!
“Ask an Educator” questions are answered by Adam Kemp, a high school teacher who has been teaching courses in Energy Systems, Systems Engineering, Robotics and Prototyping since 2005.
Have an amazing project to share? Join the SHOW-AND-TELL every Wednesday night at 7:30pm ET on Google+ Hangouts.
Join us every Wednesday night at 8pm ET for Ask an Engineer!
Learn resistor values with Mho’s Resistance or get the best electronics calculator for engineers “Circuit Playground” – Adafruit’s Apps!
Maker Business — The Essential Guide to Electronics in Shenzhen
Wearables — Lithium Batteries: a soft touch goes a long way
Electronics — Capacitor Polarity Markers
Biohacking — Can Gizmos Cure Insomnia? – The New Yorker
Sorry, the comment form is closed at this time.