Introduction: Multifunctional ESP32-Cam With E-paper Display for Home Automation and Security With Photo Transmission Via Telegram and Node-Red. Smart Doorbell
In this Instructabe I show you how I use an ESP32-Cam in my home automation. It has the following functions:
- Make a picture when the doorbell is rung. Make a picture when the front door is opened when the alarm is armed. The picture is sent via Telegram to my smartphone. Somewhat like a smart doorbell, without the video and bidirectional communication.
- Monitor the door and lock positions of my front door (door), back door (door), shed door (door and lock), bike shed door (door and lock). Monitor the main alarm state. Monitor the voltage of my sensors.
- Display the door, lock, alarm and voltage states on the e-paper display and change the display when the state changes.
- ESP32-Cam (AI Thinker)
- E-paper display (I used a 2.9 inch black and red Waveshare display)
- 5V power supply from phone charger.
- wires, connectors.
- Soldering iron
- 3D printer to print the housing (and design software)
Other required elements
- If you want to monitor data or a status you need a MQTT server and sensors which send data via MQTT.
- Home automation
- Node Red for sending the pictures from the ESP32-Cam to a smartphone
Step 1: The Idea
I had a Raspberry Pi Zero W in my hallway which made a picture when the doorbell was rung or when the door opened during the time the alarm was armed. Although this was working fine, I wanted to replace this with an even cheaper solution: an ESP32-Cam.
Next, I monitor in my home automation the door states of my main doors of the house and monitor the door and lock states of my two sheds. Often before we went to bed, someone had to check whether the doors of the sheds were locked, because the reading of the state was not easily presented in my home automation app. Therefore I wanted to present the door and lock states at a strategic position in my house.
I hade an unused 2.9 inch e-paper screen with black and red and found this suitable for my purpose. On this screen I now also present the state of the main alarm and the result of my voltage monitors of battery operated sensors (doorstate and temperature).
To combine my plans, I needed to control the e-paper screen with my ESP32-Cam, without influencing the functioning of the ESP32-Camera functions.
Step 2: Connecting the E-paper Screen to the ESP32-Cam
The ESP32-Cam from AI Thinker has very few unused exposed GPIO's (see picture). The e-paper module needed quite some connections to GPIO's (next to VCC and GND):
- DIN - SPI MOSI
- CLK - SPI SCK
- CS - SPI chip selection
- DC - Data
- RST - External reset
- BUSY - Busy status
HSPI and VSPI
The e-paper connects via the SPI bus. The HSPI pins (12, 13, 14 and 15) are exposed in the ESP32-cam and can be used. However in the standard settings not the HSPI, but the VSPI bus is active, I think because of the definitions for this board in "pins-arduino.h". The defined SPI pins can be found by printing the values to the serial port:
Serial.println(SS); Serial.println(MOSI); Serial.println(SCK);
How to use the HSPI?
I use the "GxEPD" library in the communication with the e-paper screen. In the standard code, the standard SPI-bus is used.
GxIO_Class io(SPI, /*CS*/ 15, /*DC*/ 4, /*RST*/ 2);
In my code I use the following lines to use the HSPI bus instead of the VSPI bus.
SPIClass epaper_SPI(HSPI); // define the SPI for the e-paper on the HSPI pins (CLK 14, MOSI 13, CS 15) GxIO_Class io(epaper_SPI, /*CS*/ 15, /*DC*/ 4, /*RST*/ 2); GxEPD_Class display(io, /*RST*/ 2, /*BUSY*/ 16 );
Please note that it is not possible to upload code to the ESP32-Cam when the e-paper display is connected
Step 3: The Rest of the Code
The code is based on the 'CameraWebServer' example from the Arduino IDE for the AI Thinker ESP32-CAM board.
The ESP32-Cam connects to my WiFi network and MQTT server form which it receives the door, lock and voltage statuses. When a door is opened and closed within the debouncetime of 10 seconds, the status of the display is not altered.
The code is published on my Github page.
The photos are made via a HTTP request, see the next step.
I wanted to use OTA via a HTTPUpdateServer, but I could not get it working, this seems not possible, see link.
I could not find a nice cross and checkmark for on the screen in the standard Adafruit fonts, so I made my own font characters. I made an Excel file to calculate the data/binary values. Unfortunately, I can not upload this Excel file to this Instructable. The resulting font file is attached though. It is based on the Adafruit SymbolMono18pt7b.h file. Also see the Adafruit website.
If you want to use it, place it in the \libraries\Adafruit_GFX_Library\Fonts folder.
Step 4: Photo and Telegram
It took me some time to work this out, but the resulting flow in Node-Red is quite simple, see the picture.
- The HTTP node does a GET request to the ESP32-CAM ([IP address]/capture). The result is a binary buffer. In my WiFi network I gave the ESP32-cam a fixed IP adress for this to work.
- In the File node the binary buffer is saved as a file with the given filename and location.
- In the Telegram payload node the file is sent via Telegram based on the reference of the file location and filename. The caption is the message attached to the picture. See https://flows.nodered.org/node/node-red-contrib-telegrambot-home.
The picture size generated by the GET request is defined in this code line in my code, SXGA is 1280 x 1024 pixels
Step 5: Hardware
The hardware is straightforward. I made connectors to connect:
- The ESP32-cam to the e-paper display. I soldered a JST connector in an angle of 90 degrees so the cable comes out at the back and not to the side.
- The ESP32-cam to the 5V USB input.
I designed and 3D printed a case for the ESP32-cam and the e-paper display. The case has a back plate which is mounted to the wall via glue, tape or screws and a housing for the components which is screwed to the back plate.
The camera of the ESP32-cam is pointed at my front door at a slight angle from the wall.
Step 6: Result
See the pictures for my final result.
The symbol in the top right corner displays the overall status of the doors and lock sensors. It displays a checkmark if all doors and lock are closed. So in the evening I can see whether I can go to sleep or whether I have to check or close a door or a luck.
I have you have comments or questions, feel free.