sommeil-batterie.ino
In power-down mode the 328P draws a few microamps instead of milliamps awake — the key to sewn or battery projects. Pressing the pin-2 button (INT0) wakes the microcontroller.
Hardware required
An Arduino Duemilanove (ATmega168 or 328P, 16 MHz, 5 V) with its mini-USB-B cable; the serial port appears once the FTDI driver is installed. 1 wake button; battery supply.
Wiring
Button between pin 2 and GND (pull-up is internal).
How it works
set_sleep_mode shuts everything but the external interrupt; wake runs the ISR then resumes after sleep_cpu. Remove the pull-up if a sensor drives wake. In the Arduino IDE, select « Arduino Duemilanove » (or « Diecimila » for very old boards) and the FTDI port, then Upload. The ATmega168 leaves only 14 KB for the sketch.
Going further
Also wake periodically with the watchdog (wdt_enable) for a standalone logger.
sommeil-batterie.ino
// Sommeil profond (mode power-down) reveille par interruption externe.
#include <avr/sleep.h>
#include <avr/wdt.h>
const int REVEIL = 2; // interruption externe INT0
void reveilISR() { wdt_reset(); }
void setup() {
Serial.begin(9600);
pinMode(REVEIL, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(REVEIL), reveilISR, LOW);
}
void loop() {
int mesure = analogRead(A0);
Serial.print(F("Mesure: "));
Serial.println(mesure);
delay(50); // laisse partir la ligne serie
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_cpu(); // ~microampere ; reveil sur appui (broche 2 LOW)
sleep_disable();
Serial.println(F("Reveil !"));
}