AI Security Camera with Night Vision: I Built a Smart Intruder Alert That Works in Complete Darkness
The “It Saw in Pitch Black” Moment
I turned off all the lights.
Complete darkness. Couldn’t see my hand in front of my face.
Then I triggered the camera.
A few seconds later, my phone buzzed. A photo appeared in my Telegram inbox. The image showed my room – clearly visible, illuminated by invisible infrared light.
The AI analyzed the image and reported: “Room appears empty. No persons detected. Security status: Normal.”
My security camera just saw in the dark. And it understood what it was seeing.
That’s when I realized: this isn’t just a camera. It’s an intelligent security system that never sleeps, never blinks, and can see in total darkness.
And I built it myself.

What Makes This Security Camera Different
Most DIY security cameras just stream video. You have to watch the feed yourself. Or they record to an SD card and you check it later.
This camera does something different.
| Feature | What It Does |
|---|---|
| Ambient Light Sensor | Detects when lights turn on/off |
| IR Night Vision | Sees in complete darkness (invisible to human eyes) |
| AI-Powered Analysis | Sends images to GPT-4o-mini for intelligent description |
| Telegram Alerts | Sends photo + AI analysis directly to your phone |
| Autonomous Operation | Runs 24/7 without any input from you |
How it works:
Ambient light sensor monitors your room (checks every 3 seconds)
When light changes significantly (>40%), it triggers
If dark, IR LEDs turn on BEFORE capturing (critical!)
Camera captures image
Image sent to Telegram + OpenAI for analysis
AI describes what it sees (persons, suspicious activity, security status)
Why I Built This (The Real Story)
I live in a shared apartment. People come and go. Sometimes things get moved. Once, a package went missing.
I wanted a security camera, but I didn’t want:
Cloud subscriptions ($5-10/month forever)
Privacy concerns (my footage on someone else’s server)
Expensive hardware ($100+ for “smart” cameras)
False alarms from motion sensors (curtains moving, pets, shadows)
So I built my own. Total cost? About $35. No monthly fees. My data, my control.
And I learned how AI vision actually works in the process.

DFRobot ESP32-S3 AI Camera: The Board That Does It All
Before we dive into the code, let me introduce the star of this project: the DFRobot ESP32-S3 AI Camera (DFR1154) .
This isn’t just another ESP32-CAM. It’s a complete edge AI sensor hub with everything you need for advanced computer vision projects.
Full Feature Breakdown
| Feature | Specification | Why It Matters for This Project |
|---|---|---|
| Processor | ESP32-S3 (dual-core, 240 MHz) | Handles Wi-Fi, camera, light sensor, and AI calls simultaneously |
| PSRAM | 8MB Octal PSRAM | Essential for capturing high-res images without crashing |
| Flash | 16MB | Plenty of space for code and future features |
| Camera Sensor | OV3660 (2MP) | Better low-light performance than standard OV2640 |
| Camera FOV | 160° wide angle | Captures entire room – no blind spots |
| IR LEDs | 4x 940nm infrared | Invisible night vision – humans can’t see it, camera can |
| Ambient Light Sensor | LTR-308 (I2C) | Detects when lights turn on/off – our trigger |
| Onboard LED | GPIO 3 | Visual status indicator |
| USB | USB-C | Modern connector, no FTDI programmer needed |
| Battery Connector | JST (PH2.0) | Optional battery power for portable use |
| Dimensions | 42×42mm | Compact enough to hide anywhere |
What Makes This Board Special
1. Built-in Night Vision (No Extra Hardware!)
Most ESP32 camera boards require external IR LEDs and a separate light sensor. This board has both built-in. The four IR LEDs emit 940nm infrared light – completely invisible to human eyes but perfectly visible to the camera sensor.
2. Ambient Light Sensor on I2C
The LTR-308 light sensor lets the board know when the environment gets dark. This is what triggers our night vision activation. No external wiring needed – it’s already on the board.
3. OV3660 > OV2640
The OV3660 sensor is a significant upgrade over the common OV2640 found on cheap ESP32-CAM modules. It offers:
Better low-light sensitivity (critical for night vision)
Higher dynamic range
Improved color accuracy
4. USB-C with Native USB
No more hunting for FTDI programmers. Just plug in a USB-C cable and upload code. The ESP32-S3’s native USB support makes programming simple.
5. ESP32-S3 AI Acceleration
The ESP32-S3 has vector instructions specifically designed to accelerate machine learning tasks. While we’re using cloud AI in this project, the same board can run TinyML models locally.
Why Not Use a Regular ESP32-CAM?
| Feature | ESP32-CAM | DFRobot DFR1154 |
|---|---|---|
| Night vision | ||
| Light sensor | ||
| USB programming | ||
| PSRAM | 4MB (often less) | 8MB |
| Camera | OV2640 | OV3660 (better low-light) |
| Price | ~$10 | ~$25-35 |
The ESP32-CAM is great for basic streaming. But for an intelligent night vision security camera? The DFR1154 is worth every extra dollar.
What’s NOT Built-In (Honest Truth)
No board is perfect. Here’s what you still need to add:
| Missing Feature | Solution |
|---|---|
| Microphone | Not needed for this project (but available on I2S pins) |
| Speaker | Not needed for this project (but available on I2S pins) |
| SD card slot | Not needed – images go directly to Telegram |
| Battery charging circuit | Use TP4056 module if going portable |
For this security camera project, the board has everything we need. No soldering, no extra modules – just the board, power, and Wi-Fi.
The Hardware: DFRobot ESP32-S3 AI Camera
This project uses the DFRobot ESP32-S3 AI Camera (DFR1154) – an all-in-one board with everything built-in.
| Component | Specs |
|---|---|
| Processor | ESP32-S3 (dual-core, 240 MHz) |
| PSRAM | 8MB (for AI models and image buffering) |
| Camera | OV3660 (2MP, 160° wide angle) |
| Light Sensor | LTR-308 ambient light sensor (I2C) |
| Night Vision | IR LEDs (940nm, invisible to human eye) |
| Connectivity | Wi-Fi 2.4GHz + BLE 5.0 |
| Price | ~$25-35 |
The best part? No external wiring for night vision. No separate light sensor module. No SD card required (images go directly to Telegram). Everything is on one board.
Complete Parts List
| Component | Approx Price (USD) | Notes |
|---|---|---|
| DFRobot ESP32-S3 AI Camera [Click Here to Buy] | $25-35 | Includes camera, IR LEDs, light sensor |
| USB-C Cable | $3-5 | For power and programming |
| USB Power Adapter (5V, 2A) | $5-10 | Phone charger works fine |
| Telegram Account | Free | For alerts and AI responses |
| OpenAI API Credits | ~$5 one-time | ~500-1000 analyses |
Total: ~$33-50 USD
No soldering. No extra components. Just the board, a cable, and a phone charger.
How Night Vision Works (The Critical Detail)
Here’s what I learned the hard way: IR LEDs must turn on BEFORE capturing the image.
When lights turn off, the camera sensor sees darkness. If you capture immediately, you get a black image – useless for AI analysis.
The correct sequence is:
Lights OFF detected → Turn ON IR LEDs → Wait 150ms → Capture image → Send to AI
I initially got this wrong. My first dark images were completely black. The AI reported “Unable to see anything in this image.”
Once I fixed the sequence, night vision worked perfectly. The IR LEDs emit 940nm light – invisible to human eyes but clearly visible to the camera sensor.

The Complete Code
Full code available on GitHub: https://github.com/shahrear-ab/ESP32-S3-Ai-Camera-Secuirty-Camera-Project
Setting Up Telegram Bot
| Step | Action |
|---|---|
| 1 | Open Telegram, search for @BotFather |
| 2 | Send /newbot and follow prompts |
| 3 | Copy the bot token |
| 4 | Search for @myidbot, send /getid |
| 5 | Copy your chat ID |
Important: Send /start to your bot before testing – bots can’t send unsolicited messages.

Setting Up OpenAI API
| Step | Action |
|---|---|
| 1 | Go to platform.openai.com/api-keys |
| 2 | Create new API key |
| 3 | Add minimum $5 billing credit |
| 4 | Copy key into code |
Cost per analysis: ~$0.002-0.005 (about 200-500 analyses per dollar)
What You’ll Receive on Telegram
Alert Message:
text:
SECURITY ALERT! Light Change Detected
Light Level: 45.2 Lux → 120.8 Lux (167% change)
Lights TURNED ON or bright event detected
Night Vision: OFF
Image: Captured photo attachment
AI Analysis:
text:
AI Security Analysis: 1. A well-lit room with a desk, chair, and computer monitor 2. No person detected in current frame 3. No suspicious activity observed 4. Security status: Safe

Adjusting Sensitivity
| Parameter | Default | Effect |
|---|---|---|
| LIGHT_CHANGE_THRESHOLD | 0.40 (40%) | Lower = more sensitive, Higher = less sensitive |
| COOLDOWN_SECONDS | 20 | Time between triggers |
| LIGHT_CHECK_INTERVAL | 3000 (3 sec) | How often light sensor reads |
| NIGHT_VISION_ON_THRESHOLD | 15 Lux | Below this = IR ON |
| NIGHT_VISION_OFF_THRESHOLD | 30 Lux | Above this = IR OFF |
Troubleshooting
| Problem | Solution |
|---|---|
| No Telegram messages | Send /start to your bot first, press RESET |
| Dark images at night | Check IR LEDs with phone camera; ensure sequence order |
| Wrong light change direction | Code triggers on BOTH increase AND decrease |
| Camera init fails | Ensure camera initialized BEFORE light sensor (I2C conflict) |
What I Learned
This project taught me:
| Lesson | Why It Matters |
|---|---|
| Init order matters | Camera must init before light sensor on same I2C bus |
| IR timing is critical | Turn on IR, wait, THEN capture |
| Hysteresis prevents flicker | Different ON/OFF thresholds |
| AI can run locally-ish | API calls work, but need internet |
| Telegram is perfect for alerts | Free, reliable, real-time |
Watch the Complete Video Tutorial
See the security camera in action – live testing, night vision demo, and Telegram alerts:
AI Security Camera with Night Vision | ESP32-S3 Project
Don’t forget to Subscribe to Roborear on YouTube for more robotics and AI projects every week!










