Simple ESP32-based environmental sensing prototype.
Collects:
- Gas concentration proxy (MQ-2)
- Temperature (DHT sensor)
- Moving average smoothing (SMA)
Designed for low-bandwidth telemetry preprocessing (e.g., CubeSat / remote node concept).
- Analog output → ESP32 GPIO 34
- Digital output → ESP32 GPIO 4 (unused in this code)
- Used for gas concentration proxy
- Used for temperature readings
dht.readTemperature()is called every loop- Humidity not used in this version
- 12-bit ADC resolution (
analogReadResolution(12)) - 0–4095 ADC range
- 3.3V reference
float getGasPPM(int analogPin)Steps:
- Read raw ADC value (0–4095)
- Convert to voltage
- Convert voltage → percentage of 3.3V
- Scale percentage to proxy PPM (0–400 range)
Formula used:
voltage = raw * (3.3 / 4095.0)
gasPercent = (voltage / 3.3) * 100
proxyPPM = gasPercent * 4
#define TOTAL_SAMPLE 3A rolling 3-sample window is used.
Structure:
struct SMA {
float window[3];
}Each loop:
- New value inserted
- Old values shifted
- Average calculated
Formula:
SMA = (w0 + w1 + w2) / 3
Smoothing helps reduce sensor noise before telemetry transmission.
Every 3 seconds:
- Read gas proxy PPM
- Read temperature
- Add values to SMA buffers
- After 3 samples → print SMA results
Output example:
proxy ppm: 173.24
G.getSMA() = 168.12
T.getSMA() = 29.87
Conceptually designed for:
-
Onboard environmental sensing
-
Local filtering (SMA)
-
Reduced-noise telemetry transmission
-
Future integration with:
- GPS (e.g., Quectel L80)
- Humidity sensing
- Risk scoring logic
Advantages:
- Very low computational cost
- Minimal memory usage
- Good noise reduction
- Ideal for embedded systems
Tradeoff:
- Adds slight latency (window size dependent)
- MQ-2 values are not calibrated
- No real PPM curve conversion (Rs/R0 method not implemented)
- DHT object not fully defined in snippet
- No GPS integration yet
- No packet encoding or radio transmission
- Implement proper MQ-2 logarithmic PPM calculation
- Store clean-air baseline (R0)
- Add humidity
- Add GPS coordinates
- Encode structured telemetry packet
- Add anomaly detection / wildfire risk scoring
-
Requires:
- Arduino framework
- DHT library
-
Serial baud rate:
9600 -
ADC resolution:
12-bit










