Mailbox with E-Mail Notification and Solar Panel

The following blog post was sent to us by our customer Helmut Schmidt. This is a mailbox that sends notifications via email when mail has been deposited. The power supply was realized with small solar panels and rechargeable batteries. Have fun reading and tinkering with it:

The mailbox was built together with a work group of a retirement and nursing home. The idea was to equip the mailbox with an e-mail notification. As soon as someone drops in a wish list, an e-mail is sent to a group of volunteers, the Green Ladies. After all, no one is going to check the mailboxes every day. The result was a mailbox with a solar module and an ESP8266 D1 mini. The program uses Deep Sleep until a wish list is posted or the door of the mailbox is opened.

circuit

Required hardware

1

D1 Mini Nodemcu with ESP8266-12F WLAN module

1

LM2596S DC-DC Power Adapter Step Down Module

1 or 2, depending on the ambient brightness

Mini SolarPanel Debo Solar 0.5W 5V

1

Ultra-fast avalanche sintered glass diode BYV 27/200

1

Li-ion battery, 18650, 3.7 V, 2600 mAh, incl. MicroUSB charging socket

1

Alternatively Li-Ion battery, 18650, 3.7 V

3

Alternatively NiMH batteries

1

Battery holder

1

680 KOHM resistors for voltage divider

2

10 KOHM resistors for voltage divider

2

Microswitch

2

1 μF capacitors (tantalum)

1

common diodes

1 counter


Preparations

Download Additional Board Manager Ulr
File> Preferences:
http://arduino.esp8266.com/stable/package_esp8266com_index.json

Install the nine packages with the board dress
Tools> Board> Board manager:
ESP8266 by ESP8266 Community

After installation, you will find all ESP8266 boards. Select Lolin (WEMOS) D1 Mini & R2.

Under File> Examples of D1 Mini> ESP8266 If the LowpowerDemo is located with 10 tests for Modem Sleep, Light Sleep and Deep Sleep.

This blog post has already described in detail how to send G-Mails via ESP8266:

https://www.az-delivery.de/blogs/azdelivery-blog-fur-arduino-und-raspberry-pi/g-mails-per-esp

In the blog post Sending G-Mails via ESP8266 it has already been described in detail how to send G-Mails via ESP8266. This still needs its own library of github.com getting charged. Then you can Sketch> Add File> Open The just downloaded .zip-Choose a file. over File> Examples from own libraries> ESP8266SMTP Find the G-Mail program.

It is highly recommended that you create your own email account to send emails to your main personal email address. Do not use your main personal email address to avoid accidentally blocking or temporarily disabling your account. For experiments, it is recommended to use a Gmail.com account to send the emails. The recipient email can be your personal email.

All details for setting up a Gmail.com account and an e-mail address can be found at the following link.

Connection between solar module, battery and ESP8266

The specifications were the most inexpensive application with one or two solar panels. Normal Ni-MH batteries have the disadvantage of a relatively high self-discharge, monthly around 15-25%. Meanwhile there are better Ni-MH batteries with a self-discharge of only 15% loss within one year, but then similar in price to Li-Ion. Two solar panels deliver over 5 V and mostly over 10 V at usual room brightness. Under load, the voltage usually breaks below the maximum charging voltage. Due to the protection function in the Li-Ion battery itself (or with LM2596S DC-DC power supply adapter) voltages of 7 V are no problem. However, Ni-MH batteries should be charged to a maximum of 1.4 V. A 18650, 3.7 V, 2600 mAh, incl. MicroUSB charging socket was also selected as the Li-Ion battery. Thus, the protection circuit is already integrated in the battery. The first outdoor tests showed sufficient charging by the solar panels, both with NiMH - and LiIon - batteries. At room brightness, Ni-MH had the lead. Obviously, at low charging currents, the protection circuit consumes more current than is stored in the batteries. One possibility would be to use a Li-Ion battery without built-in protection circuitry just by limiting the current by switching with the ESP8266.

To prevent overcharging, the deep sleep is briefly interrupted by the RTC timer for a voltage measurement. If, on hot days, the voltage is close to the maximum charge voltage, the Wifi is activated and the voltage is brought back to the norm. The measurement is done with analogRead(pin_voltage) at GPIO A0. The Wemos D1 mini already has a voltage divider of 220 kOhm / 100 kOhm built in, with an internal resistance of 320 kOhm. If another resistor of 680 kOhm is added between A0 and Vin, the voltage range is extended from 1 V to (680 + 320)/320 = 3.1 * 3V = 9.3 V. The measured voltage must therefore be identical with the measured voltage. The measured voltage must therefore be multiplied by the factor 9.3.

construction

If the voltage drops close to the end-of-discharge voltage, the first thing to do is charge the battery for some time. For Li-Ion batteries the final discharge voltage is 3.5 V, for Ni-MH batteries 1.1 V. To safely exclude reverse current from the battery to the solar panel, the solar panel and converter are connected via a BYV 27/200 diode. The actual task of the ESP8266 is done by WAKEUP. It is recommended to load the LowPowerDemo on the ESP8266 beforehand to try out all possibilities. It is best to operate the ESP8266 with an external voltage source and to display the current consumption with a measuring device. With runTest6 in Forced Light Sleep the minimum current consumption is 0.9 mA, in Deep Sleep only 0.15 mA. However, Deep Sleep only allows a single external signal for wakeup. The RTC timer also runs in Deep Sleep. As soon as the time of ESP.deepSleep(microseconds) has expired, LOW is applied to D0/GPIO16. So if D0 and RST are connected, the EPS8266 is reset. So that further signals can be evaluated, it needs still voltage dividers from in each case a resistor and a capacitor (s. circuit).

circuit diagram

The symbols of the LEDs behind the BYV 27/200 diode represent the solar modules. The switch (shown as dip switch module on the photos) disconnects or opens the connection to the battery.

As soon as a letter is inserted, LOW is applied via microswitch D5. When the letterbox is opened, LOW is at D7. Via the capacitor the reset is executed for a short time. The ESP8266 starts up and registers the inputs of D5 and D7. The time constant must be as short as possible so that the spike executes the reset safely, but the input at D5 and D7 is still LOW. The diode between RST and D0 allows to program the ESP8266 as well.

D1 mini wired

It is also important to monitor the WiFi status. Should a connection to the network fail, the attempt to connect is aborted after wifiTimeout = 60 seconds. The next attempt is made by the timer after about 71 min. If there is still no connection to the network after a longer time, the voltage will drop below the minimum voltage and, as described above, the battery will first be recharged. The triggering event is stored in the EEPROM.

Calculation of the power consumption

Without solar panels, the consumption in Deep Sleep is 0.15 mA . Assuming one email per day, the consumption is about 60 mA for about 30 seconds. Per day this makes 0.15 mA * 24 h + 60 mA * 1/60 / 2 h = 4.1 mAh. With a Li-Ion battery with 2600 mAh, the D1 mini could thus be operated 2600 * 70% / 4.1 h = 440 days without interruption. Even at room brightness, the two solar modules supply about 0.5 mA, which makes about 0.5 mA * 12 h = 6 mAh. This should cover the power consumption completely. Outdoors, the performance of the solar modules would be even better. For security reasons, the battery charge status is displayed with every e-mail. When sending, peaks of up to 200 mA occur. After sending an email (with 3 NiMH batteries) the same voltage was measured after 3 hours as before the email. Measurements for charge and discharge voltage by an ammeter should be taken with caution. Especially at the reversal point (about U = 0 and I = 0) with an electronic meter, the reading depends on its internal resistance. So if unusual values occur, the remedy is to set the measuring range to 10 A, with 10 mA steps.

Batteries

All batteries have advantages and disadvantages. A LiFePO4 battery has a voltage of 3.3 V and would therefore be suitable, but also requires a safe protection circuit, as it must not be charged above 3.65 V. NiMH batteries have the disadvantage of higher self-discharge. LSD NiMH (low self-discharge) are best. The use of LiIon batteries depends on the ambient brightness. No warranty is given for Li-Ion batteries without protection circuit. Alternatively, a NodeMCU-32S was also tried. The power consumption was 9.8 mA during "deep sleep". You can say the NodeMCU-32S was more in half sleep than deep sleep. The NodeMCU-32S does not disable the USB port during deep sleep. Current consumption below 20 µA is possible with the DFRobot FireBeetle ESP32 IoT and DFRobot FireBeetle ESP-12F (ESP8266) IoT.

Conclusion

The long-term testing of the mailbox with e-mail notification and solar panel is still pending. The big problem is to realize the permanent power supply. Solar panels do not always provide enough voltage and the stored current in the batteries may not be sufficient. A change from the ESP32 to the ESP8266 helped a bit because of the lower power consumption. But it was also important to show how to use three inputs despite Deep Sleep.

Mailbox

Suggesting of an open source weather sensor:
https://www.ltspiceusers.ch/threads/opensource-wettersensor-werdegang.392/

ESP8266WIFI library documentation:
https://arduino-esp8266.readthedocs.io/en/latest/libraries.html

Enclosed the entire program with notes or here as a download:

Remember to enter your wifi and email account details (from line 36 and 90)
 // MINI_SOLARPANEL 5V and Battery Connect via ultrafast avalanche sintered glass diode BYV 27/200 //
 
 // author:
 // dr. Helmut Schmidt <grueneengel17@gmail.com>
 
 #include
 #include
 #include
 
 // liion_akku
 // const int load voltage_max = 5500; // The ideal charging voltage for lithium-ion batteries is around 4.2 volts. Lion battery protected from overvoltage
 // const int load voltage_min = 3500; // discharge voltage
 
 // for NiMH_Akkus
 byte N_Akkus = 3;
 contam int Charging tension_max = N_Akkus * 1400;  // Load voltage max. 1.4 V for NiMH_AKKU
 contam int Charging tension_min = N_Akkus * 1100;  // discharge voltage = 3.3 V minimum under load
 
 
 int tension;
 contam int pin_ voltage = A0;
 
 byte flag_post = false, flag_lustration = false,
 
 uint16_t Outstanding_email = 0;
 uint16_t e-mail = 0;
 uint32_t time-out = 60E3;  // 60 Second Timeout on the WiFi Connection
 
 // for w a k e u p //
 #define push button_leung 13 // D7 / GPIO13
 #define taster_post 14// D5 / GPIO14
 #define wake_up_pin 0 // wake_up_timer is connected to D0 / GPIO16 in ESP8266 >> D0 causes a reset
 
 // for WiFi //
 // Enter Your Wifi Configuration Below
 contam Char * Ap_sid = "WiFi Network Name";                // WiFi Network Name
 contam Char * Ap_pass = "WiFi Network Password";            // WiFi Network Password
 
 
 void set up() {
   pinmode(Wake_up_pin, INPUT_PULLUP);
   pinmode(TASTON_LECTION, INPUT_PULLUP);
   pinmode(TASTON_POST, INPUT_PULLUP);
 
   IF (digitalRead(TASTON_LECTION) == Low) flag_lustration = true;    // pushed button
   IF (digitalRead(TASTON_POST) == Low) flag_post = true;
 
 // s p a n n u n g s k o n t r o l e
 // Indoor resistance in Wemos D1 Mini is 320 Kohm with a voltage divider of 680kohm / 320 KOHM should
 // Material is converting factor 3.1 * 3 = 9.3. Voltage in MVolt.
   tension = analogead(pin_ voltage) * 9.3;
 //////////////////////e////// //////www.hrägnänd
 // voltage = 4000;
 
   // data from the EEPROM
   EEPROM.Begin(512);
   Outstanding_email = EEPROM.reading(0); e-mail = EEPROM.reading(4);
 
   IF (flag_post == false && flag_lustration == false && tension < Charging tension_max && Outstanding_email == 0)  ESP.deepsleep(0xffffffff);   // continue sleeping
 
 // Do not activate WiFi at post and undervoltage
   IF (tension < Charging tension_min) {
     IF (flag_post == true) {                // Deepsleep o H N E WiFi
       Outstanding_email++;
       EEPROM.writing(0, Outstanding_email);  EEPROM.commit();
       Serial.Begin(115200);  Serial.Println("Outstanding_email" + String (Outstanding_email)); // only for testing
    }
     ESP.deepsleep(0xffffffff);               // Convert
  }
 
   EEPROM.Begin(512);
   Serial.Begin(115200);
   Serial.Println();                                    
   Serial.Println("Voltage =" + String(tension) + "Mvolt");
   Serial.Println("Start Up");
 
   Wifi.persistent(false);    // Do not Store The Connection Each Time To Save Wear On the Flash
   Wifi.Fashion(Wifi_sta);
   Wifi.SetOutputPower(10);   // Reduce RF Output Power, Increase IF It Won't Connect
   Wifi.Begin(Ap_sid, Ap_pass);
   Serial.print(F("Connecting to WiFi"));            
   Serial.Println(Ap_sid);
 
   int wifitime = millis() + time-out;          // or 60 sec
   While (Wifi.status() != Wl_connected && wifitime > millis()) {
     Serial.print(".") ;                      
     delay (1000);
  }
   IF (Wifi.status() == Wl_connected) {
     SMTP.setmail("Broader@gmail.com")
    .setpassword("Password")
    .Subject("Subject")
    .setFrom("From")
    .setforgmail();                        // simply sets port to 465 and setServer ("smtp.gmail.com");
 
     IF (flag_post == true || Outstanding_email > 0) {
       e-mail++;  EEPROM.writing(4, e-mail); Outstanding_email = 0; EEPROM.writing(0, Outstanding_email);
       SMTP.Broadcast("Dr.h.schmidt@online.de", String(tension) + "Mvolt \ R" + String(e-mail) + "A Wishlist has entered the mailbox on the station 2");
    }
     Else IF (flag_lustration == true ) {
       SMTP.Broadcast("Dr.h.schmidt@online.de", String(tension) + "MVolt \ R mailbox leered on the station 2");
       Outstanding_email = 0; EEPROM.writing(0, Outstanding_email); EEPROM.writing(4, 0);
    }
     Else IF (tension > Charging tension_max) {
       SMTP.Broadcast("Dr.h.schmidt@online.de", "Overvoltage voltage =" + String(tension) + "mvolt email =" + String(e-mail) + "Outstanding email =" + String(Outstanding_email));      // comment on possibly
       EEPROM.commit();
       ESP.deepsleep(0x10000000) ;      /// all 10 sec for degradation of overvoltage
    }
 /////// Only for testing the timer
        Else IF (true) {
           SMTP.Broadcast("Dr.h.schmidt@online.de", "email =" + String(e-mail) + "Outstanding email =" + String(Outstanding_email) +  "Voltage =" + String(tension) + "Mvolt");      // comment on possibly
        }  
 /////// test end
  }
 
   EEPROM.commit();
   ESP.deepsleep(0xffffffff); // microseconds number of microseconds to sleep. The maximum value is 4294967295US or ~ 71 minutes.
   // It wants Never get here!
 }
 
 void loop() {   // It wants Never get here!
 }
 
 ///////// For the right use, comment all serial print commands ////////////
Thanks to Mr. Schmidt for his contribution.
Esp-8266Smart homePower supply

6 comments

Helmut Schmidt

Helmut Schmidt

Hallo,
@ Herrn Carius,
Ihn Vorschlag ist interessant. Ich gehe davon aus, dass es sich dabei um wieder aufladbaren Akku handelt. Z.B. von Conrad
CR123 A Li-Ion Akku 16340 mit 3,7 Volt, min.700mAh, typisch 760mAh, max. 820mAh, 35×16mm

Ich habe ja den Li-Ion-Akku, 18650, 3,7 V, 2600 mAh, inkl. MicroUSB Ladebuchse getestet. In der Kombination mit Solarpanel ist dieser Akku aber schlechter aufladbar als NiMH. Ich würde davon ausgehen, dass in CR123 ebenfalls eine Ladenkontrolle eingebaut ist.
Aus meiner Sicht haben alle Li-Ion-Akku, soweit sie gesichert sind, oder die Anwendung des TP4056 den Nachteil, dass die Ladenkontrolle etwas Strom verbraucht. Im Freien, ist das kein Problem. Sollen die Solarpannels aber bei Zimmerhelligkeit aufgeladen werde, verbraucht die Ladenkontrolle bereits den Strom. Sprich, die Ladebilanz ist negativ. Es ist nicht einfach den sehr geringen Strom aus Solarpannels auch in einen Akku zu speichern. Ob eine Z-Diode nötig ist und ob die Ladebilanz damit positiv, hängt von den Gegebenheiten ab.

Helmut Schmidt

Helmut Schmidt

Hallo,
@ Herrn Burmester
bei der Berechnung des Innenwiderstandes habe ich es mir zu einfach gemacht. Ich habe geschrieben: Setzt man einen weitere Widerstand von 680 kOhm zwischen A0 und Vin dazu, wird der Spannungsbereich von 1 V auf (680 + 320)/320 = 3.1 * 3V = 9.3 V erweitert.

Die korrekte Berechnung liefert 10V. Google weist zum Thema „Wemos D1 mini Innenwiderstand an Analogeingang“ einige Internetseiten, z.B. https://www.nikolaus-lueneburg.de/2016/12/spannungsteiler/ .
Insgesamt sind 3 Widerstände von 100 kOhm (intern), 220 kOhm (intern) und 680 kOhm (extern) in Reihe geschaltet. Am 100 kOhm Widerstand wird mit dem Analog Digital Converter (ADC) des D1 mini die Spannung gemessen, der für eine maximale Spannung von 1 Volt ausgelegt ist. Zusammen mit dem externen 680 kOhm Widerstand, wird der Spannungsbereich auf 10 Volt erweitert. Sorry, bin halt nur Hobby-Elektriker. Der Schaltplan wird abgeändert.

veit burmester

veit burmester

Hallo
Da meine ersten Anmerkungen nicht angezeigt werden möchte ich hier weitere Änderungswünsche für den Artikel machen.
Ein Spannungsteiler aus 220 kOhm und 100 kOhm kann keinen Innenwiderstand von 320 kOhm abbilden höchstens eine Reihenschaltung der Widerstände. Die Parallelschaltung von einem Kondensator und einem Widerstand ist ein RC Kombination und kein Spannungsteiler. Die Berechnung des Spannungsbereiches ist von mir (Elektromeister) nicht nachzuvollziehen. Vielleicht fehlen mir auch entsprechende Werte für die Berechnung. Deshalb meine Bitte hier mehr Transparenz zu schaffen.
Trotzdem ein gutes Projekt das auch für andere Anwendungen genutzt werden kann. Z.b. Zutrittskontrolle in Abwesenheit. Ich sage hier extra nicht “Alarmanlage”.

Frank Carius

Frank Carius

Man lernt jedes mal bei euren Beispielen was dazu. Gerade der Betrieb eines ESP mit Akku und Solarzelle ist ja schon eine oft geforderte Aufgabe. Laderegler oder selbst LowPowerSpannungsregler haben oft mehr Eigenbedarf als die ganze DeepSleep Schaltung. Ihr kommt aber 4.1mAh/Tag. Da könnte man mit CR123 Batterien (ca. 700mAh) eventuell besser fahren, zumal der ESP dann nicht immer wieder zu “Ladekontrolle” aufwachen muss. Quasi “D5/D7” Kontakt als Aufwachtrigger reicht und vielleicht einmal am Tag einen "ich lebe noch und meine Batterie hat so viel Volt) Statusmeldung.
Eine andere Option wäre doch einfach die Eingangsspannung durch die Solarzelle durch eine Zehnerdiode zu begrenzen. Dann “verheizt” man zwar etwas am Wiederstand und Z-Diode aber das macht die Schaltung heute ja auch durch “WLAN” als Verbraucher einschalten. Notfalls macht man die Solarzelle etwas größer (mehr Strom, nicht mehr Spannung) um noch genug Ladestrom zu haben.
Da hätte ich aber mehr vertrauen in die “eingebaute” Hardwaresicherheit ohne Software.
Oder man greift gleich zum TP 4056 (Auch hier bei AZ https://www.az-delivery.de/products/az-delivery-laderegler-tp4056-mini-usb) der bis zu 8V Eingang kann und den LiPo vermutlich besser schützt. Notfalls mit einer Z-Diode davor, wenn die Solarzelle eine höhere Leerlaufspannung haben sollte.
Aber bitte weiter so.

Andreas Wolter

Andreas Wolter

@Winfried Gräf: der Beitrag (samt Schaltung) wurde noch einmal aktualisiert. Danke für den Hinweis.

Winfried Gräf

Winfried Gräf

Stimmt der Schaltplan ? Schalter ?

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