Robin Harris, Connected Humber member and initiator of the Monitair Air Quality Project talks us through his air quality sensor prototype.


My objective for this early prototype is to design and build a device able to read SDS011 values for PM2.5 & PM10, BME280 values for temperature, humidity and pressure and send these as JSON over WiFi. This is the first stage in developing a device able to send data over either WiFi or LoRa.


Bill Of Materials

The components I'll be using are:

  • Wemos D1 Mini (ESP8266)
  • BME280 sensor
  • SDS011 sensor
  • N-channel logic level MOSFET
  • LM7805 linear voltage regulator
  • 100k resistor
  • 12V battery

The power supply is a LiPo 3 cell battery producing a nominal 12V and with a capacity of 2200mAH. The battery voltage is regulated to 5V by a LM7805 linear regulator. This needs a capacitor on the input and output to prevent oscillation. This device has a quiescent current of 4.5mA - not really low enough but OK for testing.


A DC to DC power converter which uses an LM2506 ‘buck converter’ had a quiescent current of 6.1mA even with the on board LED removed (7.17mA with LED). The BME280 uses the I2C bus on D2 & D1. This device MUST be powered with 3.3V.

An SDS011 particle sensor is connected to D7 & D6 which are configured as RX and TX in SoftwareSerial. The SDS011 requires 5V (3.3V will not work). Fortunately the SDS is configured to send and receive serial data on 3.3V logic levels!

The SDS011 has a permanent connection to +5V whilst is ground return is switched via an N-channel logic level MOSFET. When the gate is grounded the MOSFET is off and the SDS011 is also off. If the gate voltage rises to about 2V the MOSFET switches hard on, connecting the SDS011 to ground and allowing it to power up.

There is a wire link between D0 (GPIO16) and RST - this may need to be removed to allow flashing to take place. It is required for the deepSleep clock to trigger a wake - D0 is taken low to wake up and this is used to take RST low.

Power Consumption

Using a nominal 2200mAH 12V battery gave me 60 hours run time using a cycle of about 5 minutes - 4 minutes sleep, 30 seconds to stabilise when first activated, 10 readings, send MQTT and go back to sleep.


The code is available here. Libraries are used for the BME280 and the PuSubClient to handle MQTT messages. ESP8266WiFi is needed to establish a wifi connection. In addition WiFiManager (which requires DNSServer.h and ESP8266WebServer.h) is used so that wifi credentials can be set up from a browser or mobile device. SoftwareSerial is used to communicate with the SDS011, leaving the normal UART0 to handle any debugging or Serial output. D5 is used as an output and turns on and off the SDS011 via an N-channel MOSFET.

The basic flow is:

  1. setup - creates a bme object and sets up the SDS011 but does NOT start wifi. It then waits 30 seconds for the SDS011 to stabilise.
  2. loop - constantly calls sensor_loop to check if any data has arrived from the SDS011.
  3. sds011.h - lots of setup and decoding functions in here. The main one receives readings and confirms a checksum. Once a set of PM25 and PM10 values have been received that are passed to ....
  4. got_new_ppm_readings - accumulates consecutive readings until the set number has been received. Calculates averages and sends these to.....
  5. publish - constructs a string in JSON format and sends these to the MQTT broker. After a delay to allow sending to be completed the ESP is put to sleep.

To do:

  • SDS011 high side switch using a p-channel MOSFET
  • Add RFM95 LoRa transceiver together with IBM LMIC library
  • Compress the data into bytes and send as binary
  • Design a PCB to improve mechanical stability
First Results

The following chart shows temperature, pressure, humidity, PM2.5 and PM10 over the first 24 hours. Note that the Y-axis for each data type has been adjusted so all lines are visible.


Enclosure for Testing

For testing I used a waterproof plastic container - a reclaimed paint pot! It is too large really but easily accommodates the device and a battery. It even has a handle to hang on a hook on the fence!

Paint Paint

Next Post Previous Post