-
1Build
This is the basic topology I ended up with for this prototype:
I did not take the time to draw up a more detailed schematic, but given the modularity of the components, this should be simple to wire up point-to-point, as I did, or to design an actual PCB around. Ultimately, this could be produced for about 2/3 the cost per unit if one were to consolidate the DC voltage regulation, esp8266, RTC, and ULPSM gas sensor breakout boards onto a single PCB.
For this prototype, I ended up sampling the ULPSM gas sensor boards single-endedly, and separately sampled the 3.0V bus voltage in order to estimate Vref, with calibration offsets that I worked out externally by solving for best fits to data form a nearby EPA station. I briefly experimented with sampling in differential mode but was plagued by drift. That was before I worked out temperature compensation and a software low-pass filter, so, in retrospect, I may not have given differential mode a fair shake.
Others have commented that op-amps configured as differential amplifiers would have worked here. If I pick this project up again, I will try these other methods. I suspect that a single quad op-amp IC would be perfect, between the four ULPSM boards and one ADS1115. The other ADS1115 would no longer be needed since the op amps produce four single-ended analog signals and there would no longer be any need to sample bus voltage.
-
2Flash
Download the arduino code and accompanying index.h file to a new directory in your arduino working directory.
https://github.com/rkinnett/air_quality_monitor
Edit the arduino file to use your wifi network SSID and password, and adjust any pin assignments as needed.
Flash using the Arduino IDE. You'll need to use a usb cable the first time you flash your esp8266. After that, you can flash over the air.
Within the arduino code, the gasSensor structure contains one Vcal calibration value for each sensor. The values in the repo version of the code work for my specific build and will not yield accurate results for your system. You must calibrate these values either by your own method or the hacky method described below.
-
3Understand the Gas Concentration Calculations
Spec-sensors provides this Application Note:
https://www.spec-sensors.com/wp-content/uploads/2016/06/SPEC-AN-104-Environmental-Effects.pdf
which describes thermal sensitivity of its gas sensors. The Application Note provides plots showing offset and scale temperature sensitivity, and also provides a brief description of a temperature compensation process. I was unable to figure out how to associate the temperature sensitivity scale and offset values from the included plots to these equations, even after contacting Spec-Sensors multiple times. Ultimately, I ended up working out my own equations, based on the functional descriptions in this document.
In order to use the data provided in the temperature sensitivity scale and offset plots, I manually fit (eyeballed) exponential curves to each sensor profile. The curves I derived have coefficients which are provided in the gasSensors struct in the arduino code and correspond to these equations:TCompOffset = Coffset0*exp(Coffset1*TdegC)+Coffset2
TCompScale = Cscale0*(1.0-exp((Cscale2-TdegC)*Cscale1))These scale and offset values vary with temperature over time. Next, these scale and offset values are used in the temperature-compensated gas concentration equation which I worked out on my own:
Gas Concentration (ppm) = ((Vgas-Vbus/2-Vcal)*1e6/Gain-TCompOffset)/Gain*(2-TCompScale)
-
4Calibrate
Legitimate AQM stations with budgets generally use controlled reference gases to calibrate sensors. This project assumes that standard calibration approach is not economically viable. The Spec-sensors gas sensors are factory calibrated, but are sensitive to the system in which they are integrated. The process described here employs the factory-calibrated sensor parameters but requires additional characterization in order to compensate for system-specific offsets. Specifically, this process finds values for offset voltages for each sensor by minimizing differences between calculated values and data from a nearby EPA station, assuming one is available.
The esp8266 serves the accompanying index.h page which you can access from a web browser by navigating to the local network IP address of your esp8266: http://[ip-address]
The esp8266 also provides a REST API which you'll use to query raw sensor values and poke Vcal values. You can use the following functions by formulating GET requests (using curl, wget, python, web browser, etc) by appending the following url suffixes to the local IP address of your esp8266 (Ex: http://[ip-address]/getVals):/getVals returns: pm25-count, pm10-count, O3-ppm, CO-ppm, NO2-ppm, SO2-ppm, pm25-filt, pm10-filt, O3-filt, CO-filt, NO2-filt, SO2-filt, temp-filt, pressure, humidity, date, time
/getVgas returns: date, time, temperature, bus voltage, O3 vgas, CO vgas, NO2 vgas, SO2 vgas
/getVcal returns: O3-vcal, CO-vcal, NO2-vcal, SO2-vcal
/setVcal sets calibration values for each sensor, relative to Vbus/2. Specify one or more gas sensor vcal values by specifying [ocns]=#### where [ocns] represents the O3, CO, NO2, and SO2 sensors. Ex: http://[ip-address]/setVcal?o=1.003&c=-0.010
Calibration process:- Create a script to query http://[ip-address]/getVgas in ~5 minute intervals and append to a csv file. Log data for several days, if not weeks or months. This collects low-pass-filtered sensor output voltages (without temperature compensation or calculated gas concentration values), along with Vbus and temperature measurements.
- Open your csv file in Excel. Create additional columns to calculate TCompOffset and TCompScale for each gas sensor as a function of temperature, per the equations above. Allocate four cells for your Vcal calibration voltages for each sensor and initialize each to 0V. Create additional columns to calculate gas concentration values using the time-varying Vgas data, time-varying TCompOffset and TCompScale values, and the non-time-varying Vcal value for each sensor.
- Plot your calculated gas concentration values from each sensor. Expect some diurnal variation.
- Find an EPA station near you and download Ozone, CO, NO2, and SO2 (if available) data spanning the time range you recorded with your own sensors.
- Manually adjust the Vcal values in your spreadsheet until your gas concentration values closely track those from the EPA station.
- Once you have found good Vcal values in Excel which minimize error between your gas concentration values and those from the EPA station, you can then update the Vcal values on the esp8266 temporarily by using the /setVcal function, or by editing the Arduino code and re-flashing.
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.