L298n Arduino Library

by Ivica_Matic in Circuits > Arduino

25764 Views, 20 Favorites, 0 Comments

L298n Arduino Library

maxresdefault.jpg

The L298n is a simple dual channel motor controler for Arduino.Featuring functions like direction change and PWM
speed control makes it easy and fun to use.And it is cheap,realy cheap.
You can get it on ebay for as low as 2$

But it is hard to find a good library for it,so i made one.
Download link https://drive.google.com/open?id=0Bxra0Xe0UREkZWdSZ2ExUGVEN3M

All you need to do is download the .h file and include it in your arduino sketch using:

#include "l298n_lib.h"

In setup part you need to initialize pins used to connect module and arduino:

set_pins (IN1,IN2,IN3,IN4,enableA,enableB);

enable pins must be pwm pins

example;

set_pins(2,3,4,5,9,11);

To controll motors in loop part of code you can write following commands:

dmot('F',127)....dmot means right motor,F is for Forward and 127 is pwm speed,can range from 0 to 255
lmot('B',127)...lmot means left motor,B is for Backward and 127 is pwm speed,can range from 0 to 255

And you can stop motors by:

dmot_stop();
lmot_stop():

Using this commands whith some serial communication and case statements can yield a very nice RC wireless car,the exaple will be included in file.

If you have read all to this point,thank you.

Follow me on twitter @ivica3730k

Have fun and have a nice day.