How to build a Wireless Controlled 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

Raspberry PI:
https://www.raspberrypi.org/products/raspberry-pi-3-model-b-plus

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

 

Batteries:
https://robokits.co.in/batteries-chargers/samsung-premium-li-ion-battery/3.7v-samsung-li-ion-batteries/samsung-icr-18650-26j-2600mah-li-ion-rechargeable-cell-original

 

Jumper Wires:
https://robokits.co.in/arduino/jumpers-wires

 

HP HDMI to VGA:
https://store.hp.com/in-en/default/hp-hdmi-to-vga-adapter-h4f02aa.html

 

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()