Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Simon Munyua Mugo
Published

Arduino Customized L298M Dual Motor Driver Module

The project is a design of an LM298 Dual DC motor driver used to drive DC and stepper motors. It is a design done in KiCAD.

IntermediateFull instructions provided3 hours984
Arduino Customized L298M Dual Motor Driver Module

Things used in this project

Hardware components

SparkFun Full-Bridge Motor Driver Breakout - L298N
SparkFun Full-Bridge Motor Driver Breakout - L298N
×1
1N4007 – High Voltage, High Current Rated Diode
1N4007 – High Voltage, High Current Rated Diode
×8
Capacitor 1000 µF
Capacitor 1000 µF
×1
Ceramic Disc Capacitor, 0.1 µF
Ceramic Disc Capacitor, 0.1 µF
×1
Capacitor 10 µF
Capacitor 10 µF
×1
Resistor 1k ohm
Resistor 1k ohm
×1
LED (generic)
LED (generic)
×1
Terminal Block Interface, Terminal Block
Terminal Block Interface, Terminal Block
×1

Software apps and online services

KiCad
KiCad

Story

Read more

Schematics

schematic

Code

L298 Code

Arduino
/*  Arduino DC Motor Control - PWM | H-Bridge | L298N  -  Example 01

    by Dejan Nedelkovski, www.HowToMechatronics.com
*/

#define enA 9
#define in1 6
#define in2 7
#define button 4

int rotDirection = 0;
int pressed = false;

void setup() {
  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  pinMode(button, INPUT);
  // Set initial rotation direction
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
}

void loop() {
  int potValue = analogRead(A0); // Read potentiometer value
  int pwmOutput = map(potValue, 0, 1023, 0 , 255); // Map the potentiometer value from 0 to 255
  analogWrite(enA, pwmOutput); // Send PWM signal to L298N Enable pin

  // Read button - Debounce
  if (digitalRead(button) == true) {
    pressed = !pressed;
  }
  while (digitalRead(button) == true);
  delay(20);

  // If button is pressed - change rotation direction
  if (pressed == true  & rotDirection == 0) {
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);
    rotDirection = 1;
    delay(20);
  }
  // If button is pressed - change rotation direction
  if (pressed == false & rotDirection == 1) {
    digitalWrite(in1, LOW);
    digitalWrite(in2, HIGH);
    rotDirection = 0;
    delay(20);
  }
}

Credits

Simon Munyua Mugo
55 projects • 16 followers
Qualified Mechatronic Engineer and PCB Designer
Contact

Comments

Please log in or sign up to comment.