A Guide to Putting Your Arduino to Sleep

Published

Introduction: A Guide to Putting Your Arduino to Sleep

About: My Name is Ab Kurk, and I help people explore the wonderful world of Arduino micro controllers with tutorial,tips and project ideas

Sometimes we are in a situation that requires us to put an Arduino in a place where plugging it in to the power grid is not an option. This happens often when we try to log information in a remote site, or only need to have your Arduino active at a specific interval/action.

Adafruit DS3231 Precision RTC BreakoutAdafruit

In these cases putting your Arduino to sleep is the perfect thing to do. Their attention is only required for a short amount of time e.g. log data in a specific interval, or put out an alert when a predetermined event happens. In this tutorial we are going to experiment with putting your Arduino to sleep and see how to turn your Arduino back on. This tutorial familiarizes you with the concept and has a small exercise to see what it takes to put an Arduino to sleep.

Step 1: Materials Needed/ What Board to Use

WHAT BOARD TO USE?

In this tutorial we will be using the Arduino Uno just because it is an easier board to prototype on. In a real live project I would use an Arduino Pro Mini for this. The Arduino Uno and the Arduino Pro Mini have very similar characteristics, the Arduino pro mini has a lot less hardware to power (e.g. the USB portion, extra leds, and some other stuff) thus using a lot less power. This is the reason why the Arduino Pro mini is a better choice. To give an example a Uno uses between 30-40 mA when awake and about 19 mA when asleep. The Pro Mini uses 25mA when awake and 0.57 mA when asleep. As every mA matters when hooking it up to a battery you can see that there is no contest and the Arduino Pro Mini is the winner.

Note: As a beginner Maker the Arduino Pro Mini might be a bit intimidating, but there is no reason for it. Yes you need to solder the headers onto the board, and you need a FTDI cable to upload your sketch, but other than that there are no major differences.

Step 2: SLEEP MODE

When you look at the documentation of the ATmega328p (click this link for a copy of this document) processor used for both Arduino Uno and the Arduino Pro mini you notice there are many different sleep modes available. But in a real world scenario there is really only one mode that is useful; The Power down mode (SLEEP_MODE_PWR_DOWN).
When you put your Arduino to sleep it turns off all unnecessary components, reducing the power consumption of the MCU (Microcontroller Unit). In this mode the only way you can wake it up is the use of an external influence (e.g. we give it a nudge to wake up). We will examine how to do this a bit later in this tutorial.

Step 3: ​INTERRUPTS

Before we go into the code to put an Arduino to sleep we need to understand the interrupt concept. The best way to describe it is ; You are working on something you really need to concentrate on. You wear headphones blasting your music loud to drown out your surrowndings . You are so concentrated on this that the outside world is lost to you. The only way to get your attention is by giving you a nudge. After you receive this nudge you pay attention to what the interruption is about, and after dealing with it you put the music back on and continue with your task.

Note: I am not going to go to deep into what interrupts are good for, but if you want to learn more about this concept check out my tutorial (Using Interrupts to improve the functionality of your project) on this topic

Most true Arduino’s have a couple of pins that do just that. The Uno and the Pro Mini have 2 pins (d2 and d3) that have the capability to interrupt what the Arduino is doing. With this we can nudge the Arduino back to a waking state.

Step 4: The Code/Sketch

You can Download the completed completed sketch from my site by clicking on this link To get a complete description and explanation how the code works you can go to my blog by clicking the Link: A guide to putting your Arduino to sleep.

Step 5: EXERCISE 1

STEP 1)

Now it is time to upload the sketch. But before doing that put a jumper wire in d2. Just leave it unplugged on the other end for now. Load your sketch and wait 5 seconds for the LED to turn off and the Arduino to go to sleep.

STEP 2)

After the LED turns off insert the other end of the jumper wire in a GND pin on your Arduino Uno. This will pull pin 2 LOW triggering the interrupt, thus awaking the sleeping Arduino. After the LED comes back on you can remove the jumper wire out of GND and 5 seconds later the Arduino goes back to sleep.

For a example Project where I use a Real Time Clock (RTC ) to wake up an Humidity and Temperature Data Logger just click the following link: EXAMPLE USING A RTC TO WAKE-UP AN ARDUINO DATA LOGGER. It is a great example how it would work in the real world

Share

    Recommendations

    • Oil Contest

      Oil Contest
    • Woodworking Contest

      Woodworking Contest
    • Make it Move Contest

      Make it Move Contest
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    Comments