Night vision on ESP32-CAM

I use a ESP32CAM module as a front door camera. It’s flashed with ESPHome and it’s connected with Home Assistant. THe biggest disadvantage of this module is the lack of night vision. The EPS32 module comes with an OV2640 camera. The standard lens has an IR filter which blocks infrared radiation. You could remove that IR filter and have some kind of night vision but it would mess the colors during daytime.

I read a conversation on reddit where KiLLeRRaT85 suggested to use a “M12 lens 3MP no IR”. I tried a lens like that and used a M12 IR cut filter to be able to switch on and off the IR filter which also holds the lens and allows to focus the image.

I also attached a IR LED board that is turned on automatically at night using a photoresistor. The IR filter needs a pulse from the ESP32 module to switch on the IR filter. Then it needs an inverted pulse to switch it off. I used a MX1508 H-bridge module to turn on and off the IR LED using two cables from the ESP32 module.

Then I created a Helper Toggle on Home Assistant that is read by ESP32 and it gives the pulse on the H-bridge module. I can toggle that switch manually or automatically based on Sun position. You can find my ESPHome configuration for my camera module below

I designed a 3d printed case that holds everything inside. Beside the camera module with my modifications there are a DHT22 sensor, a PIR module acting as a motion sensor, an external antenna and a step down converter that gets 12V (LED needs 12V) and outputs 5V for everything else including the ESP32.

List of materials:

    • ESP32CAM module
    • Lens With IR-CUT M12 (link) or get separately:
      • 1. M12 lens 3MP no IR (like that)
      • 2. M12 IR cut filter, holes distance 20mm (like that)
    • IR LED board 45mm 12V (like that)
    • MX1508 H-bridge module
    • Step Down module (like MP1584EN)
    • PIR module (HC-SR501)
    • DHT22
    • 2.4GHz SMA antenna
  •  
    •  
  •  
  •  
  •  
  •  
  •  
  •  

ESPHome configuration:

</p>
substitutions:
  devicename: esp-cam
  friendlyname: ESPcam

esphome:
  name: $devicename
  platform: ESP32
  board: esp32cam

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_wpa
  fast_connect: on
  ap:
    ssid: $friendlyname Hotspot
    password: !secret ap_pass

captive_portal:

logger:

api:

ota:

sensor:
  - platform: dht
    pin: 15
    temperature:
      name: $friendlyname Temp
      filters:
        - sliding_window_moving_average:
            window_size: 15
            send_every: 15
    humidity:
      name: $friendlyname Humidity
      filters:
        - sliding_window_moving_average:
            window_size: 15
            send_every: 15
    update_interval: 15s
    model: AM2302

binary_sensor:
  - platform: gpio
    pin: GPIO12
    name: $friendlyname Motion Sensor
    device_class: motion
  - platform: homeassistant
    name: "Input Boolean Night Mode HA"
    entity_id: input_boolean.esp32_night_mode
    on_press:
      then:
        - switch.turn_on: ir2
    on_release:
      then:
        - switch.turn_on: ir1

esp32_camera:
  external_clock:
    pin: GPIO0
    frequency: 20MHz
  i2c_pins:
    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: $friendlyname Door Camera
  resolution: 640x480
  jpeg_quality: 20 #10 best, 63 worst
  idle_framerate: 0.4 fps
  max_framerate: 5 fps
  vertical_flip: true
  horizontal_mirror: true

switch:
  - platform: gpio
    pin: GPIO2
    name: $friendlyname IR ON
    id: ir1
    on_turn_on:
    - delay: 100ms
    - switch.turn_off: ir1
    interlock: [ir2]
  - platform: gpio
    pin: GPIO14
    name: $friendlyname IR OFF
    id: ir2
    on_turn_on:
    - delay: 100ms
    - switch.turn_off: ir2
    interlock: [ir1]
<p>

21 replies on “Night vision on ESP32-CAM

Leave a Reply

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