ASK AN EDUCATOR! “Is there a way for an Arduino to turn itself off?”

Jimbo asks:

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!

Click here!

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

Stop breadboarding and soldering – start making immediately! Adafruit’s Circuit Playground is jam-packed with LEDs, sensors, buttons, alligator clip pads and more. Build projects with Circuit Playground in a few minutes with the drag-and-drop MakeCode programming site, learn computer science using the CS Discoveries class on code.org, jump into CircuitPython to learn Python and hardware together, TinyGO, or even use the Arduino IDE. Circuit Playground Express is the newest and best Circuit Playground board, with support for CircuitPython, MakeCode, and Arduino. It has a powerful processor, 10 NeoPixels, mini speaker, InfraRed receive and transmit, two buttons, a switch, 14 alligator clip pads, and lots of sensors: capacitive touch, IR proximity, temperature, light, motion and sound. A whole wide world of electronics and coding is waiting for you, and it fits in the palm of your hand.

Join 15,000+ makers on Adafruit’s Discord channels and be part of the community! http://adafru.it/discord

What do you want from CircuitPython in 2020?

Have an amazing project to share? The Electronics Show and Tell is every Wednesday at 7:30pm ET! To join, head over to YouTube and check out the show’s live chat – we’ll post the link there.

Join us every Wednesday night at 8pm ET for Ask an Engineer!

Follow Adafruit on Instagram for top secret new products, behinds the scenes and more https://www.instagram.com/adafruit/

Maker Business — Apple’s Mac Pro doesn’t fall far from the tree

Wearables — How to twist light

Electronics — Proceed with caution

Biohacking — Vitamin-C + Gelatin for Accelerated Recovery

Python for Microcontrollers — CircuitPython powers the Open Hardware Summit for 2020! #Python #Adafruit #CircuitPython @circuitpython @micropython @ThePSF @Adafruit

Adafruit IoT Monthly — Learning from IoT Projects, Adafruit Joins the LoRa Alliance, Ring Ransoms, and more!

Microsoft MakeCode — MakeCode: Opening a World of Possibilities

Get the only spam-free daily newsletter about wearables, running a "maker business", electronic tips and more! Subscribe at AdafruitDaily.com !


  1. Useful post thanks!

  2. Thank you very much for answering my question! I will look into Watchdog and Sleep functions. Keep doing what you’re doing; the internet thanks you!

Sorry, the comment form is closed at this time.