Pi cart using Raspberry pi 3 and L298d


       Pi Cart



  Material Needed

  • Raspberry pi 3           
  • L298d motor drivers
  • Edup usb wifi
  • Connecting wires 
  • Wheels and Cart chassie    
  • 4 battery 1.5v and Power bank

  Links to buy Componets    

  Circuit Diagram



  • First Assemble the Cart according to circuit.
  • Then write the program inside raspberry pi using text editor,execute using terminal. Mainly program is write in python script sample program is included below.Save the program in .py extension and execute using command $python sample.py
  • Use wifi to execute program using remote desktop in windows.Using xrdp and remote desktop configuration.
  • Connect IN1,IN2,IN3,IN4 corresponding to GPIO pin 11,15,16,17 

    Sample codes 

Forward

       
# Import required libraries
import sys
import time
import RPi.GPIO as GPIO

# Use BCM GPIO references
# instead of physical pin numbers
#GPIO.setmode(GPIO.BCM)

mode=GPIO.getmode()
print " mode ="+str(mode)
GPIO.cleanup()

# Define GPIO signals to use
# Physical pins 11,15,16,18

IN1=11
IN2=15
IN3=16
IN4=18

GPIO.setmode(GPIO.BOARD)
GPIO.setup(IN1, GPIO.OUT)
GPIO.setup(IN2, GPIO.OUT)
GPIO.setup(IN3, GPIO.OUT)
GPIO.setup(IN4, GPIO.OUT)

def forward(x):
    GPIO.output(IN1, GPIO.HIGH)
    GPIO.output(IN3, GPIO.HIGH)
    print "forwarding running  motor "
    time.sleep(x)
    GPIO.output(IN1, GPIO.LOW)
    GPIO.output(IN3, GPIO.LOW)

print"forward"
forward(10)
#time in sec

print "Stopping motor"
GPIO.cleanup()

       

Reverse

       
 # Import required libraries
import sys
import time
import RPi.GPIO as GPIO

# Use BCM GPIO references
# instead of physical pin numbers
#GPIO.setmode(GPIO.BCM)

mode=GPIO.getmode()
print " mode ="+str(mode)
GPIO.cleanup()

# Define GPIO signals to use
# Physical pins 11,15,16,18

IN1=11
IN2=15
IN3=16
IN4=18

GPIO.setmode(GPIO.BOARD)
GPIO.setup(IN1, GPIO.OUT)
GPIO.setup(IN2, GPIO.OUT)
GPIO.setup(IN3, GPIO.OUT)
GPIO.setup(IN4, GPIO.OUT)

def reverse(x):
    GPIO.output(IN2, GPIO.HIGH)
    GPIO.output(IN4, GPIO.HIGH)
    print "backwarding running motor"
    time.sleep(x)
    GPIO.output(IN2, GPIO.LOW)
    GPIO.output(IN4, GPIO.LOW)

print "reverse"
reverse(40)


print "Stopping motor"
GPIO.cleanup()

       
 

Left,Right

       
# Import required libraries
import sys
import time
import RPi.GPIO as GPIO

# Use BCM GPIO references
# instead of physical pin numbers
#GPIO.setmode(GPIO.BCM)

mode=GPIO.getmode()
print " mode ="+str(mode)
GPIO.cleanup()

# Define GPIO signals to use
# Physical pins 11,15,16,18

IN1=11
IN2=15
IN3=16
IN4=18

GPIO.setmode(GPIO.BOARD)
GPIO.setup(IN1, GPIO.OUT)
GPIO.setup(IN2, GPIO.OUT)
GPIO.setup(IN3, GPIO.OUT)
GPIO.setup(IN4, GPIO.OUT)

def right(x):
    GPIO.output(IN2, GPIO.HIGH)
    GPIO.output(IN3, GPIO.HIGH)
    print "Righting running  motor "
    time.sleep(x)
    GPIO.output(IN2, GPIO.LOW)
    GPIO.output(IN3, GPIO.LOW)

def left(x):
    GPIO.output(IN1, GPIO.HIGH)
    GPIO.output(IN4, GPIO.HIGH)
    print "lefting running motor"
    time.sleep(x)
    GPIO.output(IN1, GPIO.LOW)
    GPIO.output(IN4, GPIO.LOW)


print "left"
left(20)
 
print "Right"
right(20)


print "Stopping motor"
GPIO.cleanup()
       
 

Comments

Popular posts from this blog

What is GPIO pins in Raspberry Pi ?

What is Raspberry Pi ?