Tested on:Raspberry Pi 2; Raspberry Pi B+; Python 2.7; Raspbian pre Jessie
Prerequisites:Raspberry Pi with Raspbian Jessie and internet connection (see steps 1-7 in the Introduction)
Hardware:Raspi Camera or
PiNoir module and IR-lamp for night vision

Raspberry Pi camera and night vision with PiNoir

The Raspberry Pi camera is easy to setup and can be controlled with Python code. PiNoir is another camera module that’s especially sensitive to Infrared (IR) light, which is helpful for night vision.

Boot the Raspberry Pi, enter

in the terminal and enable the camera. Shutdown the Raspberry Pi and open the connector closest to the ethernet port. Pull both sides gently… Then, put the cable into the connector with the blue side of the camera cable facing the ethernet port and close the connector, see

Raspberry Pi with camera closeup

The blue side of the camera cable plug points to the ethernet port

Snapshots from the terminal
To make a snapshot named mypic.jpg, enter

Show the help for more options like the image size and many others with

Videos from the terminal
To take a 5 second long video named myvideo.h264, enter

Change the viewpoint by adding the option -vf for vertical or -hf for horizontal mode.
The video duration is set by adding the option -t followed by the number of miliseconds.
The terminal help shows all valid options:

Using the camera in python
First, install the python drivers with

For python3, use

Sample python script
This script will create two snapshots, image1.jpg and image2.jpg with a 5 second pause between them. Then, a 5 second long video named myvideo.h264 is recorded.

Watch the video
Watch the video on your Raspberry Pi with the omxplayer from the terminal or copy the video onto your host computer with scp and watch it there.

Default parameters

All these parameters can be set in python! Additionally, see the picamera documentation, the raspberrypi.org camera usage tutorial or the picamera GitHub repository.

Night Vision!
The IR night vision camera PiNoir can be setup like the original Raspberry Pi camera. They look almost identical, besides the PiNoir being black:

Raspberry Pi camera(left, green) and PiNoir(right, black)

Raspberry Pi camera(left, green) and PiNoir(right, black)

For having night vision by using the IR light sensibility of the PiNoir, an IR lamp like this is required:

Assembled IR lamp for using the PiNoir camera of a Raspberry Pi

Assembled IR lamp for using the PiNoir camera of a Raspberry Pi

The PiNoir and the IR lamp in action

PiCamera documentation: http://picamera.readthedocs.org/en/release-1.9/
Raspberrypi.org camera usage tutorial: http://www.raspberrypi.org/documentation/usage/camera
PiCamera GitHub repository: https://github.com/waveform80/picamera
PiNoir camera module: https://www.raspberrypi.org/products/pi-noir-camera-v2/

Knight of Pi

Johannes Bergs aka Knight of Pi. Diploma in Bioinformatics, some Webdesign and Python coding then. Living in the beautiful city of Vienna.


  1. Thank for the tutorial, found this from the face detection tutorial.
    I am getting the following errors, any ideas?

    Traceback (most recent call last):
    File “camera_test.py”, line 10, in
    File “/home/pi/.local/lib/python2.7/site-packages/picamera/camera.py”, line 1046, in start_recording
    camera_port, output_port, format, resize, **options)
    File “/home/pi/.local/lib/python2.7/site-packages/picamera/camera.py”, line 723, in _get_video_encoder
    self, camera_port, output_port, format, resize, **options)
    File “/home/pi/.local/lib/python2.7/site-packages/picamera/encoders.py”, line 601, in __init__
    parent, camera_port, input_port, format, resize, **options)
    File “/home/pi/.local/lib/python2.7/site-packages/picamera/encoders.py”, line 187, in __init__
    self._create_encoder(format, **options)
    File “/home/pi/.local/lib/python2.7/site-packages/picamera/encoders.py”, line 727, in _create_encoder
    (self.output_port.framesize, macroblocks_limit))
    picamera.exc.PiCameraValueError: output resolution 1920×1200 exceeds macroblock limit (8192) for the selected H.264 profile and level

    • Hello Roy,
      i tested it but can’t replicate your error for Python3 and a recent Raspbian Stretch. Please retry with a fresh Stretch install.


Time limit is exhausted. Please reload CAPTCHA.