How to build a Wireless Controlled Mobile Tank
Mobile Tank
Robots are the future. Before letting a robot control human, let us see how we can control a robot. We have started with very basic robot which is basically a tank, which is being controlled wirelessly by a keyboard. It’s a embedded program in python that is taking inputs from keyboard and sending signals to motors attached to tank. And the program is running on a small raspberry pi with raspbian os. Rest are connections that have been explained through a diagram in video.
We are controlling a DIY Mobile Tank Platform wirelessly using Raspberry Pi, L298n Motor Driver. We used the following hardware & Software Components:
-
Devastator Tank Mobile Robot Platform (Metal DC Gear Motor): https://www.dfrobot.com/product-1477.html
-
L298n Motor Driver: https://www.factoryforward.com/product/l298n-dual-h-bridge-dc-stepper-motor-driver-controller-board-module-arduino/
-
Croma Powerbank: https://www.croma.com/croma-ca0065-10400mah-power-bank-grey-/p/187144?gclid=EAIaIQobChMIv9SpqNa04gIVxA0rCh3ThQewEAQYAyABEgKXUPD_BwE
-
Battery Holder: https://robokits.co.in/batteries-chargers/battery-chargers/battery-holder-for-lithium-ion-18650-2-cell
-
Jumper Wires: https://robokits.co.in/arduino/jumpers-wires
-
Bluetooth Mouse: https://www.logitech.com/en-us/product/wireless-trackball-m570
Downloads:
-
Raspbian(OS): https://www.raspberrypi.org/downloads/raspbian/
-
Etcher: https://www.balena.io/etcher/
Connections Diagrams
Python Source Code for controlling the robot wirelessly
# import curses and GPIO
import curses
import RPi.GPIO as GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BOARD)
motor1a = 7
motor1b = 11
motor1e = 22
motor2a = 13
motor2b = 16
motor2e = 15
GPIO.setup(motor1a,GPIO.OUT)
GPIO.setup(motor1b,GPIO.OUT)
GPIO.setup(motor1e,GPIO.OUT)
GPIO.setup(motor2a,GPIO.OUT)
GPIO.setup(motor2b,GPIO.OUT)
GPIO.setup(motor2e,GPIO.OUT)
screen = curses.initscr()
curses.noecho()
curses.cbreak()
curses.halfdelay(3)
screen.keypad(True)
try:
while True:
char = screen.getch()
if char == ord('q'):
break
elif char == curses.KEY_UP:
GPIO.output(motor1a,GPIO.LOW)
GPIO.output(motor1b,GPIO.LOW)
GPIO.output(motor1e,GPIO.LOW)
GPIO.output(motor2a,GPIO.LOW)
GPIO.output(motor2b,GPIO.LOW)
GPIO.output(motor2e,GPIO.LOW)
GPIO.output(motor1a,GPIO.LOW) #MOTOR1
GPIO.output(motor2b,GPIO.LOW) #MOTOR2
GPIO.output(motor1e,GPIO.HIGH) #MOTOR1
GPIO.output(motor2e,GPIO.HIGH) #MOTOR1
GPIO.output(motor1b,GPIO.HIGH) #MOTOR2
GPIO.output(motor2a,GPIO.HIGH) #MOTOR2
elif char == curses.KEY_DOWN:
GPIO.output(motor1a,GPIO.LOW)
GPIO.output(motor1b,GPIO.LOW)
GPIO.output(motor1e,GPIO.LOW)
GPIO.output(motor2a,GPIO.LOW)
GPIO.output(motor2b,GPIO.LOW)
GPIO.output(motor2e,GPIO.LOW)
GPIO.output(motor2e,GPIO.LOW) #MOTOR1
GPIO.output(motor2a,GPIO.LOW) #MOTOR2
GPIO.output(motor1e,GPIO.HIGH) #MOTOR1
GPIO.output(motor1a,GPIO.HIGH) #MOTOR1
GPIO.output(motor1b,GPIO.HIGH) #MOTOR2
GPIO.output(motor2b,GPIO.HIGH) #MOTOR2
elif char == curses.KEY_RIGHT:
GPIO.output(motor1a,GPIO.LOW)
GPIO.output(motor1b,GPIO.LOW)
GPIO.output(motor1e,GPIO.LOW)
GPIO.output(motor2a,GPIO.LOW)
GPIO.output(motor2b,GPIO.LOW)
GPIO.output(motor2e,GPIO.LOW)
GPIO.output(motor1e,GPIO.HIGH) #MOTOR1
GPIO.output(motor2e,GPIO.HIGH) #MOTOR1
GPIO.output(motor1b,GPIO.HIGH) #MOTOR2
GPIO.output(motor2b,GPIO.HIGH) #MOTOR2
elif char == curses.KEY_LEFT:
GPIO.output(motor1a,GPIO.LOW)
GPIO.output(motor1b,GPIO.LOW)
GPIO.output(motor1e,GPIO.LOW)
GPIO.output(motor2a,GPIO.LOW)
GPIO.output(motor2b,GPIO.LOW)
GPIO.output(motor2e,GPIO.LOW)
GPIO.output(motor1e,GPIO.HIGH) #MOTOR1
GPIO.output(motor1a,GPIO.HIGH) #MOTOR1
GPIO.output(motor1b,GPIO.HIGH) #MOTOR2
GPIO.output(motor2a,GPIO.HIGH) #MOTOR2
elif char == 10:
GPIO.output(motor1a,GPIO.LOW)
GPIO.output(motor1b,GPIO.LOW)
GPIO.output(motor1e,GPIO.LOW)
GPIO.output(motor2a,GPIO.LOW)
GPIO.output(motor2b,GPIO.LOW)
GPIO.output(motor2e,GPIO.LOW)
finally:
curses.nocbreak(); screen.keypad(0); curses.echo()
curses.endwin()
GPIO.cleanup()