Raspberry Pi: Time-Controlled Robocar

So another simple and fun project! Here I’ve built a robocar that moves in forward direction for 4 sec and in backward direction for 4 sec.

Demo:

Things Required:

  1. Raspberry Pi (I’ve used Raspberry Pi 3)
  2. Keyboard
  3. Mouse
  4. HDMI Screen
  5. DC Motor (x4)
  6. External Power Supply
  7. Jumper wires
  8. Car Chassis
  9. Wheels(x4)
  10. L298N Motor Driver
  11. Batteries (1.5V) (x4)
  12. Battery holder

Reference Material:

  1. The link I followed: (LINK)

Code:

Note that the following code is in python!

View on/Download from Github: (LINK)

import RPi.GPIO as GPIO
from time import sleep

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)

en1= 2
in1= 3
in2= 4
en2= 14
in3= 15
in4= 18

GPIO.setup(en1, GPIO.OUT)
GPIO.setup(in1, GPIO.OUT)
GPIO.setup(in2, GPIO.OUT)
GPIO.setup(en2, GPIO.OUT)
GPIO.setup(in3, GPIO.OUT)
GPIO.setup(in4, GPIO.OUT)


pwm1= GPIO.PWM(en1, 100)
pwm2= GPIO.PWM(en2, 100)

pwm1.start(0)
pwm2.start(0)


while True:
    GPIO.output(in1, GPIO.LOW)
    GPIO.output(in2, GPIO.HIGH)
    GPIO.output(in3, GPIO.LOW)
    GPIO.output(in4, GPIO.HIGH)
    pwm1.ChangeDutyCycle(50)
    pwm2.ChangeDutyCycle(50)
    sleep(4)
    GPIO.output(in1, GPIO.HIGH)
    GPIO.output(in2, GPIO.LOW)
    GPIO.output(in3, GPIO.HIGH)
    GPIO.output(in4, GPIO.LOW)
    pwm1.ChangeDutyCycle(50)
    pwm2.ChangeDutyCycle(50)
    sleep(4)

Stay Tuned for upcoming posts on Raspberry Pi Projects! Want to be the first to know when a new and amazing post comes up?? Then feel free to subscribe!

Happy Learning!!

This image has an empty alt attribute; its file name is stay-tuned.gif

Leave a Reply

PHP JS HTML CSS BASH PYTHON CODE

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this:
search previous next tag category expand menu location phone mail time cart zoom edit close