Setup a Wireless Raspberry Pi Camera with 15 Lines of Code

Ayomipo Ojo
Python in Plain English
3 min readOct 2, 2021

--

It is without doubt that having a camera included in your project helps to spice it up a bit and as such your choice of camera (whether USB cameras or the official Raspberry Pi camera) will have an indelible impact on the quality of your project.

In this post I’ll be giving a step by step approach to setting up your android smartphone as a Raspberry Pi camera. In effect, we are converting our smartphone into an IP camera. Sounds interesting, right?

In this post I’ve assumed the reader has a firm grasp of the Python programming language.

In order to execute this project, we shall consider the smartphone setup, the Raspberry Pi setup and the demonstration stage.

Smartphone setup

In order to setup the smartphone as an IP camera, we need to download the “IP Webcam” app on Google Playstore.

IP Webcam on Google Playstore

Once the installation is complete, you can open the IP Webcam app.

IP Webcam interface

Next, we need to adjust some video preferences. Click on video preferences and change the photo resolution to “352 x 288”. This resolution is suitable for the Raspberry Pi we are using. You can decide to adjust other camera settings as deemed fit.

Return to the main interface and click on “Start server” to start the wireless camera.

Take note of the first IP address displayed on the screen as we will need it in the Python code for the Raspberry Pi.

Wireless webcam feed

At this point, we have successfully set up the smartphone as a wireless webcam or IP camera. Next, we need to set up the Raspberry Pi.

Raspberry Pi setup

The raspberry pi used in this project is the raspberry pi 4. However, this post is still applicable to the Raspberry Pi 3. To setup the Raspberry Pi, some libraries would have to be installed. I’m using the Thonny IDE to install the following packages:

  1. OpenCV
  2. Urllib3
  3. Numpy

To install these libraries, use the following command:

Once the libraries have been installed, you can now run the code on your Python IDE. Make sure that the IP webcam server is running on the smartphone before running the Python code.

Demonstration

Below is a video demonstration of what happens after running the Python code:

Raspberry IP Camera demonstration

What next?

At the end of this project, we now have the Raspberry Pi accessing our IP camera without any physical connection. We can use this approach to access multiple IP cameras.

Furthermore, we can perform some image preprocessing and undertake some computer vision projects with a wireless webcam in place.

More content at plainenglish.io

--

--

Physicist, Embedded systems engineer, Educator, Computer vision enthusiast, Robotics engineer.