Skip to content

Simple ESP8266 e-mail sensor / switch

I live in a building on a second floor. All the mailboxes are located on same spot at the main entrance. There is no way to pull any wires for power or the sensors.
To cut the story short a notification was needed when something was delivered to my mailbox.
I decided to go with ESP8266 powered by a Li-ion battery.

Main requirements:

• device must be off for maximum battery conservation
• device must be turned on by micro switch and stay on until the notification is sent
• after the task is completed device must turn itself off

Some fail safes:

• in case the lid stays open after the notification (big newspaper) unit goes to deep sleep
• spam prevention (my brother) if tries to open and close the lid multiple times in short time
• in case WiFi is down and no connection is possible, program times out and unit turns itself off

Another nice feature I wanted to implement was battery measurement and sending the value together with notification. But it didn’t happen cause I was very short on time.

Battery:

Battery was made by connecting two cells 3,7V 3000mAH in series and managed by 2S BMS board with balance charging capability. Cells were salvaged from old drone battery pack.

3,3V power supply for ESP8266 was integrated on battery using simple connection of LDO 1117 3,3V with two electrolytic capacitors.

Device schematic:

I made this schematic based on similar ideas on internet and ESP-12F datasheet.

For the main controller I chose ESP-12F simply because I had one lying around from my other project.
It was mounted on Izokee D1 mini (Wemos D1 mini clone I suppose).

Idea was to use complete D1 mini board but for some reason when ESP was turned off it was still using 16mA.
That was unacceptable so after being sure that code works as it should I de soldered ESP-12F from Izokee board and used it as standalone unit.
That reduced current to 16uA while device is off witch is acceptable.

The code:

Code was built on a guide from this great webpage: https://www.electronicshub.org/send-an-email-using-esp8266/
Please read the entire article from above webpage as it has complete guide how to make the code work correctly. Mine ISP supports only SSL encrypted SMTP on port 465 and it doesn’t allow a connection.

I had to register an account on SMTP2GO and soon after was getting an error message: “550 that smtp username’s account is not allowed to send”
I submitted a support request as described by one commenter in web page suggested above link:

Raibisch says
I solve the problem :

send an email to the smtp2go service and explain your problem (.”.. I use it for IOT services on an ESP Microcontroller…, please allow the use without own mail server account….”)

Short time after, great SMTP2GO support enabled the requested function and everything worked on first try.

Code is written for Arduino IDE

I wanted to make this build as simple as possible so everything was done “in the air”.
PCB was isolated with some Kapton tape and I soldered everything directly on ESP-12F.

Two wires are for 3,3V power supply, and 2 wires lead to micro switch.

We all have the same style of mailbox on building entrance so it looks a bit used but it serves its purpose.
Micro switch (sensor) was installed with some hot glue:

Battery was mounted in a way that it can easily be disconnected and taken out for a recharge. A wire holder with a tiny piece of Velcro.

ESP-12F was glued to plastic window so the WiFi signal can easily pass through.

Final thoughts:

Device is up and running for a full month now with 0 problems.
So far so good. Let’s hope it stays that way 😊

3 Comments

  1. Joaquim Santos Joaquim Santos

    Hi

    Getting this comment:
    21:28:12.005 -> Sending To
    21:28:12.255 -> 550 that smtp username’s account is not allowed to send

    Can you help ?
    Thanks

  2. Joaquim Santos Joaquim Santos

    Hi

    forget my previous question.
    Solved

  3. JULIEN KENIS JULIEN KENIS

    This looks great! Well done and congratulations!
    I am thinking of making the same thing but in stead of a micro switch, I would like to use an IR detection. Do you think this is possible.
    The reason: the mail box is a big box, where also small (grey) packages can be dropped, as well as (white) news papers and (brown) commercials… I don’t know if the IR detector can “see” these differences in color? Do you?
    Thanks,
    Julien (Belgium)

Leave a Reply

Your email address will not be published. Required fields are marked *