In our garden cottage we store gasoline mowers and cans, the gas grill and some cans with colours and nitro thinners. When flammable gases or liquids run out or even a fire breaks out, I want to be alerted. Since the shed is still in the area of our WLAN, I have therefore chosen a D1 Mini (ESP8266) with DHT22 temperature sensor and MQ-2 gas sensor. The data is transmitted using the ESP as web server
|1||D1 Mini NodeMcu with ESP8266-12F WLAN module|
|optional||Battery Shield for lithium batteries for D1 Mini|
|optional||Lithium Battery 3,7V|
|1||DHT22 AM2302 Temperature and humidity sensor|
|1||MQ-2 Gas Sensor Smoke Sensor Air Quality Module|
|Mini Breadboard, Jumper cable|
For the sketch, I was able to use pieces from other programs. The simplest is to ask for the gas sensor MQ-2, which is supplied with a voltage of 5V for internal heating. For the data , you have the choice between a digital and an analogue output. Both options require a voltage divider (e.g. 1 kOhm and 2,2 kOhm), since the ESP8266 inputs only support 3.3V. Although the small microcontroller has only one analog input, I use this one. Because here you can set the limit value with a certain value in the sketch. Alternatively, you can set the digital output limit with a built-in potentiometer. Although the condition HIGH is also shown on a green LED, the calibration is difficult due to lack of comparisons. To query the analog pin we only need:
The DHT22 (AM2302) is a combined temperature and humidity meter from the one-wire sensor family (1-wire). The voltage supply is flexible between 3 and 6 V, the data is sent to a digital pin. A program library is conveniently used to query the measurement values, as so often developed by the Adafruit team around Limor Fried. So we only need to instantiate the object dht:
Since we use the measured values in different functions, we define them as global variables before void setup() :
Programming the web server on the ESP8266 is not a secret science. There are examples in the Arduino IDE when installing the following program libraries.
However, the sketch can become very extensive if the output in the browser of the PC or smartphone is also to look good and be updated automatically. A colleague for the new eBook Smart Home Starter Set
developed a code block that I had little to adapt. The HTML code can be found in the complete sketch: (Download)
Our garden shed is built quite robustly and the door is secured with a safety lock. That's why I've given up motion detectors or other sensors to prevent theft. It would be easy to adjust the code for that.
In the second part I would like to show how I can display the transmitted data not only in the browser on the PC or smartphone, but also with the help of a Raspberry Pi or a Micro Controller. This has the advantage that you can even connect a buzzer and/or LED to trigger an alarm.