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:

 

 

 

 

 

 

Downloads:

  1. Raspbian(OS): https://www.raspberrypi.org/downloads/raspbian/

  2. Etcher: https://www.balena.io/etcher/

Connections Diagrams

Advertisements

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

Advertisements