Gartenhäuschen mit Micro Controller und Sensoren überwachen - Teil 3
in the first part I have described how the D1 Mini (ESP8266) with temperature sensor DHT22 and Gassensor MQ-2 as Web Server transmits measured values ​​from our garden cottage into domestic Wi-Fi.

These values ​​are displayed in the browser on the PC or the smartphone when you enter the IP address of the Web server (with me: into the address line.

The web server is programmed to output the word "alarm" when a temperature of 50 ° C or a gas concentration of 100 is exceeded. But you have to look active on the corresponding page to get everything displayed. I did not care, I also wanted to be notified with an acoustic and optical signal. So I had to evaluate the web page with a Micro Controller or Micro computer, filter out the measured values ​​and, if necessary, trigger the alarm with a buzzer and LED. in the second part I have a solution with a wireless Raspberry Pi and 1.3 inch OLED I2C 128 x 64 pixel display presented.

Now I want to show the structure with a D1 board and LCD Keypad Shield:

Required hardware for the first part:


D1 Mini Nodemcu with ESP8266-12F WLAN module


Battery shield for lithium batteries for D1 mini


Lithium battery 3.7V


DHT22 AM2302 Temperature sensor and humidity sensor


MQ-2 gas sensor smoke sensor air quality module

Mini Breadboard, Jumper Cable

Required hardware for the third part:


D1 Board NODEMCU ESP8266MOD-12F WIFI WLAN module


LCD1602 Display Keypad Shield HD44780 1602 Module with 2x16 characters


HD44780 1602 LCD module display 2x16 characters 

Mini Breadboard, Jumper Cable


Red LED with series resistor 200 to 330 ohms

The starting point for many projects is the collection of sample sketches expanded with each installation of new Micro Controller or a program library. Quickly I found the sketches Wificlient and WificlientBasic with Examples / ESP8266WIFI, which are basically adapted to include links from the Internet.

Two challenges (I learned at NATO: "No Problems, Only Challenges"):

First, I do not want to query the Internet, but an IP address in the domestic WLAN. And secondly, I want to save the transmitted HTML text in a string variable for further processing.

So the Sketch WificlientBasic must be extended and modified. We need the following program libraries to indicate the D1 Board at first at home on the home router and then as a Web Client to read the HTML side of the web server in the garden house.

 ESP8266Wifimulti Wifimulti;

Furthermore, the SSID and the password for Wi-Fi access are declared as well as the IP address of the web server (with me and the port for HTML (80) entered. Here you have to make your own entries.

Then the global variables are defined for the measured values ​​so that they are available in all functions.

In the void setup (), the connections to the serial monitor of the Arduino IDE as well as to the domestic Wi-Fi are manufactured.

The regular query of the Web server is then done with http.get () and http.getString () in the void loop (), the entire web page is stored in the variable payload.

After many lines of formatting and the code for the automatic updating of the web page in the browser, we will find the searched measured values ​​for temperature, rel. Humidity (engl. Humidity) from the DHT22 and for the gas concentration from the MQ-2 at the end. First, only "Tabula Rasa" = the deletion of the first 721 characters with the string method StringName.Substring (from, to). For me was from = 722, to is optional and can be omitted.

With a for loop I then search for the indexes for the letter T (for temperature), H (for humidity = rel. Humidity) and G (for gas concentration) as reference variables for the reuse of the method StringName.Substring (from, to) . For the respective values ​​for the parameters from and to I had to tinker a little, because the temperature may be one or two digit and, if necessary, be provided with a minus sign, and the value of the gas concentration can be two or three digits. Luckily, the string.Tofloat () method is very tolerant and ignores the spaces at the temperature and the character

Voila, thus displaying the values ​​for the temperature, humidity and gas concentration in the serial monitor. Here the (partial) sketch to Download

But that's just half the rent. We want to use the D1 BOARD without connection to the PC and, if necessary, trigger an alarm when the limit values ​​are exceeded. So a small display must be and, of course, our buzzer and, if necessary, a red LED for the alarm when the limit values ​​are exceeded.

Because it is as beautiful practical, I use the LCD Keypad Shield. Special features for using the keypad (ie the keys) can be found in the blog post "The new D1 with ESP8266Mod-12F in UN format". But we do not need the keys here. We only use the LCD, which is connected to GPIO pins. So install and include the appropriate library (not I2c) and define the pins according to the Pinout diagram of the D1 Board:

 // The LCD has no i2c adapter, the data is transmitted via the pins D4 to D7
 // LCD Pin To Arduino
 constant int pin_bl = 15;
 constant int pin_en = 2;
 constant int pin_rs = 0;
 constant int pin_d4 = 4;
 constant int pin_d5 = 14;
 constant int pin_d6 = 12;
 constant int pin_d7 = 13;  

The free pin D2 = GPIO16 we use for the buzzer and the LED.

Here is the advanced sketch: (Download)

     This Sketch Reads The HTML Text From A TCP Server in Your Local Network.
     By Gerald Lechner and Bernd Albrecht for AZ-Delivery * /
 #include // *** HTTP client
 #Ifndef Stassid
 #define Stassid "Your SSID"
 #define stapsk "your password"
 constant Char * SSID     = Stasid;
 constant Char * password = Stapk;
 constant Char * url = "";
 constant uint16_t port = 80;
 // The LCD has no i2c adapter, the data is transmitted via the pins D4 to D7
 // LCD Pin to Arduino
 constant int pin_bl = 15;
 constant int pin_en = 2;
 constant int pin_rs = 0;
 constant int pin_d4 = 4;
 constant int pin_d5 = 14;
 constant int pin_d6 = 12;
 constant int pin_d7 = 13;  
 Liquidcrystal LCD( pin_rs,  pin_en,  pin_d4,  pin_d5,  pin_d6,  pin_d7);
 float t = 0.0;
 float H = 0.0;
 float G = 0.0;
 int index;
 int indexh;
 int index;
 int buzzer=16;
 ESP8266Wifimulti Wifimulti;
 void set up() {
   // Initialize Digital Pin D2 = GPIO16 AS on OUTPUT.
   pinmode(buzzer, OUTPUT);  
   LCD.Begin(16, 2);       // LCD1602 with 16 characters and 2 lines
   // WE Start by Connecting to A Wifi Network
   Wifimulti.addap(SSID, password);
   Serial.print("Wait for wifi ...");
   whiler ( != WL_CONNECTED) {
   Serial.println("WiFi connected");
   Serial.println("IP address: ");
 void loop() {
   Serial.print("connecting to ");
 // Serial.print(host);
   Serial.print(url);    //neu
   //**** Neue Hauptschleife
   if (( == WL_CONNECTED)) {
     WiFiClient client;
     HTTPClient http;
     Serial.print("[HTTP] begin...\n");
     if (http.begin(client, url)) {  // HTTP     "url" ""entfernt
       Serial.print("[HTTP] GET...\n");
       // start connection and send HTTP header
       int httpCode = http.GET();
       // httpCode will be negative on error
       if (httpCode > 0) {
         // HTTP header has been send and Server response header has been handled
         Serial.printf("[HTTP] GET... code: %d\n", httpCode);
         // file found at server
         if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
           String payload = http.getString();
           String payload1 = payload.substring(722);
 //         Serial.println(payload);
 //         Serial.println();
           for (int i=0;i<=payload1.length();i++)  
               if (payload1.charAt(i) == 'T') indexT = i;
 //             Serial.println(indexT);
               if (payload1.charAt(i) == 'H') indexH = i;          
 //             Serial.println(indexH);
               if (payload1.charAt(i) == 'G') indexG = i;          
 //             Serial.println(indexG);
             String Tstring = payload1.substring(indexT+12,indexH-10);
             String Hstring = payload1.substring(indexH+10,indexH+12);
             String Gstring = payload1.substring(indexG+18,indexG+22);
 //           Serial.println(payload1);
             t = Tstring.toFloat();
             h = int(Hstring.toFloat());
             g = int(Gstring.toFloat());
             lcd.setCursor(0,0);     //Zählung beginnt bei Null, erst Zeichen, dann Zeile
             lcd.print(" h=");
             lcd.setCursor(0,1);     // 0=Erstes Zeichen, 1=zweite Zeile
             if (t>50.0 || g>100) {
               lcd.print(" Alarm!");
               digitalWrite(buzzer, HIGH);   // turn the Buzzer and LED on
               delay(200);                       // wait
               digitalWrite(buzzer, LOW);    // turn the Buzzer and LED off
               delay(100);                        // wait
               digitalWrite(buzzer, HIGH);   // turn the Buzzer and LED on
               delay(200);                       // wait
               digitalWrite(buzzer, LOW);    // turn the Buzzer and LED off
               delay(100);                       // wait
       else {
         Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
    } else {
       Serial.printf("[HTTP} Unable to connect\n");

In dem dreiteiligen Blog habe ich gezeigt, wie man Sensordaten über das heimische WLAN senden kann und die Werte am PC, Smartphone, mit Raspberry oder ESP8266 (auch alle gleichzeitig) anzeigen und einen Alarm auslösen kann, wenn Grenzwerte überschritten werden. Wie eingangs erwähnt, könnte man auch Bewegungsmelder und andere Sensoren als Diebstahlsicherung ergänzen. Viel Spaß beim Nachbauen.

Download als pdf

DisplaysEsp-8266Projects for beginnersRaspberry piSmart home

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