Fouad
Published

DC Motors Control Using Arduino PWM with L298N H-Bridge

In this tutorial i'm going to show you how to control the speed and direction of two DC motors by the most common method PWM signals.

IntermediateFull instructions provided91,872
DC Motors Control Using Arduino PWM with L298N H-Bridge

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Dual H-Bridge motor drivers L298
SparkFun Dual H-Bridge motor drivers L298
×1
DC Motor, Miniature
DC Motor, Miniature
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Servo Motor, Premium Male/Male Jumper Wires
Servo Motor, Premium Male/Male Jumper Wires
Premium Female/Male 'Extension' Jumper Wires, 40 x 3" (75mm)
Premium Female/Male 'Extension' Jumper Wires, 40 x 3" (75mm)

Story

Read more

Custom parts and enclosures

Components Required

Schematics

L298N

Connections

Code

L298N.ino

Arduino
const int IN1 = 7;
const int IN2 = 6;
const int IN3 = 5;
const int IN4 = 4;
const int ENA = 9;
const int ENB = 3;


void setup() {

  pinMode (IN1, OUTPUT);
  pinMode (IN2, OUTPUT);
  pinMode (IN3, OUTPUT);
  pinMode (IN4, OUTPUT);
  pinMode (ENA, OUTPUT);
  pinMode (ENB, OUTPUT);

}

void loop() {
//control speed 
  analogWrite(ENA, 255);
  analogWrite(ENB, 255); 
//control direction 
  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, LOW);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, LOW);
  
  

}

Credits

Fouad

Fouad

1 project • 9 followers

Comments