cycles-sleep.ino
The MKR WAN 1300 is built for battery nodes: this cycle wakes every fifteen minutes, measures, emits a short SF9 frame, then sleeps modem and MCU. With no serial port or LED, average current drops below half a milliamp.
Hardware
An Arduino MKR WAN 1300 (SAMD21 microcontroller, Semtech SX1272 LoRa modem for point-to-point links, no built-in LoRaWAN stack, 868/915 MHz antenna). 2x AAA pack or LiPo, sensor on A1, antenna; weatherproof enclosure for outdoors.
Wiring
Sensor on A1; if the sensor needs switched power, drive its VCC from a dedicated pin rather than A0.
How it works
The SX1272 draws ~150 µA in sleep, the SAMD21 in deepSleep ~2 µA apart from RTC. The RTC alarm wakes the MCU; the full radio cycle lasts under a second.
Running it
Install Arduino SAMD Boards and the MKRWAN library, select the board, upload. You need TWO LoRa boards (two MKR WAN 1300s, or a 1300 and a 1310) to see exchanges; set the same frequency plan in the code.
Variants
Also wake on an interrupt (pulse meter) for water metering, or raise the SF at night when radio noise drops.
cycles-sleep.ino
// Cycle sobre : reveil RTC, mesure, emission LoRa, deepSleep.
// Une trame toutes les 15 min sur 2x AAA -> plusieurs mois.
#include <MKRWAN.h>
#include <ArduinoLowPower.h>
#include <RTCZero.h>
LoRaModem modem;
RTCZero rtc;
void setup() {
// Pas de Serial en production : la LED serie consomme ~5 mA
if (!modem.begin(EU868)) {
pinMode(LED_BUILTIN, OUTPUT); // clignotement d'erreur
while (true) { digitalWrite(LED_BUILTIN, HIGH); delay(100);
digitalWrite(LED_BUILTIN, LOW); delay(100); }
}
modem.setFrequency(868.5);
modem.setSpreadingFactor(9); // portee sans sacrifier l'energie
rtc.begin();
LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, NULL, RISING);
}
void loop() {
// 1) mesurer
int brut = analogRead(A1);
// 2) emettre
modem.beginPacket();
modem.print("A="); modem.print(brut);
modem.endPacket(false);
// 3) dormir jusqu'a la prochaine alarme
modem.sleep(); // SX1272 en veille
rtc.setAlarmEvery(15 * 60);
rtc.enableAlarm(rtc.MATCH_SS);
LowPower.deepSleep();
}