L298N Dual H-Bridge

The L298N Dual H-Bridge circuit is great for controlling motors for robotic applications. It accepts a wide range of power supply voltage, anywhere from 5V – 46V. In this guide we will show you the most basic implementation of the L298N (without speed control) with the raspberry pi to drive 4 motors in a sequential pattern.

PARTS:

RPI 3 – https://amzn.to/2VA9pQY
4 Amp Power Adapter – https://amzn.to/2CTptWu
16GB micro SD – https://amzn.to/2SFMwd3
6 x 1.5V AA Battery Holder: https://amzn.to/2LW10mq
5.5×2.1mm Male+Female DC Power Socket: https://amzn.to/2VA5ZNW
120 pcs jumper cable: https://ebay.to/2VAb9cY
L298N – 5 Pcs: https://amzn.to/2VycIIm
4WD Robot Car Chassis Kit: https://amzn.to/2SBVho9

SCHEMATIC:

CODE:

import RPi.GPIO as gpio
import time

def init():
 gpio.setmode(gpio.BCM)
 gpio.setup(17, gpio.OUT)
 gpio.setup(22, gpio.OUT)
 gpio.setup(23, gpio.OUT)
 gpio.setup(24, gpio.OUT)

def forward(sec):
 init()
 gpio.output(17, True)
 gpio.output(22, False)
 gpio.output(23, True) 
 gpio.output(24, False)
 time.sleep(sec)
 gpio.cleanup()

def reverse(sec):
 init()
 gpio.output(17, False)
 gpio.output(22, True)
 gpio.output(23, False) 
 gpio.output(24, True)
 time.sleep(sec)
 gpio.cleanup()

print "forward"
forward(4)
print "reverse"
reverse(2)