Component · Sensor
Raspberry Pi Camera
The camera that plugs into a Raspberry Pi's CSI ribbon rather than USB — a dedicated data lane, autofocus, and the sensor most robot vision code assumes.
What it is
A small sensor board on a flat ribbon cable that connects to the Raspberry Pi’s CSI port — a dedicated camera interface, not USB. That distinction is the whole reason it exists. A robot’s Pi is usually already carrying Wi-Fi, a serial link to a motor controller, and possibly storage on its USB bus; a camera pushing 1080p through the same bus is where that stops working.
For a robot, the camera is the sensor that changes what is possible. Every other sensor on this site reports one number — a distance, an angle, a reflectance. A camera reports a scene, and that is what lets a robot recognise what something is rather than only that something is there.
How it works
Light hits the sensor, and the sensor streams raw rows out over MIPI CSI-2 — a fast, short-range serial link — into the Pi’s image pipeline. The Pi turns those raw rows into a usable image: debayering, white balance, exposure, lens shading correction. On current Raspberry Pi OS this is handled by libcamera, with rpicam-apps on the command line and Picamera2 in Python.
Two consequences matter for robots:
The pipeline costs time. A frame is not available at the instant it was exposed. By the time your code sees it, tens of milliseconds have passed, and a moving robot has moved. Any control loop closed on vision has to be designed around that delay.
Exposure is automatic unless you stop it. Auto-exposure will happily change the brightness of your scene between frames, which is fine for photographs and hostile to a vision algorithm that thresholds on brightness. Lock exposure and gain once the lighting is settled.
When to use it
Reach for a camera when the robot needs to answer a question a scalar sensor cannot:
- Fiducial markers — ArUco tags give a full 3D pose from a single frame, which is the cheapest way to get a robot a real position fix.
- Line following in the real world — a camera sees the line metres ahead, where a reflectance array sees only what is directly beneath it.
- Object recognition — telling a chair from a wall, rather than reading the same 40 cm from both.
- Visual SLAM — building a map from images alone.
Do not add one for obstacle avoidance. A VL53L0X answers “how far?” in 20 ms with three lines of code; a camera answers it worse, slower, and with a hundred times the effort.
Wiring and gotchas
- The ribbon has an orientation. The silver contacts face the board’s connector contacts — on a Pi, that means the blue backing tab faces the USB/Ethernet side. Inserted the wrong way, the camera simply is not detected, and nothing is damaged.
- Lift the connector latch first. Pull the plastic collar up gently, seat the ribbon fully square, then press the collar back down. A ribbon that is in at a slight angle enumerates intermittently, which looks like a faulty camera.
- Pi 5 and Zero need the 22-pin cable. Same camera, narrower connector. Check before you order.
- Keep the ribbon away from motor wiring. It is an unshielded high-speed link running next to whatever else you have crammed into the chassis; motor noise coupled into it shows up as corrupted frames.
- Budget the power. Roughly 250 mA on top of the Pi’s own draw, from the same supply that browns out and corrupts the SD card if you skimp on it.
- Focus is a setting, not just a ring. On Module 3 the autofocus will hunt if the scene is low-contrast. For a robot that always looks at roughly the same distance, set a fixed focus position and stop it hunting mid-manoeuvre.
Explore the graph
Used in these builds
Projects, learning paths, and simulators that include the Raspberry Pi Camera.
Questions
Raspberry Pi Camera FAQ
Is a Pi camera better than a USB webcam for robotics?
For a robot, usually yes, and the reason is the connector rather than the picture. A CSI camera has its own data lane straight into the Pi's image pipeline, so it does not compete with a Wi-Fi dongle or a serial link for USB bandwidth, and its frame timing is far more predictable. A webcam is the better choice only when you need a long cable — CSI ribbons are short and fragile — or when you want the camera to work unchanged on a laptop.
Which Raspberry Pi camera should I buy for a robot?
Camera Module 3 for most robots — autofocus, a wide-angle option, and current software support. Take the wide (102°) version if the robot needs to see things close to itself, which is nearly always true for navigation. Choose the Global Shutter camera instead if the robot moves fast while looking, and the HQ camera if you need a specific lens. Camera Module 2 is still fine and cheaper if fixed focus suits you.
Why does my camera image skew when the robot turns?
Rolling shutter. The sensor reads out one row at a time rather than capturing the whole frame at once, so anything that moves during readout is recorded at a slightly different place on each row — a turn shears straight lines into slanted ones. It matters because pose estimation assumes one instant per frame. Shorten the exposure, slow the robot while measuring, or use the Global Shutter camera, which captures every row at once.
Does the Pi 5 use the same camera cable?
No, and this catches almost everyone. Pi 5 and the Zero models use a narrower 22-pin connector, while Pi 4 and earlier use the 15-pin one that ships with most cameras. The camera itself is the same; you need the right ribbon or an adapter. The Pi 5 also has two camera connectors, so it can run a stereo pair.
Do I still use the picamera library?
No — the original `picamera` module was written against a camera stack that no longer exists on current Raspberry Pi OS. Use **Picamera2**, which sits on libcamera, or capture through OpenCV once the camera appears as a V4L2 device. Most tutorials older than a few years are written for the dead API, which is the usual reason a copied snippet fails immediately on a fresh install.
Further reading