Air quality map on a bicycle
Build it step by step
0 of 7 doneTest the PMS5003
Print PM2.5 over Serial.
Test the GPS
Wait for a fix outdoors.
Add the SD card
Write one line.
Set the boost to 5.0 V
With a meter, before connecting.
Power everything from the cell
Check it runs.
Ride a short route
Log and import.
Colour the map
By PM2.5.
How do you build an air quality map on a bicycle?
A PMS5003 and GPS on a bike log PM2.5 with location every few seconds, then a map shows which roads have the dirtiest air. You need ESP32 DevKit V1, PMS5003 particulate matter sensor, GPS module NEO-6M, MicroSD Card Module, 18650 cell 2600 mAh (branded), Battery holder 18650 single, TP4056 module with protection (USB-C), MT3608 Boost Module and ABS project box (100 × 60 × 25 mm). It takes 7 steps and about 180 minutes.
- Level
- Intermediate
- Time
- About 180 min
- Parts
- 9
Wiring
| From | To | Why |
|---|---|---|
| 18650 holder | TP4056 module B+ and B- | Charging and protection |
| TP4056 OUT+ and OUT- | MT3608 IN+ and IN- | Battery power |
| MT3608 OUT | ESP32 VIN, PMS5003 VCC (5 V), common ground | Set to 5.0 V with a meter before connecting anything |
| PMS5003 TX | ESP32 GPIO16 | Particle data |
| GPS TX | ESP32 GPIO25 | Position data |
| GPS VCC and GND | ESP32 3V3 and GND | Power |
| SD module CS, MOSI, MISO, SCK | ESP32 GPIO5, GPIO23, GPIO19, GPIO18 | SPI |
| SD module VCC and GND | ESP32 VIN (5 V) and GND | Power (most modules need 5 V) |
Code
Air quality changes from street to street, and one reading at home hides that. The sensor measures fine dust by counting how much a small laser beam is scattered, the GPS gives the place, and every five seconds the pair is written as a line in a file you can import into a free map tool, colouring the points by PM2.5. Ride the same route at rush hour and at midday, and compare a main road with a side lane. The sensor's own fan needs 5 V, so a single 18650 cell goes through a charger board with protection and a boost module that you set to exactly 5.0 V with a meter before connecting the ESP32. Use a branded 18650 in a proper holder, charge it only through the charger board, and never let the bare cell short against metal; keep the box out of direct sun and hot cars. The GPS needs a view of the sky, so give it a few minutes at start. The file contains where you were, so share it carefully. Readings from low-cost sensors are good for comparing places, not for official limits, and the sensor is not rated for rain. Arduino IDE with the ESP32 boards package 2.0.x, board "ESP32 Dev Module".
Runs on a virtual ESP32 Dev Module in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
// Bicycle air quality logger: PMS5003 (Serial2) and a GPS (Serial1 on GPIO25) write a CSV line every 5 seconds once there is a fix.
// Libraries: TinyGPSPlus, SD. Board: ESP32 Dev Module. Import the CSV into a free map tool and colour points by pm25.
#include <HardwareSerial.h>
#include <SPI.h>
#include <SD.h>
#include <TinyGPSPlus.h>
TinyGPSPlus gps;
HardwareSerial GPSSerial(1);
const int SD_CS = 5;
uint16_t pm25 = 0, pm10 = 0;
bool pmValid = false;
unsigned long lastLog = 0;
void readPMS() {
static uint8_t buf[32]; static int n = 0;
while (Serial2.available()) {
uint8_t b = Serial2.read();
if (n == 0 && b != 0x42) continue;
if (n == 1 && b != 0x4D) { n = 0; continue; }
buf[n++] = b;
if (n == 32) {
n = 0;
uint16_t sum = 0; for (int i = 0; i < 30; i++) sum += buf[i];
if (sum == (uint16_t)((buf[30] << 8) | buf[31])) {
pm25 = (buf[12] << 8) | buf[13]; // PM2.5 in micrograms per cubic metre (atmospheric)
pm10 = (buf[14] << 8) | buf[15];
pmValid = true;
}
}
}
}
void setup() {
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, 16, -1);
GPSSerial.begin(9600, SERIAL_8N1, 25, -1);
if (!SD.begin(SD_CS)) { Serial.println("SD card not found"); while (true) delay(1000); }
File f = SD.open("/airlog.csv", FILE_APPEND);
if (f) { if (f.size() == 0) f.println("date,time,lat,lon,pm25,pm10"); f.close(); }
}
void loop() {
while (GPSSerial.available()) gps.encode(GPSSerial.read());
readPMS();
if (millis() - lastLog >= 5000 && pmValid && gps.location.isValid() && gps.date.isValid()) {
lastLog = millis();
File f = SD.open("/airlog.csv", FILE_APPEND);
if (f) {
char line[96];
snprintf(line, sizeof(line), "%04d-%02d-%02d,%02d:%02d:%02d,%.6f,%.6f,%u,%u", gps.date.year(), gps.date.month(), gps.date.day(),
gps.time.hour(), gps.time.minute(), gps.time.second(), gps.location.lat(), gps.location.lng(), pm25, pm10);
f.println(line); f.close();
Serial.println(line);
}
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Fix | Lines start appearing on Serial |
| Blow near the sensor | PM2.5 changes |
| File | Opens in a spreadsheet |
| Map | Points follow the route |
If it does not work
No lines
Wait for the GPS fix and check the PMS wiring.
SD error
Format the card as FAT32 and check 5 V on the module.
Resets on the road
Check the boost is set to 5.0 V and well secured.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the air quality map on a bicycle?
ESP32 DevKit V1, PMS5003 particulate matter sensor, GPS module NEO-6M, MicroSD Card Module, 18650 cell 2600 mAh (branded), Battery holder 18650 single, TP4056 module with protection (USB-C), MT3608 Boost Module and ABS project box (100 × 60 × 25 mm).
How long does the air quality map on a bicycle take to build?
About 180 minutes for a intermediate maker, in 7 steps.
How do I know the air quality map on a bicycle works?
Fix: Lines start appearing on Serial. Blow near the sensor: PM2.5 changes. File: Opens in a spreadsheet.
No lines: what should I check?
Wait for the GPS fix and check the PMS wiring.
SD error: what should I check?
Format the card as FAT32 and check 5 V on the module.
Resets on the road: what should I check?
Check the boost is set to 5.0 V and well secured.
