meteo-lora.ino

Arduino MKR WAN 1300 · File : meteo-lora.ino · Language : Arduino · Use case : Envoyer température et humidité par LoRa toutes les 10 min

Complete standalone weather station: the BME280 on I2C supplies temperature, humidity and pressure, the MKR WAN 1300 broadcasts them over LoRa every ten minutes. The compact T;H;P frame fits in 20 bytes, ideal for one receiver serving many stations.

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). MKR WAN 1300, I2C BME280 sensor (address 0x76), LiPo battery for autonomy, a second LoRa board as receiver.

Wiring

BME280 VCC→3.3 V, GND→GND, SDA→SDA pin, SCL→SCL pin of the MKR WAN I2C header.

How it works

The sketch checks the BME280 at boot, reads the three quantities, formats them into one semicolon line, and publishes without ACK to save airtime and battery.

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

Prefix the frame with a station ID to share one receiver, or switch to binary (5 bytes) to quarter the airtime.

meteo-lora.ino

// Station meteo LoRa P2P : BME280 (I2C) -> MKR WAN 1300 -> recepteur.
#include <MKRWAN.h>
#include <Adafruit_BME280.h>

LoRaModem modem;
Adafruit_BME280 bme;

unsigned long dernier = 0;

void setup() {
  Serial.begin(115200);
  if (!modem.begin(EU868)) while (true);
  modem.setFrequency(868.5);
  if (!bme.begin(0x76)) {
    Serial.println(F("BME280 absent (0x76)"));
    while (true);
  }
}

void loop() {
  if (millis() - dernier < 600000) return; // 10 min
  dernier = millis();
  float t = bme.readTemperature();
  float h = bme.readHumidity();
  float p = bme.readPressure() / 100.0;
  // Trame compacte : T;H;P avec 1 decimale
  String trame = String(t, 1) + ";" + String(h, 1) + ";" + String(p, 1);
  modem.beginPacket();
  modem.print(trame);
  if (modem.endPacket(false) > 0)
    Serial.println("publie : " + trame);
  else
    Serial.println(F("emission KO"));
}

← Back to the board