White Cube on guard of clean air, part 2

    The second part of the publication about White Cuba.

    In the first part , a home-made device for measuring environmental parameters was described. This is the second part of the publication.

    The construction of the White Cube

    The main module BK is mounted on the basis of double-sided foil fiberglass. The base is carved in the shape of the bottom of Cuba. On this plate, cuts were made with an office knife for mounting connectors for gas sensors, power wiring.



    Arduino Nano, a Wi-Fi module and a module with pressure sensors, etc. are mounted on vertically mounted trims. On the strips made contact pads by cutting the foil, the connectors are soldered on the sides. Connectors purchased in Brown Bear. The Wi-Fi module has a connector in 2 mm increments, not the standard 2.54. The height of the strips is made greater than the height of the modules, the remaining space was used to place discrete elements (a transistor for controlling the heating of the CO sensor, pull-up resistors I2C and 1Wire, etc. The picture also shows a loop of wire, I used it when debugging the system the ground pin of the oscilloscope probe and the tester probe.

    The strips are installed in place by soldering to the base. For reliable melting of the solder, you need to use a powerful soldering iron, I have 100 watt with a copper sting in a finger made in USSR thick.

    BC power is supplied from an external power source with a nominal value of 5V to 2 A. I used a source from a faulty DLINK router. BC consumes slightly less than 2 A and the power supply has a current margin. The built-in Arduino stabilizer is not used. During debugging, you can power the battery from the computer, but the analog gas sensors must be removed from the connectors, otherwise there will not be enough current from USB. The simultaneous connection of an external power source and USB is not recommended. My USB port in the Lenovo X200 laptop did not burn out, but it did not work either. There are no guarantees that you will not burn, I strongly do not recommend doing this.

    Two identical round connectors are fixed on the BC case. One is for power supply, the other is for connecting a loop with 18B20 temperature sensors. Not quite the right solution from the point of view of foolproofness (you can mix up the connectors), it is possible in the future to replace the sensor connector with another type.


    For cooling and exchange with the external environment, holes with a diameter of 8 mm were drilled in the housing. Since the applied gas sensors require heating of the measuring surface, quite a lot of heat is released inside the White Cube. At a voltage of 5 volts, the current consumption is about 2 A, which gives about 10 watts of heat. Inside, the White Cube is heated to a temperature of about 40 degrees, according to the temperature sensor from BMP085. Such a high internal temperature led to the need to move the humidity and ambient temperature sensor outside of Cuba, otherwise the humidity sensor readings are noticeably distorted.
    After a series of experiments in an attempt to thermally isolate the sensor from the housing without moving elements, I settled on a swivel heat-insulating bracket. The bracket is made of a standard wooden chopstick :) The SHT10 sensor is mounted on the end.


    The sensor has soldering points on both sides, although only one side points are used for exchange. The points from the second side are used for fastening - a pair of short wires that are not connected anywhere are soldered to them. This made it possible to securely attach the sensor at the end of the bracket.


    A high rectangular hole is made in the side surface of the cube. The bracket with the SHT10 sensor slides into this groove. This is done to prevent damage to the bracket and sensor when carrying, otherwise the bracket protruding 10 cm is easy to break. For easy removal of the bracket, a petal is made of black insulation tape. The mechanism allows you to remove the sensitive sensor in the case when carrying the Cube and easily get the sensor by turning the bracket when the system is in a stationary position.


    The diameter of the holes in Cuba for cooling, their number and location is determined from engineering and intuitive thoughts and memories of the subject “Rags”, they are also the “course of the property of electro-radio materials”, in which they talked about the design of passive REA cooling systems. The main thing that is important is the diameter of the holes, which should not be small for air to pass through them.

    The Wi-Fi module came from China without an internal antenna, only with an external U-FL type connector. I was forced to buy additional antennas from DESSY.RU for mounting inside the case (ANT 2.4 ESG-2400-12 UFL-F, price about 150 r). I would know in advance - I would order exactly the same antennas along with the modules. Unfortunately, on the seller’s website (DX.COM) there is a photo of the module with an internal antenna and the presence of both an internal and external antenna is mentioned in the description. However, I opened a ticket and they returned my money for the antennas. As I already mentioned, this module is a truncated version of the router, to which you can connect up to four additional RJ45 connectors. Inside there is Linux. By default, the module, after switching on, is configured for the access point mode with the password “12345678” (and not “0000000”, as erroneously indicated in its description).

    After about a minute, a device like HI-LINK_A3B8 will appear in the Wi-Fi environment, where the last characters correspond to the MAC address of the module written on its panel.


    We connect, enter the password (12345678), configure the TCP \ IP protocol in the machine to the network 192.168.16.XXX. The default address of the module is, the username is admin \ admin. I changed the mode of the module to WiFi Client Serial. This is the mode in which the module connects to the home access point and provides transparent serial data transfer:


    The first serial port is configured at 38400 and set to server mode. The rest of the settings are unchanged.


    The second serial port is also set to server mode, the rest is unchanged. For test purposes, the signal Tx (terminal 22) is applied to the input Rx (terminal 26).
    As a result, it turned out that when accessing the address, the first serial port is available, the address is the second, and the router itself is available at the address
    The module is also able to show the signal level. You can compare the operation of two external antennas in the same conditions. According to my data, it turned out that the purchased flat antennas work better than the whip antennas from the old WiFi PCI card.


    You can check the operation of the module using the PUTTY program in telnet connection mode.
    The first serial port works at speeds up to 115200, the second - up to 57600. In White Cuba, the second serial port is not used.

    A few more photos of the internal structure of the BC:

    Recalculation of the readings of analog gas sensors into a digital value in ppm (parts per million, parts per million).

    From the medical literature I extracted the following data:

    Acute effects of carbon monoxide poisoning
    relative to the surrounding concentration in parts per million (concentration, ppm):
    35 ppm (0.0035%) - headache and dizziness for six to eight hours of constant exposure
    100 ppm (0.01%) - minor headache after two to three hours of exposure
    200 ppm (0.02%) - minor headache after two to three hours of exposure, loss of criticism
    400 ppm (0.04%) - frontal headache after one or two hours of exposure
    800 ppm (0.08%) - dizziness, nausea and su roads after 45 minutes of exposure; loss of feeling after 2 hours
    1600 ppm (0.16%) - headache, tachycardia, dizziness, nausea after 20 minutes of exposure; death in less than 2 hours
    3200 ppm (0.32%) - headache, dizziness, nausea after 5-10 minutes of exposure; death after 30 minutes
    6400 ppm (0.64%) - headache, dizziness after 1-2 minutes of exposure; cramps, respiratory arrest and death after 20 minutes
    12800 ppm (1.28%) - unconscious after 2-3 breaths, death in less than three minutes
    0.1 ppm - natural atmospheric level (MOPITT)
    0.5 - 5 ppm - the average level in houses is
    5 - 15 ppm - next to a properly regulated gas stove in the house
    100 - 200 ppm - from exhaust gases from cars
    5000 ppm - in smoke from a wood stove
    7000 ppm - in warm exhaust gases of cars without a catalyst.

    From these data it follows that it makes sense to measure the values ​​of the CO level in the range from ppm to 100 ppm, and consider all values ​​above this level to be deadly. This is also confirmed by the fact that the first threshold in industrial sensors is set to 20 ppm, the second - 100 ppm.

    The manufacturer of the MQ7 sensor provides in its manual all the necessary data to create an algorithm for converting the readings of an analog voltmeter into ppm digits. A careful study of this document gives the following initial data: The

    resistance of the sensor in clean air can be in the range of 2-20 KOhm.
    The load resistance is recommended in the region of 10 k. The study of the details on the sensor printed circuit board showed that a 1 kΩ resistor is installed in the finished module. As will be shown later, such a load resistor gives the sensor output voltage in the range from about 400 mV in clean air to 5 volts at a CO value of about 1000 ppm. This range covers by an order of magnitude the need for measuring CO. A hazardous CO value of 100 ppm produces approximately 3.6 volts at the output of the sensor.

    A graph of the relationship between the sensor resistance and the gas level in the mixture:

    Bold black lines were added by me to verify the formal correctness of the data. I checked whether three lines converge at point 0 — the vertical axis y, the horizontal straight line of the dependence of the sensor resistance in clean air and the line of dependence of the sensor resistance on the level of impurities of the detected gas in the mixture. As you can see - there is a practical hit at one point, taking into account errors.

    Using this graph, you can make a table of the relationship of the ratio of the resistance of the sensor in the measured mixture and clean air on the amount of impurities of the detected gas. I applied a technical trick - I wrote down the cursor position on the tablet in Excel, pointing it to the necessary points on the graph. The values ​​I need fall between the measured values. I applied the linear approximation method to calculate intermediate values. Thus, I got the ratio values ​​for ppm values ​​in the range 10, 20, 30 ... 100, 200, 300, ... 1000

    I converted these resistance change values ​​to voltage values ​​and then to the ADC readings in the range 0 - 1023. Having built a graph and an approximating curve , I used this data to derive a formula for converting ADC values ​​to ppm values ​​for CO.

    Here is the table:

    The pop column is the ADC value for "parrots." Exp - calculated ppm values ​​by the formula = ROUND (10 * EXP ((pop-339) / 175); 0)

    Two formulas should be displayed, one for the range 0-100 ppm and the second for the range 100-1000 ppm. I deduced the first and decided to consider everything above 100 ppm (more than 3.6 V) deadly.

    In principle, it is possible to calibrate the sensors using reference gas mixtures. Such mixtures can even be bought. A quick study of the issue showed that, firstly, the price level for such mixtures is not at all pleasing, and secondly, you need to buy a bottle of at least five liters and at least a minimum set of gas fittings to ensure a constant flow of the mixture. Looking at prices, I found this idea unreasonable in relation to the budget of the White Cuba.

    Sketch can be downloaded here

    The WhiteBox program for receiving data from the BC, logging and graphical display of data is written in Visual Basic in Visual Studio Express 2012. An

    archive with the project can be downloaded here.

    The program implements a connection recovery mechanism in the event of a signal loss. If the channel crashes and there is no data after the specified timeout, the program will close the channel, clean the “tails” and open the channel again. And it will do so until the connection is restored. In the case of whitebox, the timeout is set to 10 seconds with a normal interval between sendings of 3 seconds. The program correctly executes and shuts down - turning on the transmitting module, Wi-Fi access point or any connected equipment along the path of the data stream.
    Channel opening and closing events are logged. A program start and stop event is also noted.
    Data and events are written separately in two separate text files.
    Once the timer is triggered, the program for writing statistics to the log file is run once a minute.

    After starting, the program opens a channel for reception from the White Cube and in the background channel awaits the arrival of data.
    Upon receipt of data from the channel, they are placed in a buffer, and upon reaching certain conditions, this buffer is sent to the input data processing program. In this program, the condition is that the last bytes of the string are equal to vbCrLf (that is, Hex (0D0A), they are also characters "carriage return" "return line").

    The processing routine checks the input string for formal validity using the regular expression mechanism. If the line has an invalid format, this is noted in the log file. If the string has a valid format, the program splits the string into elements using the regular expression mechanism, resulting in an array of elements.

    Further processing consists in entering the necessary elements into arrays of the “FIFO queue” (QUEUE) type.

    I chose two types of data display - conditionally Low and Fast. Points on Fast charts go after 3 seconds, and on Low - after a minute.

    The queue length for Fast data was chosen to be equal to 1200 elements, which gives about 1 hour ago for an interval of data arrival of three seconds.

    The queue length for Low data was chosen equal to 1440 elements, which, with an interval of data arrival of one minute, gives a picture 1 day ago.

    In this program, a calculated expression is used to convert CO measurement data from ADC units to ppm values.


    Sensor response to the use of hairspray. It can be seen that all the sensors reacted, unfortunately the selectivity of the sensors is small.

    The upper graph is the CO2 level in the apartment per day. Maximums in the morning and evening, each person gives approximately +200 ppm to the background level of 450 ppm. A very high level of CO2 gives a gas stove. During the operation of the gas stove, the CO2 level jumps to 2000 - 2500 rpm. These values ​​are already beyond the limits of hygiene standards and require active ventilation of the room.

    A curious effect is the measurement of CO2 in the student's room. When the child is engaged, the CO2 level is approximately 1200 ppm. And when a child plays rpg / shooter, it reaches 2000 ppm. The result was an indirect method of measuring diligence in the classroom. CO2 level correlates with brain activity and allows you to draw certain conclusions about the diligence of a student :)

    Here is a screenshot of another program that communicates with a CO2 sensor connected to the control computer via a USB-Serial converter:

    CO2 peak at around 19:00 - homecoming and entertainment. Morning peak around 8 hours. The background value during the day is about 400 ppm, at night 450 ppm.

    Obviously, the level of CO2 directly correlates with the intensity of the brain. It turns out that by the level of CO2 one can objectively judge the intensity of classes. And the opportunity arises to objectively argue on the phrase “I taught!” :)

    Another interesting effect (not discovered by me, used in advanced security systems) - the level of CO2 indicates the number of people in the room. Well, or in general about the presence of people. When I just started this system and it was interesting for me to analyze the data, one evening I look at the chart - the CO2 level drops only after one in the afternoon. And the son says that he went to college to the second pair. It doesn’t fit :))) he showed his son the schedule and the child sadly said: “Well, now you can’t walk, I can’t breathe!”

    This is of course a joke and an unexpected secondary effect, the system was not created to control the child.
    Although my son adapted the system for his needs - I made a conclusion of the CO2 level on his laptop and added a voice warning about the excess of CO2 level in his room.

    Also popular now: