sommeil-batterie.ino

LilyPad Arduino · File : sommeil-batterie.ino · Language : Arduino · Use case : Endormir la carte entre deux mesures pour économiser la batterie

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

A LilyPad Arduino (ATmega168V/328V, 8 MHz, 3.3 V) with its sew tabs, programmed via an FTDI cable (breakout) and powered by 3.7 V (LiPo) or 5 V on V-REG. 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 « LilyPad Arduino » and the FTDI port, then Upload. Conductive thread adds a few ohms of resistance: keep runs short and insulate crossings.

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 !"));
}

← Back to the board