{"id":623504,"date":"2026-01-12T12:59:37","date_gmt":"2026-01-12T10:59:37","guid":{"rendered":"https:\/\/mybroadband.co.za\/news\/?p=623504"},"modified":"2026-01-12T13:00:23","modified_gmt":"2026-01-12T11:00:23","slug":"building-a-diy-environmental-sensor-for-under-r550","status":"publish","type":"post","link":"https:\/\/mybroadband.co.za\/news\/hardware\/623504-building-a-diy-environmental-sensor-for-under-r550.html","title":{"rendered":"Building a DIY environmental sensor for under R550"},"content":{"rendered":"\n<p>I built a homebrew environmental sensor that cost R535.90, and found that there were very few benefits over buying a commercial version of the product.<\/p>\n\n\n\n<p>Some time ago, I came upon the idea that it might be useful to track temperature and air quality statistics at home and around the office.<\/p>\n\n\n\n<p>I found a variety of sensors available through local online retailers, but most of these seemed to either only measure one metric or be very expensive.<\/p>\n\n\n\n<p>These sensors also operate independently, without the ability to transmit the measured data to other platforms.<\/p>\n\n\n\n<p>Being a tinkerer, I challenged myself to build a device with sensors that could measure at least temperature, humidity, carbon monoxide levels, and an air quality metric.<\/p>\n\n\n\n<p>The entire sensor package should cost less than R500 and be able to connect to Home Assistant, share measurements with the platform, and operate independently.<\/p>\n\n\n\n<p>Having used <a href=\"https:\/\/www.home-assistant.io\/\" target=\"_blank\" rel=\"noreferrer noopener\">Home Assistant<\/a> several times before, I immediately decided to use the <a href=\"https:\/\/esphome.io\/\" target=\"_blank\" rel=\"noreferrer noopener\">ESPHome framework<\/a>.<\/p>\n\n\n\n<p>This allows users to program <a href=\"https:\/\/www.robotics.org.za\/ESP32-C3-SMINI-V2?search=esp32%20super%20mini\" target=\"_blank\" rel=\"noreferrer noopener\">commonly available ESP microcontrollers<\/a> priced at R112.70 as sensors that integrate easily into Home Assistant.<\/p>\n\n\n\n<p>An alternative would be to use the Arduino IDE, as it can also be used to program ESP microcontrollers and has libraries available that make it easy to interface with nearly any sensor.<\/p>\n\n\n\n<p>Regarding the sensors themselves, I found <a href=\"https:\/\/www.robotics.org.za\/BME280-33V\" target=\"_blank\" rel=\"noreferrer noopener\">a BME280 sensor<\/a> from a nearby electronics retailer for R78.20 that would be able to measure temperature, humidity and air pressure.<\/p>\n\n\n\n<p>For the remaining measurements, I opted to use MQx sensors. These are a series of gas sensors that all share the same footprint and are sensitive to different gases.<\/p>\n\n\n\n<p>They are available relatively cheaply from various electronics retailers for around R50 each. I got a pack that <a href=\"https:\/\/www.communica.co.za\/products\/hkd-mq-series-9xgas-detector-kit?variant=51767520821548\" target=\"_blank\" rel=\"noreferrer noopener\">included nine different sensors<\/a>, allowing us to choose what we would like to measure, for R345.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Integrating the components<\/h2>\n\n\n\n<figure class=\"wp-block-gallery has-nested-images columns-default is-cropped wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex\">\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/esp32-picture.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"480\" data-id=\"623506\" src=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/esp32-picture.jpg\" alt=\"\" class=\"wp-image-623506\" srcset=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/esp32-picture.jpg 640w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/esp32-picture-533x400.jpg 533w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><figcaption class=\"wp-element-caption\">ESP32 microcontroller<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/BME280-sensor.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"650\" height=\"350\" data-id=\"623507\" src=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/BME280-sensor.jpg\" alt=\"\" class=\"wp-image-623507\" srcset=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/BME280-sensor.jpg 650w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/BME280-sensor-600x323.jpg 600w\" sizes=\"(max-width: 650px) 100vw, 650px\" \/><\/a><figcaption class=\"wp-element-caption\">BME280 temperature, humidity, and air pressure sensor<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><a href=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/MQX-sensors.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"640\" height=\"480\" data-id=\"623508\" src=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/MQX-sensors.jpg\" alt=\"\" class=\"wp-image-623508\" srcset=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/MQX-sensors.jpg 640w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/MQX-sensors-533x400.jpg 533w\" sizes=\"(max-width: 640px) 100vw, 640px\" \/><\/a><figcaption class=\"wp-element-caption\">MQX sensors<\/figcaption><\/figure>\n<figcaption class=\"blocks-gallery-caption wp-element-caption\">Click to enlarge images of the components used<\/figcaption><\/figure>\n\n\n\n<p>Once we had all our parts, we started putting everything together and soon ran into the first issues.<\/p>\n\n\n\n<p>While reviewing the sensor datasheets, we noticed that the MQ-7 and MQ-9 sensors, which are sensitive to carbon monoxide, require different control circuits than the other sensors.<\/p>\n\n\n\n<p>These control circuits were not implemented correctly on the cheap sensors we purchased, which meant we had to work around the issue.<\/p>\n\n\n\n<p>The standard sensors all take 5V in and output a voltage proportional to the measured gas concentration, which is easily read using the ESP board.<\/p>\n\n\n\n<p>The carbon monoxide sensors, however, need to cycle between 5V to burn off other gases, and then 1.5V to measure carbon monoxide levels.<\/p>\n\n\n\n<p>Luckily for us, the ESP supports pulse width modulation outputs, allowing us to vary the voltage going into these sensors through a cheap transistor.<\/p>\n\n\n\n<p>The BME280 sensor was easier to set up, as it communicates over the I2C serial protocol. This means that we only needed to connect power, ground and two communication wires to the sensor.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Firmware vibe-coding test<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/env-sensor-wiring.jpg\" alt=\"\" class=\"wp-image-623509\" srcset=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/env-sensor-wiring.jpg 1200w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/env-sensor-wiring-600x338.jpg 600w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/env-sensor-wiring-768x432.jpg 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<p>Writing the firmware was easy with some AI assistance. However, the large language model still made several significant errors that required a human hand to resolve.<\/p>\n\n\n\n<p>ChatGPT was able to create an outline of the firmware, implement calibration steps, and develop a web portal to monitor values.<\/p>\n\n\n\n<p>It also attempted to perform the mathematical conversion from raw voltages output by the sensors to actual gas concentrations.<\/p>\n\n\n\n<p>However, we had to fix several syntax and naming errors to get the code to compile, and we noticed that some of the values we were getting were quite strange.<\/p>\n\n\n\n<p>We discovered that ChatGPT did not understand the sensor datasheets nearly as well as we had led ourselves to believe, and we ultimately had to redo most of the maths and calibration steps.<\/p>\n\n\n\n<p>The sensors output a voltage which is relative to the gas concentration, but this relationship contains a few variables that need to be calculated or calibrated.<\/p>\n\n\n\n<p>The sensor acts as a resistive voltage divider, with one part being fixed and the other varying with the concentration. The ratio between these resistances follows a logarithmic curve corresponding to the gas concentration.<\/p>\n\n\n\n<p>While the one resistance value is known, the other needs to be calibrated in a lab, or by running the sensor in &#8220;clean air&#8221;, and assuming a specific gas concentration.<\/p>\n\n\n\n<p>This type of calibration is very rough and will not result in perfect values. However, the values can be compared over time.<\/p>\n\n\n\n<p>Eventually, after more than 20 iterations of our firmware, we had a sensor that read reasonable values when calibrated, operated standalone or connected to Home Assistant.<\/p>\n\n\n\n<p>It could also read temperature, humidity, pressure, carbon monoxide levels, volatile organic compounds and combustible gases.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Getting readings and packaging the sensors<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"343\" src=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/env-sensor-combustable-gas-test.jpg\" alt=\"\" class=\"wp-image-623510\" srcset=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/env-sensor-combustable-gas-test.jpg 1200w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/env-sensor-combustable-gas-test-600x172.jpg 600w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/env-sensor-combustable-gas-test-768x220.jpg 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<p>Temperature, humidity and pressure all correlated well with commercial sensors we already had. Opening a LPG burner without igniting it near the sensor sends the combustible gas sensor values sky high.<\/p>\n\n\n\n<p>Breathing into an enclosed container increases the carbon monoxide reading to a value of around 20 parts per million, compared to the usual value of under five parts per million.<\/p>\n\n\n\n<p>This makes sense as the sensors are also sensitive to carbon dioxide. Finally, we enclosed the sensor in a laser-cut wooden box, making it easier to move around and test in different locations.<\/p>\n\n\n\n<p>Overall, the project was a success, but it required a significant amount of time and tinkering. Although we spent R535.90, it would have been closer to R380 if we had bought loose sensors instead.<\/p>\n\n\n\n<p>Buying an off-the-shelf unit is generally the best option for most people, unless you&#8217;re willing to spend hours understanding the intricacies of each sensor and still struggle to get them to work.<\/p>\n\n\n\n<p>This project highlights how difficulty can vary in projects, as building the temperature and humidity part of the sensor took minutes, compared to days of tinkering to get the MQx sensors working well.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Photos of the completed project<\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/env-sensor-headline.jpg\" alt=\"\" class=\"wp-image-623511\" srcset=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/env-sensor-headline.jpg 1200w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/env-sensor-headline-600x338.jpg 600w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/env-sensor-headline-768x432.jpg 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"675\" src=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/env-sensor-enclosure-rear.jpg\" alt=\"\" class=\"wp-image-623512\" srcset=\"https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/env-sensor-enclosure-rear.jpg 1200w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/env-sensor-enclosure-rear-600x338.jpg 600w, https:\/\/mybroadband.co.za\/news\/wp-content\/uploads\/2025\/12\/env-sensor-enclosure-rear-768x432.jpg 768w\" sizes=\"(max-width: 1200px) 100vw, 1200px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>We built an environmental sensor from electronics parts, and it turned out to be a significant undertaking.<\/p>\n","protected":false},"author":341074,"featured_media":623505,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_sma_x_autopost_status":"idle","_sma_x_autopost_error":"","_sma_x_post_id":"","_sma_facebook_post_id":"","_sma_instagram_post_id":"","_sma_threads_post_id":"","_sma_x_attempts":0,"footnotes":""},"categories":[29,15,31750],"tags":[83065,40858,102689,102834,102690,102835,102691,27459],"class_list":["post-623504","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-gadgets","category-hardware","category-science","tag-chatgpt","tag-diy","tag-esp32","tag-esphome","tag-homeassistant","tag-mqx-sensors","tag-sensors","tag-smart-home"],"_links":{"self":[{"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/posts\/623504"}],"collection":[{"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/users\/341074"}],"replies":[{"embeddable":true,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/comments?post=623504"}],"version-history":[{"count":8,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/posts\/623504\/revisions"}],"predecessor-version":[{"id":624765,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/posts\/623504\/revisions\/624765"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/media\/623505"}],"wp:attachment":[{"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/media?parent=623504"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/categories?post=623504"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mybroadband.co.za\/news\/wp-json\/wp\/v2\/tags?post=623504"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}