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:

  • 3D Printed parts (download on thingiverse)
  • ESP32CAM module
  • M12 lens 3MP no IR (like that)
  • 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:

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]
      

20 replies on “Night vision on ESP32-CAM

  • Jayson Bucknell

    Your project looks very interesting. In checking though the parts the link for the “M12 lens 3MP no IR” is no longer working. I’m not sure I’m finding the right device in my search. Can you confirm what is needed?

    Reply
  • Corey Johnson

    I just received the parts and went to ‘fit’ everything. It seems the ESP32CAMT12_main.stl is different than the one in you images above. The IR LED board will not recede into it due to the screw posts and camera tube. Is there a different version of this stl?

    Reply
  • JirkaAerox

    Hello there! I’m really impressed with your project – it’s fantastic! I had a question regarding the IR filter and related aspects. As far as my understanding goes, most of the standard (cheapest) ESP-Cam models come with a built-in IR blocking filter. So, I’m a bit puzzled about whether you used a sensor that already had this IR filter in place and then added another switchable IR filter on top of it, or if you went for a sensor without IR capabilities altogether. I got a bit confused when you mentioned removing the IR filter and referred to the KiLLeRRaT85 post. The thing is, I couldn’t quite determine whether you used the original sensor or went a different route, as it wasn’t explicitly mentioned. Could you please clarify this for me? Thanks a bunch!

    Reply
    • Giannis

      The IR filter is behind the lens and is attached to it. I removed the lens with the IR filter to attach a new lens which is screwed on the switchable IR filter. I didn’t replace the sensor.
      Search on google or on youtube how to “remove the IR filter from an OV2640” and you will understand it.

      Reply
  • jeeva

    “M12 lens 3MP no IR” – the Alixexpress link no longer resolves, and I can’t find a matching product on google. Do you maybe have another description I can search for ? Only getting 3 mp with IR as my closest finds.

    Reply
  • damien

    Bonjour
    Très beau projet est intéressant serait il possible de détailler un peu plus la partie montage et cablage
    merci et bonne continuation

    Reply
  • Daniel

    Hi, I found this project after a long time trying to figure out how to make a good nightvision camera. Please, can you share wiring scheme and some images from this camera? Plus I am thinking about using the default lense or upgrading.

    Reply

Leave a Reply

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