flash a ESP32-CAM to make a smart camera

Costing less than £10 (or $), the ESP32-CAM board comes equipped with WiFi, a camera and a micro SD-card slot. It needs a little work to turn this ‘development board’ into a something you can use to keep an eye on your desk, your pet or whatever. As a DIY project this is a fun way to make a first home automation accessory for say Home Assistant.

a tutorial sequence: > the offer > why a platform > home assistant > ESPhome > camera project > main menu

what you need

  • ESP32-CAM development board – comes with a camera. (Some kits have an external aerial that I’ve never needed)
  • Duport wires – female to female or any wire
  • FTDI UART board – switchable 3.3v or 5v and (check) mini-USB cable
  • If you prefer to have a standalone web camera see this project here instead.
  • If you want to integrate the camera into Home Assistant you’ll need Home Assistant set up on a Raspberry Pi with the ESPHome add-on installed. Follow the tutorial sequence above.

what is ESPHome?

ESPhome is software that helps to add a program to an ESP32 or ESP8266 chip. This process is often called “flashing a chip with new firmware”. The ESP chips are at the core of many automated devices from commercial smart plugs to home made projects. The EspHome software helps you bring together the features your need (eg we want a camera; we want it transmitting over wifi) and then connect these features to Home Assistant running on a Raspberry Pi. The instructions below show how to make the firmware file and get it loaded on an ESP32-CAM camera board.

Sometimes you can’t even buy the smart home gadget you need or it’s overpriced. ESPHome is software that allows you to monitor or control home-made devices with ‘Home Assistant’.

For example: a camera project using an ESP32-CAM was my first foray into DIY home automation. That wasn’t the easiest (but it was the funnest I think). I went on take apart and flash Sonoff devices which was challenging – though by 2022 this was less necessary. A next but easier task was to find a way to display readings of Xiaomi temperature sensors I’d placed in several rooms. You buy one of many sensors and wire it to an ES32 board. This is how I monitor how much heating oil is in my tank and how I made a smart meter that could tell me how much electricity I’m using through the day.

compile the ESPhome code into firmware

What we’re trying to do is to add our code to the ESP chip and replace what’s currently there. We first copy and paste this code into the ESPhome interface and add our wifi password and network settings. We can also add a wifi signal meter. We can re-edit this code for future projects.

   devicename: cat_camera
   name: ${devicename}
   platform: ESP32
   board: esp32dev
#Enable logging

# Enable a connection to the Home Assistant API 
  password: "YOUR Home ASSISTANT API password"
  password: ""

   ssid: "YOUR_SSID"
   password: "YOUR WIFI PASSWORD"
     # Set this to the IP you want for the ESP
     # Set this to the IP address of the router. Often ends with .1
     # The subnet of the network. works for most homes 
#Author by airijia.com board: esp32dev
     pin: GPIO0
     frequency: 20MHz
     sda: GPIO26
     scl: GPIO27
   data_pins: [GPIO5, GPIO18, GPIO19, GPIO21, GPIO36, GPIO39, GPIO34, GPIO35]
   vsync_pin: GPIO25
   href_pin: GPIO23
   pixel_clock_pin: GPIO22
   power_down_pin: GPIO32
   name: ${devicename} cam
   resolution: 800x600
 # Flashlight CHECK PIN
   - platform: gpio
     pin: GPIO4
     id: gpio_4 

  - platform: binary
    output: gpio_4
    name: ${devicename} light  

# The following can be omitted 
  - platform: restart
    name: ${devicename} restart 

  - platform: wifi_signal
    name: ${devicename} wifi signal
    update_interval: 600s
  - platform: uptime
    name: ${devicename} uptime 

how to ‘flash’ or put this code into a ESP32-CAM – words and video

Inconveniently, the ESP32-CAM doesn’t have a USB socket to connect it directly to your computer. To work round this a FTDI module is required.

On the right is a 3.3v ftdi which connects to the computer. On the left are dupont leads to connect to the ESP32-CAM.
  1. Identify the VCC (or 3.3v input), GND, TX and RX on the ESP32-CAM
  2. Use female-to-female Dupont jumper leads to connect the ESP32-CAM to a FTDI UART board set at 3.3v.
  3. Add the code to the ESPhome new device. Validate and compile the code into a binary file on your PC.
  4. Connect GPIO0 to GND with a Dupont lead as you plug the FTDI into a USB socket on your computer. You might also need to press the button on the ESP32-CAM.
  5. Use Esphome-flasher to upload the binary file to the ESP32-CAM.
A groundbreaking moment for one maker – my thanks to them for breaking ground for me.

2 Responses

  1. Graeme Watt says:

    Compiling failed on the first word of the first line of the example code; Substititions.

    • roger says:

      Tardy reply from me: by now I hope you’ll have noticed that the compiler isn’t helpful at locating a problem – it gets thrown by as little as a wrong space or colon. It’s not the “substitutions:” bit, it’s further below.
      A possible problem is that any of the sections further down your code is incomplete or incorrect.

Leave a Reply

Your email address will not be published.