Remote CCTV Surveillance Robot using Raspberry Pi 3
WiFi WiFi Everywhere… Why not play with it? In this tutorial will show you to develop a python based wireless robot which can be controlled from anywhere around the world using Wifi.
Watch this Demo First
About Raspberry Pi
This tiny computer is a precious tool for students, artists, and of course hobbyists and hackers. With features for developing things in different areas, it is not a surprise to have hundreds of thousands if not millions of users.
Pi and Python
Python is a wonderful and powerful programming language that’s easy to use (easy to read and write) and with Raspberry Pi lets you connect your project to the real world.Python syntax is very clean, with an emphasis on readability and uses standard English keywords.
Physical computing is one of the most engaging activities, and it’s at the heart of most projects we see in the community. From flashing lights to IoT smart homes, the Pi’s GPIO pins make programming objects in the real world accessible to everybody.
The H Bridge
An H bridge is an electronic circuit that enables a voltage to be applied across a load in either direction. These circuits are often used in robotics and other applications to allow DC motors to run forwards or backwards.
Most DC-to-AC converters (power inverters), most AC/AC converters, the DC-to-DC push–pull converter, most motor controllers, and many other kinds of power electronics use H bridges. In particular, a bipolar stepper motor is almost invariably driven by a motor controller containing two H bridges.
A DC motor has two terminals. When we apply a potential difference across the two, It will rotate in one direction. If we reverse the polarity, It will rotate in anticlockwise direction. To reverse a DC motor, you need to be able to reverse the direction of the current in the motor. The easiest way to do this is using an H-bridge circuit. There are many different models and brands of H-Bridge. This tutorial uses one of the most basic, a Texas Instruments L293NE.
Here, I will Give you a Basic Idea on How to setup things.The rest is up to you. Everything is limited by your imagination only.
Setup a Chasis
Build a chasis, whichever design you like, that have enough space to carry our Raspberry Pi, Motor Driver Board, Regulator Circuit and the Lithium Polymer Battery.
You can use either Foam Board Base or Aluminum Base.
The Regulator
The Power input for Raspberry Pi and working for l298n Internal circuit is 5V and the voltage needed for driving the motor is 11 V ( up to 32 V).
And so we have to make sure that the voltage we are providing the Raspberry pi is not more than 5.5 V. Otherwise it may burn the Board.
Watch This video to set one yourself.
Network
In this project I will be using wifi connection to control this robot. In raspberry pi You can use any OS that supports Python GPIO library. I am Using Kali Linux. But for beginners, I recommend Raspbian OS.[AdSense-A]
Once you install everything, you have to setup network connection. In Raspberry Pi 3 there is a n inbuilt Broadcom Wifi Adapter. If you are using previous versions, you will have to connect an external USB Wifi Adapter. Connect the Pi to you Network. It is better to provide a static IP address for the Pi. Next you will have to enable and setup SSH on your pi.Test your connection by connecting to your Raspberry Pi from another Device.
GPIO
The Curses
Write a script to capture keystroke. I used pythons curses library to do the same. Using that we can easily control the bot from the terminal itself.
Roll Out
Next thing to do is Driving the motor. Each L293N IC can Drive two motors independently. Configure 4 pins (or 6 pins if enable pins are counted) as Output Pins. Give
appropriate output signals to the Motor Driver board and make make sure that the enable pins of the driver board is active high. Otherwise it wont work.[AdSense-C]
The Code
import curses
# Get the curses window, turn off echoing of keyboard to screen, turn on
# instant (no waiting) key response, and use special values for cursor keys
screen = curses.initscr()
curses.noecho()
curses.cbreak()
screen.keypad(True)
try:
while True:
char = screen.getch()
if char == ord(‘q’):
break
elif char == curses.KEY_UP:
print “up”
elif char == curses.KEY_DOWN:
print “down”
elif char == curses.KEY_RIGHT:
print “right”
elif char == curses.KEY_LEFT:
print “left”
elif char == 10:
print “stop”
finally:
#Close down curses properly, inc turn echo back on!
curses.nocbreak();
screen.keypad(0);
curses.echo()
curses.endwin()
Set Up a Camera (Optional)
For controlling the bot remotely You may have to use a camera to drive it. Camera modules for raspberry pi are available online. Or you could use a USB camera. Buy one and set it up. Install motion and start live streaming through browser.
Once Everything is setup, combine all the scripts in a single python file. I will update my code here. Try to write everything as functions. Its much easier to call the functions than to write everything once again, when the code grows.[AdSense-C]
Now, for a fresh start, power off your pi. Assemble everything on the chassis, tighten all the connection, connect your pi and Power on the Bot.
Connect it via SSH and run the script and there you GO..