Yaml code for MQ135 sensor with auto calibration function
Compile YAML , Publish bin to ESP32 C6, and visit ESP32’s web site, and wait at least 15 minutes
Obtain the ‘RZERO reading’ and ‘PPM CO2 reading’ values on the street, yard or outside not in other room in your house, at least 1-2 hours
If the values above are stable, then press button named ‘Calibrate Sensor’ and wait until ‘CO₂ level’ value are stable
Move esp32 to living room. CO₂ level values displays relativly Air Quality from outside air quailty to living rooms values.
CO₂ PPM values meanings in YAML file, below the 1000 meanings is clear air conditions.
To reset to factory settings, press ‘Return to Factory settings’ button. And needs re-calibrate sensor
Calibration settings is persistent but only based for calibrated outside values. No need to re-calibrate on restart, re-power and awake from deepsleep.
If you move another new apartment, city, country etc must re-calibrate.
DHT11 sensor for Humidity & Temperature. You can easly change different sensor type.
YAML code in RZERO and ATMOCO2 values calibrated for istanbul/Turkey.
ESP32 C6 used
MQ135 sensor supply voltage 5V , GPIO Pin GPIO4
DHT11 sensor supply voltage 3.3V , GPIO Pin GPIO0
Exactly this is what im looking for.
I have tried it with a esp32 dev kit c v4 and it seems working.
But my Results feeling wrong.
Do you have any idea whats the problem?
Hi,
The values are wrong, because this values like no calibration has been made.
possible solutions:
go back default factory settings with ‘Factory reset’, with paramters İstanbul/Turkey. Your’s outside CO₂ level values must be below 1000 ppm. But no one garanties this values because different envirioments statues effects, your cities air quality. By the way values can >5000 ppm, near the endustrial cities, cars, facilities make a lot of pollision of air. But values must be maximum 40k or 70k, no worries , the earths co2 values average is 420-430 ppm now
your sensor is like new, as opened packed as new. Dou you run this sensor at least 2-3 days long?
make this control steps, check sensors VCC voltage ,it must be 5V, check AO pin to esp32 connected, GND pin to esp32 GND no other sensors GND with same cable connectin, off course gnd pin on share GND connectin between different sensors, but GND conntection of sensors connect near to the esp’s gnd connection. This can be mith but use diffenett cables to gnd to gnd all sensors. Sensors red light power led is red must be ON, and sensord metalic grid cap temperatures must be around 40 °C. This means sensor ise working and can calculate enought to warm.
do you push calibrate button after wait enough time at least 2-3 hours? push factory reset, wait 2-3 hours, dont touch anything, esp32 must be outside of your room, becuse we want to read relativly values outside of house between inside values,
this is critic, when press button to calibrate CO₂ level ppm (yours is 115945 ppm) wait 1 minutes, values must be dramticly decrease to below 1000 ppm, when values are calculating, there are a moving average func in yaml, this is for smooth value chancing, but after 2 minutes value is not to near or around 1000 ppm, this sensor is broken or too new, or not working very well, throw sensor to the garbage bin . This situations happened to me, 2 days testing, after 20 cups of coffe not helped, I changed the sensor with new one, no adjustment then works very well
test with new sensor, think this way, your outside walue maybe 5000ppm, after calibration value could/must below 1000ppm, no matter how hight values important, calibration means 5000ppm is normal values, indoor values greateer then but not bigger then 5000ppm because after calibration CO₂ level ppm is MUST be below/around 1000ppm.
there is a another way to test is sensor working? light the cigaretees or pice of paper, go to the near the sensor 2 cm, values are going to space, but this is not means working sensor, this sensor connected well but not calibrated because sensors sensitivies are bad.
And a word of warning: after calibration, the indoor values might disappoint you. The human nose and metabolism aren’t that sensitive; you’ll notice that ventilating a room takes at least 15 minutes, and it takes about 2 hours for the air to become polluted when we breathe it in. But it seems we’re living in rooms with more CO2 than we should normally be breathing.
I performed a reset and reconnected all the cables.
The sensor is new, and I replaced it. I tried it with different pins. Apparently, the cables were the problem. Now I have a new result; the sensor is currently working outdoors.
- id: RZERO
type: float
restore_value: no
initial_value: '5.56'
#Atmospheric CO2 level for calibration purposes. Outdoor CO2 level during calibration. Usually 450, but it's better to clarify.
- id: ATMOCO2
type: float
restore_value: no
initial_value: '90485'
first image rzero saved value 78.03 and atmco2 56.63, this image show value saved the global variables, because system display this value from reading the glabal variables . Normally this values persistent (means never erased until apply factory settings) , 2. images diplays İstanbul values , normally, awake , re-power or reboot does not return to yaml settings, it’s interesting but no matter for you, if you think this values working anf displays real co2 ppm values , write this numbers to yaml parameters and rebuild & publish esp32 .
this values function is
restore_value: no
Please control this parameter for atmco2 & r zero in yaml settings. ‘yes’ means , even if user set new value, after reboot, re-power it does not write to persistent memory, use original values like yaml settings. your settings in yaml must be ‘no’
Last log displays factory settings logs, its normal deletes user settings. But last error line, I don’t know what ise error for key=233825507
if you want to every time run program use original yaml settings, like WHO (World Health Org.) worker wants to measure another cities co2 ppm values, this parameter must be restore_value: yes
if you are a normal user and lives same city/region , paramater must be
restore_value: no, because you dont want to re calibrate sensor after reset or open after power lost
orijianlly calibrate must be in chamber and controlled co2 %, like controled lab enviroment, this ise not posible for everyone and not necessarily. PPM means paritcule per million, 400 ppm means, 400 atoms in 1 million atoms, so, sensor is so sensitive but we don’t use of this type of sensitivity.
additional info for co2 ppm values:
this value is very very relativly, this case, we measure ppm, room ppm relativly outside ppm, like color of sea, some people lives in london and says the sea color is green-blue, some people said in ancient era, sea color ise dark-red color like wine, other people says sea clolor is deep-blue who lives İstanbul like me.
I made another sensor code for MQ2, it measure LPG (likit petroleum gas) CO (Carbon Monoxide) ans SMOKE (smoke means smoke but it’s defines, perticules hanging in the air) .
I’ve to plan for combine MQ2 and MQ135 values in same ESP32, my goal is comple air qualty sensing for indoor useage you can see in MQ2 Sensor in this forum. MQ2 sensor work but I did not test long time and not sure to I can’t can yet, it’s realy working well
This values not making me sense. Because, CO₂ level is 63 ppm, normally earth average 420-450, this value can’t be true. Where dou you live? It’s like heaven , this is joke.
You did not press calibrate, when you press calibrete button, 63 ppm value must be rise, because, this is calculated value by paramters with RZERO=5.56 and ATMOCO2= 90485, when you press button, RZERO reading value write to disk and you’ll be see RZERO Default value displays 70.850000, and PPM default value will be 90.000000, it’s now calibrated.
Move your esp to living room, wait 15 minutes, this value is your in-door co2 ppm witch calbireted from outside.
İf you pess calibrate button no need to save yaml file, bu if you wish off course you colud.
I wrote below.
‘RZERO reading’ value to => RZERO , means replace ‘5.56’ to ‘70.85’ (seventy point eighty-five)
‘PPM C02 reading’ value to => ATMOCO2 , means replace ‘90485’ to ‘90’ (ninety)
in YAML file, attention to dot symbols,
By the way witch city do you live now? I was just curious about the CO2 level, that’s why I asked.
I’ve tried a lot of things, but when I calibrate it the way you suggested, I get CO2 readings that are way too high. I’ve now found a way that works for me. I’ve programmed the RZero into YAML so that there’s a baseline value when the room is fresh, and I can see how the air quality deteriorates over time. Then I open the windows.
Perhaps the low temperatures at the moment are preventing the calibration from working, as the resistance changes with them.
Ok, This type of calibration is also suitable. My testing ise also runing. Pay attention to this clue as well. - id: volt_resolution in YAML file, could effect values of measuring, when you connect and use severel sensors, supply voltage to MQ135 will be lower then 5 V, use separate voltage to supply mq135 or, adjust real voltage value to volt_resolution. mq135’s supply voltgae islower then 5 V means meusuring co2 values higher then normal measures.
By the way you are right, low temp affects values but sensor already worms itself for this reason.
Normally we used to “ready to use” components. But this sensor is not one of them. Olso this is fascinating ways to make usable tools for us. Otherwise, we would just go and buy ready-made products from IKEA I wish you ease and a good days.