Wearable Environmental Monitoring PCB Design
Table
| Function | ESP32 GPIO | Schematic Net | Connected To | Notes |
|---|---|---|---|---|
| I2C SDA | GPIO21 | I2C_SDA | BME688 SDI, MAX17043 SDA | 4.7k pull-up to 3.3V |
| I2C SCL | GPIO22 | I2C_SCL | BME688 SCK, MAX17043 SCL | 4.7k pull-up to 3.3V |
| UART0 TX | GPIO1 | UART0_TX | Programming header Pin 1 | External USB-UART RX connects here |
| UART0 RX | GPIO3 | UART0_RX | Programming header Pin 2 | External USB-UART TX connects here |
| EN / Reset | EN | ESP_EN | Reset button, header Pin 5 | 10k pull-up + 1uF to GND |
| BOOT | GPIO0 | ESP_IO0 | Boot button, header Pin 6 | Hold low during reset for bootloader |
| Status LED | GPIO25 | STATUS_LED | R9 + D3 | Active high LED drive |
| Fuel gauge alert | GPIO34 | FG_ALRT | MAX17043 ~ALRT | Input only; external 10k pull-up |
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
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(); } }
Bash
pio run pio run -t upload pio device monitor
Platform & Toolchain
Pin Mapping
Dependencies & Project Setup
Complete Firmware Source (`src/main.cpp`)
Build & Flash Instructions