Das sechzehnte Türchen

In our Blog on November 22nd we briefly presented the new AZ-Envy and showed how to read out the values ​​of the built-in sensors with the help of the recommended libraries and displaying them in the serial monitor. I would now like to go deeper, use the great advantage of the ESP micro controller with built-in WiFi and answer the previously unanswered questions about the sensors. Even if the MQ-2 does not have a CO2 sensor (but LPG, i-butane, propane, methane, alcohol, hydrogen and smoke), I would like to show you at the end how you can connect a traffic light for air quality.

Investigation on sensor SHT30 for temperature and relative humidity

We had seen that the temperature display was a little too high and, as a result, the value of the relative humidity was a little too low, despite the recesses in the circuit board, which we can clearly see in the following picture. This largely reduces heat conduction via the board. But the proximity to the heated MQ-2 gas sensor is still noticeable. The only thing that helps here is a combination of all the tricks that we have also received from our customers: plastic strips, place the Envy at an angle or upright with the MQ-2 above the SHT30, a small fan to move the ambient air and blow the warm air away, and finally a correction value in the sketch. More about this issue further down in the Envy_WebServer_MQ2_SHT30.ino sketch.

 

Examination of the MQ-2 sensor

In the first part we wrote that MOS sensors measure the change in resistance when gases are present. The recommended MQ-2 library from labay11 then showed values ​​for LPG, CO and Smoke using an unknown algorithm. All of these values ​​are based on one single measured value at the analog input A0. So if there are known limit values ​​for these substances, this library is good to use.

But the simple solution that Niklas Heinzel uses in his Easy-Start Sketch (download on the product page) is completely sufficient. The analog values ​​are between 1 and 1024. In our living room the value was between 70 and 110; after placing a piece of kitchen paper soaked in rum on the MQ-2, 1024 was displayed immediately, after a while decreasing to 900 and 800. Which threshold value you want to use in the end to switch on the yellow or red indicator light, you can determine yourself, maybe 200 for yellow and 250 for red?


We connect our AZ-Envy to the WLAN

With the following sketch we connect the AZ-Envy to the WLAN and use it as a server for the measurement data. Please note that you have to enter your SSID and your WLAN password in the code before uploading so that you can see the sensor data in the browser of your PC or smartphone. Download Sketch Envy_WebServer_MQ2_SHT30.ino.

With the tilted AZ Envy, a small 5V fan, operated with 3.3 volts because of the significant reduction in the noise level, and a correction value of 0.5, I have achieved useful results.

 


There is a second possibility to register the AZ-Envy in the home WLAN as Gerald Lechner described in his blog in April 2019: the use of WPS (= WiFi-Protected-Setup).

For this we use the built-in button on the AZ-Envy: the FLASH button. This is only needed when starting if we want to put the ESP8266 into flash mode. After starting the program with RESET we have a "normal" button on GPIO0 (zero). So we only need to change the second line of code in the sketch #define WPS 0 .

Here the adapted Code for logging into the WLAN using the WPS button can be downloaded.

If you set the baud rate to 74880 in the serial monitor, you will see all outputs during the start of the ESP8266. When prompted, first press the WPS button on the router, then the FLASH button on the AZ-Envy. After a successful login, the access data are saved in the non-volatile memory of the ESP8266. So you don't need to press the WPS button every time.

The Arduino IDE offers a practical tool under Tools to delete the WLAN data. Under Erase Flash you have three options to choose from:

  • Only Sketch // just clears the code
  • Sketch + WiFi Settings // clears code and WiFi password
  • All Flash Contents // erases everything including SSID and password


GPIO outputs

Now that we have already discovered the button as a GPIO input, I would like to show the two (hidden) GPIO outputs in order to control a traffic light for the air quality.

First I show the circuit diagram of the AZ-Envy:


As read above, the FLASH button is on GPIO0. The only GPIO connections that are brought out are called TX and RX in the picture at the top right. These are used as serial ports for programming and for displaying sensor data in the serial monitor.

However, if we display the sensor data in the WiFi anyway, we can also use these pins with a Bi-color LED. Our pins are then called GPIO1 and GPIO3. And what do you have to consider?

First, provided we are using the Serial Monitor for the startup phase with Serial.begin (baud_rate), we have to end this connection with Serial.end (). Then GPIO1 and GPIO3 can be used.

And secondly, our traffic light should of course display the three colors red, yellow and green. This is possible with the bi-color LED with its three legs GND, R and G and the pulse width modulation. So either the pin for the red component to "On" or the pin for the green component to "On". And yellow is the mixed color of red and green, but with PWM I took only half of the green component.


/********************************************************************
Ampel mit bi-color LED

 gelb = rot(255) + grün(128)
********************************************************************/

int ledred = 1; // RX = the PWM pin the red LED is attached to
int ledgreen = 3; // TX = the PWM pin the green LED is attached to

// the setup routine runs once when you press reset:
void setup () {
// declare pin 9 to be an output:
pinMode (ledred, OUTPUT);
pinMode (ledgreen, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop () {
// set the brightness of pin 9:
analogWrite (ledred, 255);
delay (1000);
analogWrite (ledgreen, 128);
delay (1000);
analogWrite (ledred, 0);
analogWrite (ledgreen, 255);
delay (1000);
analogWrite (ledgreen, 0);
delay (1000);

Download Sketch

Who would have thought what is in the little AZ Envy. And that's not all. Because our “old master” Gerald Lechner, whose book “SMARTHOME” has just hit the shelves, has come up with a little more, for which you can use the parts behind today's door sensibly. But this is another story.


Furthermore, a nice pre-Christmas season!

Specials

3 comments

Bernd Albrecht

Bernd Albrecht

Hallo und vielen Dank für Ihr Interesse an unseren Produkten und Blog-Beiträgen.
Auszug aus dem Datenblatt des MQ-2
MQ-2 Sensors are used in gas leakage detecting equipments in family and industry, are suitable for detecting
of LPG, i-butane, propane, methane, alcohol, Hydrogen, smoke.
Der Sensor kann nicht zwischen den Gasen unterscheiden. Das Prinzip ist eine Widerstandsänderung in Abhängigkeit von der Gaskonzentration. Deshalb wird lediglich ein analoger Wert am ADC (Eingang A0) gemessen. Sie können einen Grenzwert angeben, bei dem Alarm ausgelöst werden soll. Dafür sollten Sie ggf. die Werte im Normalbetrieb einige Tage messen und den Grenzwert dementsprechend festlegen. Das Schöne beim AZ-Envy ist, dass der Alarm sowohl über WLAN ausgelöst werden kann als auch über eine rote LED oder Buzzer an den umfunktionierten GPIO pins für TX und RX.

Martin Vierbücher

Martin Vierbücher

Ich habe mir kürzlich ein 3-er Set bestellt und über die Feiertage in Betrieb genommen. Mit der Anleitung war das kein Problem und das Gehäuse war auch schnell Dank der stl Dateien gedruckt. Leider musste ich im Deckel eine Nut fräsen damit der Deckel wegen der Stiftleiste auch zuging. Vielleicht die Nut schon im 3D Modell aufnehmen? Mit offenem Gehäuse bin ich so etwa mir dem im Sketch angegebenen Offset hingekommen, mit geschlossenem Gehäuse bin ich dann aber wieder um fast 4°C und somit um über 10°C daneben. Damit ist der Messfehler größer als die zu erwartende Temperaturdifferenz im Zimmer! Das schreit eher nach einer Korrekturkurve, oder? Der Gassensor funktioniert sehr gut, ich zweifle aber auch die Werte für Monoxid an, danach müsste ich öfter Kopfweh haben. Habe mal gelesen dass er 24h an der frischen Luft eingebrannt werden muss? Dynamisch, d.h. angepustet, reagiert er wunderbar. Und jetzt meine eigentliche Frage, ich würde einen der Sensoren im Heizungsraum platzieren und frage mich nun was ich anwählen soll. Erdgas ist laut google Methan und Methan kann der Sensor nur weiß ich nicht was ich im Web Interface selektieren soll. Wurde Methan vergessen?

Cretel

Cretel

Bonjour, je souhaiterai intégrer l’azenvy a mon serveur domoticz et mysensors, pourriez vous m’indiquer un exemple de croquis.
Merci pour toutes vos innovations et votre sérieux.
Cordialement.

Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN