Wearable Environmental Monitoring PCB Design


Make a circuit that blinks a red LED once per second.
Power it with a 9V block battery through an on/off switch.
Use components that are easy to hand-solder.

Firmware Starter — AeriSense ESP32-WROOM-32D
Platform & Toolchain
  • MCU: ESP32-WROOM-32D
  • Framework: Arduino for fast prototype bring-up
  • Build system: PlatformIO
  • Key peripherals: BME688 over I2C, MAX17043 over I2C, UART0 external programming/debug, status LED on GPIO25, fuel-gauge alert on GPIO34
Pin Mapping

Table


FunctionESP32 GPIOSchematic NetConnected ToNotes
I2C SDAGPIO21I2C_SDABME688 SDI, MAX17043 SDA4.7k pull-up to 3.3V
I2C SCLGPIO22I2C_SCLBME688 SCK, MAX17043 SCL4.7k pull-up to 3.3V
UART0 TXGPIO1UART0_TXProgramming header Pin 1External USB-UART RX connects here
UART0 RXGPIO3UART0_RXProgramming header Pin 2External USB-UART TX connects here
EN / ResetENESP_ENReset button, header Pin 510k pull-up + 1uF to GND
BOOTGPIO0ESP_IO0Boot button, header Pin 6Hold low during reset for bootloader
Status LEDGPIO25STATUS_LEDR9 + D3Active high LED drive
Fuel gauge alertGPIO34FG_ALRTMAX17043 ~ALRTInput only; external 10k pull-up
Dependencies & Project Setup
Create a PlatformIO project with this platformio.ini:

Ini


[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
monitor_speed = 115200
upload_speed = 921600
lib_deps =
    adafruit/Adafruit BME680 Library@^2.0.4
    adafruit/Adafruit Unified Sensor@^1.1.14
    sparkfun/SparkFun MAX1704x Fuel Gauge Arduino Library@^1.0.4
Complete Firmware Source (src/main.cpp)

Cpp


#include <Arduino.h>
#include <Wire.h>
#include <WiFi.h>
#include <HTTPClient.h>
#include <Adafruit_BME680.h>
#include <SparkFun_MAX1704x_Fuel_Gauge_Arduino_Library.h>

#define I2C_SDA_PIN 21
#define I2C_SCL_PIN 22
#define STATUS_LED_PIN 25
#define FUEL_ALERT_PIN 34

#define BME688_ADDR 0x76
#define SENSOR_INTERVAL_MS 5000

const char* WIFI_SSID = "YOUR_WIFI_SSID";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";
const char* CLOUD_ENDPOINT = "http://example.com/aerisense";

Adafruit_BME680 bme;
SFE_MAX1704X fuelGauge(MAX1704X_MAX17043);

unsigned long lastSensorRead = 0;
bool bmeReady = false;
bool fuelReady = false;

void setStatusBlink(uint8_t count) {
  for (uint8_t i = 0; i < count; i++) {
    digitalWrite(STATUS_LED_PIN, HIGH);
    delay(120);
    digitalWrite(STATUS_LED_PIN, LOW);
    delay(120);
  }
}

void initWiFi() {
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
  Serial.print("Connecting to WiFi");

  for (int i = 0; i < 20 && WiFi.status() != WL_CONNECTED; i++) {
    digitalWrite(STATUS_LED_PIN, !digitalRead(STATUS_LED_PIN));
    delay(500);
    Serial.print('.');
  }

  if (WiFi.status() == WL_CONNECTED) {
    Serial.printf("\nWiFi connected: %s\n", WiFi.localIP().toString().c_str());
    digitalWrite(STATUS_LED_PIN, HIGH);
  } else {
    Serial.println("\nWiFi not connected; continuing offline.");
    digitalWrite(STATUS_LED_PIN, LOW);
  }
}

void initBME688() {
  bmeReady = bme.begin(BME688_ADDR, &Wire);
  if (!bmeReady) {
    Serial.println("BME688 not found at 0x76. Check CSB=3V3 and SDO=GND wiring.");
    return;
  }

  bme.setTemperatureOversampling(BME680_OS_8X);
  bme.setHumidityOversampling(BME680_OS_2X);
  bme.setPressureOversampling(BME680_OS_4X);
  bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
  bme.setGasHeater(320, 150);
  Serial.println("BME688 initialized.");
}

void initFuelGauge() {
  fuelReady = fuelGauge.begin(Wire);
  if (!fuelReady) {
    Serial.println("MAX17043 fuel gauge not found. Check I2C and VBAT filter wiring.");
    return;
  }
  fuelGauge.quickStart();
  Serial.println("MAX17043 initialized.");
}

void postToCloud(float tempC, float humidity, float pressureHpa, float gasKohms, float battV, float battPct) {
  if (WiFi.status() != WL_CONNECTED) return;

  HTTPClient http;
  http.begin(CLOUD_ENDPOINT);
  http.addHeader("Content-Type", "application/json");

  String payload = "{";
  payload += "\"temp_c\":" + String(tempC, 2) + ",";
  payload += "\"humidity_pct\":" + String(humidity, 2) + ",";
  payload += "\"pressure_hpa\":" + String(pressureHpa, 2) + ",";
  payload += "\"gas_kohms\":" + String(gasKohms, 2) + ",";
  payload += "\"battery_v\":" + String(battV, 3) + ",";
  payload += "\"battery_pct\":" + String(battPct, 1);
  payload += "}";

  int code = http.POST(payload);
  Serial.printf("HTTP POST code: %d\n", code);
  http.end();
}

void readAndReportSensors() {
  float tempC = NAN;
  float humidity = NAN;
  float pressureHpa = NAN;
  float gasKohms = NAN;
  float battV = NAN;
  float battPct = NAN;

  if (bmeReady && bme.performReading()) {
    tempC = bme.temperature;
    humidity = bme.humidity;
    pressureHpa = bme.pressure / 100.0f;
    gasKohms = bme.gas_resistance / 1000.0f;
  } else {
    Serial.println("BME688 read failed.");
  }

  if (fuelReady) {
    battV = fuelGauge.getVoltage();
    battPct = fuelGauge.getSOC();
  }

  Serial.printf("T=%.2f C, RH=%.2f %%, P=%.2f hPa, Gas=%.2f kOhm, Batt=%.3f V %.1f %%\n",
                tempC, humidity, pressureHpa, gasKohms, battV, battPct);

  postToCloud(tempC, humidity, pressureHpa, gasKohms, battV, battPct);
}

void setup() {
  pinMode(STATUS_LED_PIN, OUTPUT);
  pinMode(FUEL_ALERT_PIN, INPUT);
  digitalWrite(STATUS_LED_PIN, LOW);

  Serial.begin(115200);
  delay(300);
  Serial.println("AeriSense firmware starting...");

  Wire.begin(I2C_SDA_PIN, I2C_SCL_PIN);
  Wire.setClock(400000);

  initBME688();
  initFuelGauge();
  initWiFi();
  setStatusBlink(3);
}

void loop() {
  unsigned long now = millis();

  if (digitalRead(FUEL_ALERT_PIN) == LOW) {
    Serial.println("Fuel gauge low-battery alert asserted.");
  }

  if (WiFi.status() != WL_CONNECTED) {
    initWiFi();
  }

  if (now - lastSensorRead >= SENSOR_INTERVAL_MS) {
    lastSensorRead = now;
    readAndReportSensors();
  }
}
Build & Flash Instructions

Bash


pio run
pio run -t upload
pio device monitor
Bootloader entry with external USB-UART adapter:
  1. Connect adapter GND to J3 Pin 3, 3V3 reference to J3 Pin 4, adapter RX to J3 Pin 1, adapter TX to J3 Pin 2.
  2. Hold BOOT, tap RESET, then release BOOT.
  3. Run upload command.
Use a 3.3V UART adapter only. Do not connect 5V UART signals directly to ESP32 pins.
  • Platform & Toolchain

  • Pin Mapping

  • Dependencies & Project Setup

  • Complete Firmware Source (`src/main.cpp`)

  • Build & Flash Instructions