Software apps and online services
In this post, you are going to learn how to build a Wireless Video Surveillance Robot using Raspberry Pi. You will be able to control it from your smartphone browser or PC browser. Not only you will be able to move the robot but also the camera as we will add a pan tilt system.
- Raspberry Pi (I have used Raspberry Pi 4, also tested with Raspberry pi 3)
- Power Supply for Raspberry Pi or Power Bank
- 2 x L293D
- 4WD Robot chassis kit
- Pan tilt bracket with servos
- DC Power source (I have used 2×18650 batteries with battery holder)
- 2 X 3 Pin Header
- 2X20 Pin Header
- 5 X 0.1uf Capacitor
- 0.33uf Capacitor
- 100uf Capacitor
- 330 ohm resistor
- 5 X Terminal block
For video streaming, we are going to use Flask. Flask is micro web framework written is Python that is very easy to use and requires no libraries.
Use following command to install Flask.
pip3 install Flask
Then we need to install Numpy as we will have to map values in between our code.
pip3 install numpy
Then we need to install OpenCV to captures frames from pi-camera. Before install OpenCV, we need to install some dependencies required by OpenCV.
sudo apt-get install libhdf5-dev -y && sudo apt-get install libhdf5-serial-dev -y && sudo apt-get install libatlas-base-dev -y && sudo apt-get install libjasper-dev -y && sudo apt-get install libqtgui4 -y && sudo apt-get install libqt4-test -y
pip3 install opencv-contrib-python==22.214.171.124
After that, we need to install pigpio package required for controlling servo motors.
pip3 install pigpio
In last, we need RPi.GPIO package required for controlling DC Motors.
pip3 install RPi.GPIO
Project directory will look as follows
Our Flask App has 4 route.@app.route(‘/’) will host the home page. Calling this url will return the index.html file.
@app.route(‘/video_feed’) will be used to send a stream of video frames to the webpage captured from camera. It starts a new thread each time a new user is connected and thread is closed when the user disconnects.
To know more how this is done, check out article by Miguel Grinberg i linked above.
@app.route(‘/DCmotor’) will get data when moving left joystick.
@app.route(‘/ServoMotor’) will get data when moving right joystick.
We are basically sending
XMLHttpRequest when moving the joysticks. These requests are used to interact with servers without the need to do a full page refresh. These can both send and receive data but we are only sending in our case.
Below code from line 126 in index.html sends the data on moving left joystick.
var xhr = new XMLHttpRequest();
xhr.open('GET', "./DCmotor?x_dist=" + (sendJoystickL_xDist) + '&y_dist=' + (sendJoystickL_yDist))
To add virtual joysticks on webpage, i have used nipplejs by Yoann Moinet.
There are two joysticks available on the webpage. Red one on the right will control servo Motor and blue one on the left will control DC motors. Blue joystick will be available in 40% area from left and red joystick will be available in 40% area from right. Joysticks will not be available in 20% area in the centre.
Before running the code, you need to turn on the pigpio daemon.
Then type following command to run the code.
Then from your browser, type the IP address of your Raspberry pi followed by :8000.
If you don’t know IP address of your Raspberry Pi, type ifconfig in terminal and it will show IP address. My Raspberry Pi’s address is 192.168.0.103 so i will type 192.168.0.103:8000 and it will show webpage.
I have designed the PCB on KiCad.
Following is a link to the project folder of this project.
After designing the PCB’s, I generated the Gerber file needed for manufacturing of PCB.
You can download the Gerber file through following link
Now we have got the PCB design and it’s time to order the PCB’s. For that, you just have to go to PCBWay.com, and click on “QUOTE NOW” button.
PCBWay are also sponsor of this project. PCBWay is a China Shenzhen-based PCB manufacturer and PCB assembler. You can instantly get the quotation of your PCB and PCBA, you can also check the order fabrication and processing status online in your account panel with PCBWay. You can order a minimum of 5 PCBs for just $5.
Next Click on Quick-order PCB.
To get the PCB manufactured, upload the gerber file given in the PCB Design Step.
Then check the files and click on add to cart.
My PCBs took 2 days to get manufactured and arrived within a week using DHL delivery option. PCBs were well packed and the quality was really good.
Here is how it looks like after assembling everything.
If you have any questions, feel free to ask in comment section.