station-air.ino

Arduino Nano Every · File : station-air.ino · Language : Arduino · Use case : Station air complètes sur le bus I2C

Air-quality station in three wires: the BME280 on I2C supplies temperature, humidity, pressure and estimated altitude, which the Nano Every publishes as CSV every two seconds. The 4809 Wire bus sits on A4/A5, like the old Nano.

Hardware

An Arduino Nano Every (ATmega4809 at 20 MHz, same footprint as the Nano, micro-B USB, separate UART chip, 5 V pins, drop-in compatibility with the classic Nano). Nano Every, I2C BME280 (address 0x76 or 0x77 per strap), USB cable.

Wiring

BME280 VCC→3.3 V (never 5 V on this module), GND, SDA→A4, SCL→A5; the module carries its pull-ups.

How it works

The begin(0x76)||begin(0x77) test covers both possible sensor addresses. readAltitude converts pressure to altitude with the international atmosphere formula.

Running it

Install the Arduino megaAVR Boards package in the IDE, select Arduino Nano Every, upload. The USB Serial is separate from hardware Serial1 (RX/TX pins): classic serial code works as is.

Variants

Add a BME688/BME680 for equivalent CO2, or log the CSV to a PC over the serial port for a long campaign.

station-air.ino

// BME280 (I2C 0x76) sur Nano Every : T/H/P via la bibliotheque Adafruit.
// Le bus Wire du 4809 est sur A4/A5 comme sur l'ancien Nano.
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

Adafruit_BME280 bme;

unsigned long dernier = 0;

void setup() {
  Serial.begin(115200);
  Wire.begin();
  if (!bme.begin(0x76) && !bme.begin(0x77)) {
    Serial.println(F("BME280 absent (0x76/0x77)"));
    while (true);
  }
  Serial.println(F("T;H;P;Alt"));
}

void loop() {
  if (millis() - dernier < 2000) return;
  dernier = millis();
  float t = bme.readTemperature();
  float h = bme.readHumidity();
  float p = bme.readPressure() / 100.0;
  float a = bme.readAltitude(1013.25);
  Serial.print(t, 2);  Serial.print(';');
  Serial.print(h, 1);  Serial.print(';');
  Serial.print(p, 1);  Serial.print(';');
  Serial.println(a, 1);
}

← Back to the board