L298n Arduino Library

7,741

13

4

Posted in TechnologyArduino

Introduction: L298n Arduino Library

About: Short way,Everything Arduino,AVR... C++,C# and Basic. Full home automatization is my dream I love playing whith stuff that can kill you or fry you like in hell. If you want me to help you with various proje...

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.

Share

Recommendations

  • Microcontroller Contest

    Microcontroller Contest
  • Science of Cooking

    Science of Cooking
  • Spotless Contest

    Spotless Contest
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

4 Comments

hi i think this module no need library..

une précision

j'ai mis

A precision I put

analogWrite(ENA,500);au lieu de zero idem pour ENB

seul les moteurs ENA fonctionnent

Only ENA engines operate