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)
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>
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?
Giannis
I have updated the links. I haven’t bought from these sellers but the parts look similar to the ones I used.
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?
Giannis
No there is no other version. You should break off these tubes using a pliers.
http://go.hackermagnet.com/1s
These are added only for support during printing.
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!
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.
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.
jeeva
Nm, just finding it hard to get them in South Africa
Giannis
Maybe something like that
https://vi.aliexpress.com/item/33037970540.html
Me
Hi, great project 🙂 I’ve tried to rebuild but now ordered multiple times the wrong lens. I just have a black picture around and a tiny, holy picture in the middle. Probably my lenses have a wrong focus. Without the lens I have a normal picture. Could you share some more details of your ordered lens, maybe from the letters on it or from your order? Maybe then I can also find a suitable one. Thanks!
Giannis
Hello, if you have a normal picture without the lens you probably haven’t removed the stock lens from the camera module. Search on youtube how to remove that.
The lens I used is a 3mp 2.8mm M12 like this:
https://vi.aliexpress.com/item/1005003036046197
Benji
Thank you Giannis ..very interesting.
can you share wiring scheme ?
Regards,
Ben
Giannis
I have added a schematic.
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
Giannis
I have added a schematic.
JS
Hi,
Which voltage is the IR Cut Filter expecting?
Giannis
Mine is working with 3.3V-5V.
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.
Vasant
Hi
Nice Project. Can you share the yaml configuration in HA for snapshot capture?
Giannis
A snapshot could be taken using the service “camera.snapshot”. Have a look here:
https://www.home-assistant.io/integrations/camera/
I use this service in automations when my doorbell is pressed to receive an actionable notification with a snapshot of my camera and a button to open my door. You could have a look on an example for actionable notifications here:
https://companion.home-assistant.io/docs/notifications/actionable-notifications/
I also have a script named espcam_video.sh in .homeassistant/scripts/ to take videos when I press a button on HA. You need to change the folder location and http_url. Also you need ffmpeg installed. Then you could execute this script calling the service shell_command.espcam_video_shell. Here is my script:
https://pastebin.com/TzChQbL6