Raspberry Pi Control Remote Toy Car
by murphypoon in Circuits > Raspberry Pi
1232 Views, 7 Favorites, 0 Comments
Raspberry Pi Control Remote Toy Car
Raspberry Pi Control Remote Toy Car
Hardware :
1 . Raspberry Pi B+ or Higher
2. (4) 2N3904 NPN (EBC) Q6
3. (8) 10K Resisters
4. (4) 1K Resisters
5 (4) LED Light (Any Color)
How to Make ?
See above Photos
Pin Connect
Raspberry Pi -- Control Circuit -- Remote
GPIO 17 -- Circuit A -- LEFT
GPIO 27 -- Circuit B -- RIGHT
GPIO 22 -- Circuit C -- Forward
GPIO 23-- Circuit D -- Backward
Simple Python Test
This simple test is to control GPIO 4 ON and OFF, you have to connect to Forward Pin on Toy Car Remote before RUN
$ sudo nano simpletest.py
<pre><p><strong>import</strong> time</p><p><strong>import</strong> RPi.GPIO <strong>as</strong> io</p><p>io.setmode(io.BOARD)</p><p>pir_pin = 7</p><p>io.setup(pir_pin, io.OUT)</p><p><strong>while</strong> True:</p><p> io.output(pir_pin, io.HIGH)</p><p> <strong>print</strong>(<strong>"Forward On"</strong>)</p><p> time.sleep(3)</p><p> io.output(pir_pin, io.LOW)</p><p> <strong>print</strong>(<strong>"Forward OFF"</strong>)</p><p> time.sleep(3)</p>
Complete Script
$sudo nano toycarremote.py
<p>import time <br>import RPi.GPIO as gpio </p><p>class ToyCarRemote: def __init__(self, forward_pin=11, backward_pin=13, left_pin=15, right_pin=16, test_pin=7): #gpio.setmode(gpio.BCM) #test_pin = 4 # GPIO 4 #forward_pin = 17 # (GPIO 17) #backward_pin = 27 # GPIO 27 #left_pin = 22 # GPIO 22 #right_pin = 23 # GPIO 24</p><p> self.test_pin=test_pin self.forward_pin=forward_pin self.backward_pin=backward_pin self.left_pin=left_pin self.right_pin=right_pin</p><p> gpio.setmode(gpio.BOARD) test_pin = 7 # GPIO 4 forward_pin = 11 # (GPIO 17) backward_pin = 13 # GPIO 27 left_pin = 15 # GPIO 22 right_pin = 16 # GPIO 23</p><p> gpio.setup(self.test_pin, gpio.OUT) gpio.setup(self.forward_pin, gpio.OUT) gpio.setup(self.backward_pin, gpio.OUT) gpio.setup(self.left_pin, gpio.OUT) gpio.setup(self.right_pin, gpio.OUT)</p><p> gpio.output(self.forward_pin, gpio.LOW) gpio.output(self.backward_pin, gpio.LOW) gpio.output(self.left_pin, gpio.LOW) gpio.output(self.right_pin, gpio.LOW) </p><p> def clearAll(self): gpio.output(self.forward_pin, gpio.LOW) gpio.output(self.backward_pin, gpio.LOW) gpio.output(self.left_pin, gpio.LOW) gpio.output(self.right_pin, gpio.LOW) </p><p> def updown(self, direction, OnOff, tsecond): # direction F:forward , B:Backward if direction in ('F'): gpio.output(self.backward_pin, gpio.LOW) gpio.output(self.forward_pin, OnOff) if direction in ('B'): gpio.output(self.forward_pin, gpio.LOW) gpio.output(self.backward_pin, OnOff) time.sleep(tsecond)</p><p> def leftright(self, direction, OnOff, tsecond): # direction L:left , R:Right if direction in ('L'): gpio.output(self.right_pin, gpio.LOW) gpio.output(self.left_pin, OnOff) if direction in ('R'): gpio.output(self.left_pin, gpio.LOW) gpio.output(self.right_pin, OnOff) time.sleep(tsecond)</p><p>#try: # while True: # gpio.output(test_pin, gpio.HIGH) # #except KeyboardInterrupt: # gpio.cleanup()</p><p>if __name__ == '__main__': tcr = ToyCarRemote() for i in range(20): print('\n', 'Loop : ', i) print 'Forward 2 Second' tcr.updown('F', gpio.HIGH , 0) tcr.leftright('L', gpio.HIGH, 0) time.sleep(2) tcr.clearAll() print 'Stop Forward' tcr.updown('B', gpio.HIGH, 0) time.sleep(2) tcr.clearAll()</p>
More Information : iMediaBank - http://www.imediabank.com