Security Camera: From Light on a Sensor to a Stream You Can Store
A camera is a sensor, a processor and a compressor. Understand those three stages and you can judge any camera on its real numbers instead of its resolution.
What a camera really does
Light falls on a silicon sensor and is converted into charge, then into digital numbers. A colour sensor has a Bayer filter over it, so each pixel only records one colour and the rest is worked out by interpolation. The camera then sets an exposure, a gain and a white balance, and produces one still frame. That part is the same in a $30 camera module and a professional broadcast lens.
A video stream is thousands of those frames, and raw frames are far too big to send anywhere. The frames are compressed, and the compression is where the numbers that matter come from. A 1080p stream at 30 frames per second runs at roughly 2 Mbit/s with modern H.265 compression. At that rate you store about 0.9 GB an hour, 21 GB a day, and around 640 GB for a month of continuous recording. Resolution is the least interesting of the published numbers. A 4 Mbit/s stream gives a better-looking recording than 2 Mbit/s, but a 4 megapixel image of an empty corridor at 4 frames per second is worth less than a 2 megapixel image at 30 frames per second of a doorway, because frames per second is what tells you what happened.
Latency and light decide whether a camera is useful
A camera that takes two seconds to show you the doorway is a recording, not a warning. That delay comes from the encoding, the network and the playback buffer, and the biggest single contributor is usually the buffer used to smooth out jitter in the network. Recording to a local SD card removes the network from the path entirely and gives you near real-time feedback.
Light is the other constraint. A sensor needs photons, so in the dark you get noise unless the camera adds light. Infrared illuminators work around 850 nm, which most silicon sensors can detect even though the eye cannot see it, and the camera switches its filter and exposure when it detects darkness. The switch has a cost: colour becomes monochrome, and the image can look flat. Which is why the best cheap systems are motion-triggered rather than always-on. A passive infrared sensor watches for a body moving across the scene and wakes the camera to record for a few seconds. Because most of the time nothing happens, the storage cost falls by a factor of fifty to a hundred, and the interesting footage is exactly the footage you keep.
Step by step
-
Capture a single still image
Take one frame from a camera module and save it to an SD card. Doing this first separates the imaging problem from the streaming problem.
-
Measure the real bitrate
Stream for a minute and measure the bytes on the wire. The number will surprise you, and it is what sets the storage bill.
-
Work out the storage requirement
Multiply the measured bitrate by the hours you intend to record, then by 30. This is the calculation that decides between a card, a drive and a subscription.
-
Add a PIR trigger
Connect a passive infrared sensor so the camera only records when something moves. Compare the daily storage with the always-on version.
-
Add night vision
Switch on an infrared illuminator and adjust the sensor's gain and exposure for the dark scene. Compare the result with the daylight frame.
-
Test the whole loop against the real link
Stream over Wi-Fi to a laptop on the same network and measure the end-to-end delay. If it is more than a second, move the encoder closer to the sensor.
What you'll need
| Item | Qty | Why |
|---|---|---|
| ESP32-CAM module with OV2640 camera | 1 | A camera and an MCU on one board, so the image is compressed before it ever touches the network. |
| Arduino Mega 2560 | 1 | More RAM than an Uno for buffering frames, and the serial hub project shows how to pair it with other sensors. |
| PIR motion sensor | 1 | The trigger that cuts storage by a factor of fifty and keeps the footage that matters. |
| Infrared LED array with a lens, 850 nm | 1 | Illuminates the scene in darkness where the sensor cannot see on its own. |
| MicroSD card module and 32 GB card | 1 | Local recording removes the network from the latency path and keeps working when the internet does not. |
| 5 V, 2 A power supply | 1 | Cameras, illuminators and an SD card write all at once, and a marginal supply causes dropped frames. |
Practise it before you build it
Every step above has a matching circuit in the ThinkEdge Learn simulator. The simulator runs a real
Arduino sketch against a modified-nodal-analysis solver, so digitalWrite actually drives the
LED on screen and the readings change when you change the wiring — no hardware, no burnt components.
A PIR (Passive Infrared) sensor detects motion by sensing the infrared heat that people and animals give off. The HC-SR501 outputs HIGH when it sees movement. Wire it to a digital pin and read it with digitalRead() — when motion is detected, sound the buzzer and flash the LED. This is the same sensor used in real burglar alarms and automatic lights.
Combine a PIR motion sensor with a slide switch (arm/disarm) and a buzzer. This is the same logic as a real home alarm: you arm the system when you leave, and if anything moves while it is armed, it sounds the alarm. We also use millis() to keep the alarm sounding for a fixed time even if the motion stops.
A PIR (Passive Infrared) sensor detects motion by watching for changes in infrared light. When a warm body (you, a pet, a robot) moves through its field of view, the OUT pin goes HIGH for a few seconds. We use that HIGH signal to switch an LED on. This is the same sensor in hallway lights, security lights, and automatic doors at the mall.
Mount an HC-SR04 ultrasonic sensor on top of a servo. Sweep the servo from 0° to 180° and back, and at each step measure the distance. Print the results to the Serial Monitor as "angle,distance" pairs. Open the Serial Plotter in the Arduino IDE to see a live radar-like graph of the room. With Processing on your computer, you can build a full visual radar.
The Mega has 4 hardware serial ports (Serial, Serial1, Serial2, Serial3). That means you can talk to 4 different devices at the SAME time — like a GPS, a Bluetooth module, an XBee radio, and the USB. Use 3 of those ports to read 3 different sensors in parallel and stream their data to the Serial Monitor as a CSV row every second. This is the foundation of every real Arduino data logger.
Common questions
How much storage does a security camera need?
At 2 Mbit/s for 1080p, budget about 21 GB a day, so a 1 TB drive holds roughly 45 days of continuous recording and a 256 GB card about 12 days. Motion-triggered recording changes the figure completely: the same drive can then hold months, because the camera is idle most of the time.
Is an IP camera better than analogue for a school?
For a classroom lab, IP is easier to teach because the video is a file you can open in any player and analyse frame by frame. Analogue is still cheaper per camera over long distances and is what most commercial systems use. The deciding factor is usually storage and whether you want to run your own analytics.
Can I build a DIY security camera for less than a commercial one?
You can, and it is a good project, but the commercial version wins on image quality, low-light performance and weatherproofing, which are the three things that are hard to build. The DIY version wins on being able to see exactly what the camera does, which is the reason to build it in a class.
Related guides
Try the full simulator with your class
103 guided circuit projects, 21 lessons and an in-browser Arduino simulator. The first 15 projects are free, no account needed. NCERT Science mapping on 47 projects, with Arabic and English copy in the regional builds.