
Another way to determine air quality on the Arduino is through data transmission to the network.
My name is Eugene and I am a web developer. There are already dozens of posts about various weather stations on arduino, but I wanted to write that in 2016 you can quickly, easily and without knowledge of electrical engineering assemble a useful sensor that claims to be IoT, which can easily work with your infrastructure written on anything.
If you're wondering why to measure CO2 at all, then you can find useful links at the end of the post.
So, our goal is to make a temperature, humidity and CO2 sensor with data displayed on the display and sent to the web server. What we need for this:
1. Arduino. I took Wemos D1, an Arduino compatible board based on the ESP-8266EX microcontroller. Wemos is compatible with the Arduino IDE, it has its own Wi-Fi, and it costs $ 6.3.
2. CO2 sensor. Earlier I tried the usual MQ-135, but even after burning, calibrating and taking into account the temperature and humidity corrections, the errors were quite noticeable - about 300 ppm. So to guarantee accurate measurements, I took the MH-Z19 - the most expensive component of the circuit, $ 27.
3. Temperature and humidity sensor. Used the standard and loved by all DHT11 for $ 1.44. The comments suggest that it is better to take DHT22, but for the scheme and cost this is not important:
4. I2C compatible display. I took the cheapest hd44780 for $ 3.06.
5. To make it look not very terrible, and be movable, it is also nice to have a body. In order not to bother with cutting, I took a $ 8 case with holes and mounts for usb and a display. Attention - there must be holes in the case for ventilation, otherwise it will only measure its special atmosphere.
6. Debugging USB cable and about 10 wiring. I will not consider the price.
The total cost is $ 44, if you take on aliexpress. Similar devices without the ability to transfer something to the network now cost the Chinese around $ 100. An analogue from Tion, which in number do their posts on the gytime with advertising of breathers, is still in development (I have nothing to do with them, but it's a pity).
Ordered, waited a month - proceed to assembly! There is nothing easier.
1. Connect the temperature and humidity sensor. Earth to earth, dust to dust, plus five volts per arduino, digital output to digital output (I used D5).
2. Connect the CO2 sensor. It has a wide selection of interfaces - PWM, analog and digital output. The only element of soldering is to attach the legs to the desired outputs. Checked personally - everyone works. I stopped at receiving digital data - precisely, beautifully, concisely, and there is also the opportunity to send commands for calibration, which I did not need. Again - ground to ground, plus the other five volts, TX and RX pins to digital pins - in my case, to D6 and D7.
3. Connect the display. And again - earth to earth, plus the last remaining output of five volts, SDA on the display to SDA on the arduino, SCL also to SCL.
And ... That's it! You can spin the resulting good into the case, if you certainly have not managed to make any mistake when connecting. Please note that the CO2 sensor does not have air intakes pressed (or, as it is more correctly called, such white things). As a bonus, during assembly in the housing, deviations in measurement are significantly reduced.
Well, we just have to write software. The links below have a github repository that you can simply upload and use. The only subtle point is that your display may have a different address. Use the mini program from the links to scan i2c addresses and change to the one you need if it doesn’t work right away. Disconnect other devices before scanning, otherwise you can get a lot of garbage.
Yes, Wemos D1 is compatible with Arduino, and you just need to add the appropriate board to the Arduino IDE. We connect a standard short cable via micro USB and fill in the firmware. If you did everything right, then the device will first try to connect to Wi-Fi (the network and password are taken from the settings file), then it waits for a while to “warm up” the sensors, and finally displays the data on the display. If the network fails to send data, it will report it. If the CO2 level is acceptable, then after loading the backlight will turn off and turn on only if you need to open the window.
It looks like this for me (carefully, traffic):
Unassembled
assembled, with the backlight turned off
It's time to ventilate!
Now about working with the network. Without further ado, I collect the data in JSON and send it to the server with the usual POST request, where a simple PHP script puts it in the MySQL database. Then you can see how your living conditions changed throughout the day using PHP and Google Charts - the entire server part is also in the links.
As a result, at a ridiculous price, with zero knowledge in electrical engineering and with minimal time investment, we can get about such nice graphics:
Caution, traffic
I will not say that this directly tears the cover from the simple truth that “less people - more oxygen”, and that you need to periodically ventilate, and they talked about this many times - including the harm of plastic windows. But this example shows how simple, fast, reliable and beautiful it is possible to make almost any sensor that supplies data for some more complex system.
Yes, I compared the readings with such a Chinese Green Life sensor - the readings are almost identical, only mine responds a little faster to changing circumstances:
Of course, much could be done better. Offhand, I see the following disadvantages:
And then I want to take a break from working days and play laser tag with friends. One problem - the game costs from 500 rubles per hour per person. This is in the complete absence of consumables. And to buy a kit for the game will cost some kind of sky-high money - from about 8000. So in order to play laser tag, you must first collect it. I plan to do something like Skirmos - where some kind of money will cost only the barrel itself, which should be pretty solid. Interesting? Follow publications! What are you doing on Arduino?
If you're wondering why to measure CO2 at all, then you can find useful links at the end of the post.
So, our goal is to make a temperature, humidity and CO2 sensor with data displayed on the display and sent to the web server. What we need for this:
Components
1. Arduino. I took Wemos D1, an Arduino compatible board based on the ESP-8266EX microcontroller. Wemos is compatible with the Arduino IDE, it has its own Wi-Fi, and it costs $ 6.3.
what does it look like

2. CO2 sensor. Earlier I tried the usual MQ-135, but even after burning, calibrating and taking into account the temperature and humidity corrections, the errors were quite noticeable - about 300 ppm. So to guarantee accurate measurements, I took the MH-Z19 - the most expensive component of the circuit, $ 27.
what does it look like

3. Temperature and humidity sensor. Used the standard and loved by all DHT11 for $ 1.44. The comments suggest that it is better to take DHT22, but for the scheme and cost this is not important:
what does it look like

4. I2C compatible display. I took the cheapest hd44780 for $ 3.06.
what does it look like

5. To make it look not very terrible, and be movable, it is also nice to have a body. In order not to bother with cutting, I took a $ 8 case with holes and mounts for usb and a display. Attention - there must be holes in the case for ventilation, otherwise it will only measure its special atmosphere.
what does it look like

6. Debugging USB cable and about 10 wiring. I will not consider the price.
The total cost is $ 44, if you take on aliexpress. Similar devices without the ability to transfer something to the network now cost the Chinese around $ 100. An analogue from Tion, which in number do their posts on the gytime with advertising of breathers, is still in development (I have nothing to do with them, but it's a pity).
Ordered, waited a month - proceed to assembly! There is nothing easier.
Assembly
1. Connect the temperature and humidity sensor. Earth to earth, dust to dust, plus five volts per arduino, digital output to digital output (I used D5).
2. Connect the CO2 sensor. It has a wide selection of interfaces - PWM, analog and digital output. The only element of soldering is to attach the legs to the desired outputs. Checked personally - everyone works. I stopped at receiving digital data - precisely, beautifully, concisely, and there is also the opportunity to send commands for calibration, which I did not need. Again - ground to ground, plus the other five volts, TX and RX pins to digital pins - in my case, to D6 and D7.
3. Connect the display. And again - earth to earth, plus the last remaining output of five volts, SDA on the display to SDA on the arduino, SCL also to SCL.
And ... That's it! You can spin the resulting good into the case, if you certainly have not managed to make any mistake when connecting. Please note that the CO2 sensor does not have air intakes pressed (or, as it is more correctly called, such white things). As a bonus, during assembly in the housing, deviations in measurement are significantly reduced.
Firmware
Well, we just have to write software. The links below have a github repository that you can simply upload and use. The only subtle point is that your display may have a different address. Use the mini program from the links to scan i2c addresses and change to the one you need if it doesn’t work right away. Disconnect other devices before scanning, otherwise you can get a lot of garbage.
Yes, Wemos D1 is compatible with Arduino, and you just need to add the appropriate board to the Arduino IDE. We connect a standard short cable via micro USB and fill in the firmware. If you did everything right, then the device will first try to connect to Wi-Fi (the network and password are taken from the settings file), then it waits for a while to “warm up” the sensors, and finally displays the data on the display. If the network fails to send data, it will report it. If the CO2 level is acceptable, then after loading the backlight will turn off and turn on only if you need to open the window.
Result
It looks like this for me (carefully, traffic):
Unassembled
assembled, with the backlight turned off
It's time to ventilate!
But what about the network?
Now about working with the network. Without further ado, I collect the data in JSON and send it to the server with the usual POST request, where a simple PHP script puts it in the MySQL database. Then you can see how your living conditions changed throughout the day using PHP and Google Charts - the entire server part is also in the links.
As a result, at a ridiculous price, with zero knowledge in electrical engineering and with minimal time investment, we can get about such nice graphics:
Caution, traffic
I will not say that this directly tears the cover from the simple truth that “less people - more oxygen”, and that you need to periodically ventilate, and they talked about this many times - including the harm of plastic windows. But this example shows how simple, fast, reliable and beautiful it is possible to make almost any sensor that supplies data for some more complex system.
Yes, I compared the readings with such a Chinese Green Life sensor - the readings are almost identical, only mine responds a little faster to changing circumstances:
what does it look like
The contrast of the display is raised in the picture - everything is perfectly visible on it, but the phone was distorted from its light:


conclusions
Of course, much could be done better. Offhand, I see the following disadvantages:
- The display off has a very low contrast. It’s better to take another, another 10 cents broke.
- When the backlight is on, the screen flickers a little. Not critical, but apparently he doesn’t like that three devices with five volts are powered from the arduino right away. It would probably be right to do separate meals.
- Of course, all this can be beautifully soldered, and not just left in the box, somehow connecting.
- The temperature and humidity sensor sometimes returns huge left values. I just cut them off, but generally unpleasant. Perhaps the effect of general washing or poor connection.
- Of course, one could accumulate statistics and periodically send them (and accumulate in case of errors) - no one needs to know their air quality with an accuracy of 5 seconds.
- In order not to drive the Wi-Fi point data during compilation, we could make it so that if the connection fails, the device switches to the Wi-Fi point mode (yes, Wemos can), picking up to which you can reconfigure it - including entering a new one network name and password.
- Wemos D1 is good for everyone, but sometimes it flies out (every 2-3 days) for unknown reasons, and it only reboots after a few hours. It seems like not my software curve, just the board is not very stable. You can deal with this by connecting the device to some Arduino nano, which restarts it if necessary, or simply put a piece of iron with a timer that will restart the device once every half an hour (since it has a RESET input).
- When you pull out and return the power, the CO2 sensor goes crazy, which is treated by a reboot. I decided this in a simple way - when a certain number of continuous errors accumulate, the device restarts itself, after which everything returns to normal. Probably, it would be possible to solve this in a more correct way at the level of iron.
- Temperature is measured with an accuracy of two degrees, humidity - with an accuracy of ten percent. For domestic purposes, it is enough, but for some other use you will need a more accurate sensor.
- If you need to send one small packet of data, then the library for working with JSON is killing sparrows from a cannon. It is much easier to assemble JSON with handles, or even pass parameters using GET / POST, which I did at the beginning. But if there is a huge amount of RAM on Wemos - why not, it's more beautiful. But when porting the code to a low-power arduino, you will most likely have to rewrite it.
- In the current implementation there is no backlight brightness control - it can only be turned on and off. You can remove the jumper and put resistance in its place or enter the arduino - then you can control the brightness of the backlight.
- You can also manage or retrieve information using the application. The easiest way, funny as it may seem, is to add a telegram to the bot - there is already a library for communicating arduino via telegrams.
What's next
And then I want to take a break from working days and play laser tag with friends. One problem - the game costs from 500 rubles per hour per person. This is in the complete absence of consumables. And to buy a kit for the game will cost some kind of sky-high money - from about 8000. So in order to play laser tag, you must first collect it. I plan to do something like Skirmos - where some kind of money will cost only the barrel itself, which should be pretty solid. Interesting? Follow publications! What are you doing on Arduino?
References
Main
- Code for Arduino
- Server side
- You can see the air in my office here
- You can hire me (yes, I'm looking for her) here
Useful
- If you don't know anything about CO2 - geektimes.ru/company/tion/blog/269134
- About wemos d1
- MH-Z19 Sensor Specifications
- A good article , about the same thing, but without a network, with a display from the phone, with work on PWM and Arduino nano
- Scan devices on i2c
- Future analog of the sensor from Tion (I have no relation to it)
- Iron-level ESP8266 restart solution
- Another good article about ESP, Lua and CO2
- And here the students of MAMI are engaged in all kinds of good electronics. By the way, they need teachers. Soon I will give lectures there.