0
0
Arduinoprogramming~30 mins

Arduino sleep modes - Mini Project: Build & Apply

Choose your learning style9 modes available
Arduino Sleep Modes
📖 Scenario: You have a small Arduino project that runs on battery power. To save battery, you want the Arduino to sleep when it is not doing anything and wake up when a button is pressed.
🎯 Goal: Build a simple Arduino program that puts the board into sleep mode and wakes it up using a button press.
📋 What You'll Learn
Use the avr/sleep.h library to control sleep modes
Set up a button on pin 2 to wake the Arduino from sleep
Put the Arduino into sleep mode inside the loop()
Print a message to the Serial Monitor when the Arduino wakes up
💡 Why This Matters
🌍 Real World
Battery-powered devices like remote sensors or wearable gadgets use sleep modes to save power and extend battery life.
💼 Career
Understanding sleep modes is important for embedded systems engineers working on low-power IoT devices and hardware optimization.
Progress0 / 4 steps
1
Setup button input and Serial communication
Write code to set pin 2 as an input with an internal pull-up resistor. Also, start Serial communication at 9600 baud in the setup() function.
Arduino
Need a hint?

Use pinMode(2, INPUT_PULLUP); to set the button pin. Use Serial.begin(9600); to start serial communication.

2
Configure sleep mode and interrupt
Add code to set the sleep mode to SLEEP_MODE_PWR_DOWN and attach an interrupt to pin 2 that will wake the Arduino when the button is pressed.
Arduino
Need a hint?

Use set_sleep_mode(SLEEP_MODE_PWR_DOWN); to set the sleep mode. Use attachInterrupt(digitalPinToInterrupt(2), wakeUp, LOW); to attach the interrupt.

3
Put Arduino to sleep inside loop
Inside the loop(), add code to put the Arduino to sleep using sleep_enable() and sleep_cpu(). Make sure to disable sleep after waking up.
Arduino
Need a hint?

Use sleep_enable(); before sleep_cpu(); and sleep_disable(); after waking up. Print messages before and after sleep.

4
Test and observe output
Upload the complete program and observe the Serial Monitor. The Arduino should print Going to sleep..., then sleep until the button on pin 2 is pressed, then print Woke up!. Write the exact output you see after pressing the button once.
Arduino
Need a hint?

Open the Serial Monitor at 9600 baud. Press the button connected to pin 2 once. You should see the messages printed before and after sleep.