• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
  • YouTube
  • MakerWorld
  • Instagram
  • Threads
  • Bluesky
  • Mastodon
  • Facebook
makerhacks-logo

Maker Hacks

Ideas, news & tutorials for makers and hackers – Arduino/Raspberry Pi, 3D printing, robotics, laser cutting, and more

  • Home
  • About
  • 3D Printing
  • Laser Cutting
  • CNC
  • Programming
  • Free Arduino Course
  • Free Robotics Course
  • Recommendations

L298N Breakouts

You are here: Home / Robotics Course / L298N Breakouts

You might find the code below familiar! That’s because the code to drive a breakout is very similar to driving the chip.

Really the board is just an easier and more convenient way of working with the L298N chip.

The motor battery goes to the screw terminal marked 12V (it is happy with anything from about 6V up to 12V), and its ground to GND, along with a wire back to your Arduino’s GND so they share a ground. Leave the 5V jumper in place: the board then makes its own 5V for its logic, and the terminal marked 5V is an output, not where the battery goes. We also have two control pins, to direct if forward or backward, and the Enable pin where we can set speed.

Click to zoom

You can plug the grounds into the breadboard, or you can add both the power ground and the ground from your Arduino into the motor driver ground input, just ensure the grounds are connected.

As before, we can make the motor run forward or backward using serial input.

Enter the direction and speed with no spaces, just a comma to separate. Ensure your baud rate is set to 115,200, and you are sending NL & CR:

Code

Serial Monitor settings: in the Arduino IDE, open the Serial Monitor, set the speed to 115200 baud and the line ending to “Carriage return”, then type f or r, a comma and a speed from 0 to 255, such as f,200, and press Enter.

/*

 In this sketch we control a motor using
 the L298N H-Bridge breakout.

 We use pins 4, 5 and 3 for this example.

 */ 


// input pins
// these control direction
int pin1 = 4; 
int pin2 = 5;

// set on/off and speed
int enablepin = 3;

// how much power to send
int power = 0; 

// set things up ...
void setup() {

 // start the serial connection
 Serial.begin(115200);

 // tell us we are starting
 Serial.println("Starting ...");

 // declare both pins to be output:
 pinMode(pin1, OUTPUT);
 pinMode(pin2, OUTPUT);

 // enable pin is also output
 pinMode(enablepin, OUTPUT);

}

// keep doing this forever:
void loop() {

 // play with the power setting to see
 // the effects
 while (Serial.available() > 0) {

 // F or R
 String direction = Serial.readStringUntil(',');
 direction.trim(); // ignore any stray newline from the Serial Monitor

 // look for the next power number in the serial monitor
 // turn it into an integer and place in our power variable:
 int power = Serial.parseInt();
 
 // look for the carriage return (Enter)
 if (Serial.read() == '\r') {

 // report back the number we were provided:
 Serial.print(power);
 
 if(direction == "f") {
 digitalWrite(pin1, LOW);
 digitalWrite(pin2, HIGH);

 // set the speed
 analogWrite(enablepin, power);

 
 } else {
 digitalWrite(pin1, HIGH);
 digitalWrite(pin2, LOW);
 
 // set the speed
 analogWrite(enablepin, power);
 }

 
 // output text to say we got it
 Serial.println(" - Roger!");
 }
 }
}
Previous Stepper DriversCourse contentsNext Changing Direction with Tank Turning – L298n Breakout and Two Motors

Robot Course Lessons

  • Introduction
  • Choosing a Brain for your robot
  • Motors and Actuators
  • Basic Motor Controllers
  • Sensors
  • Breadboards, Batteries, Chassis, Wheels and Wires
  • Introduction
  • Basic DC Motor Movement
  • Forward and Reverse with Servos
  • Controlling DC Motors with the L293D H-Bridge Chip
  • Using Motor Drivers, Shields and Breakouts
  • Stepper Drivers
  • L298N Breakouts
  • Changing Direction with Tank Turning – L298n Breakout and Two Motors
  • Infrared Sensor
  • IR Remote Control
  • Robot Chassis
Creative Commons Attribution-ShareAlike 4.0 licence

Free to use, adapt and share. This course by Chris Garrett, Maker Hacks, is licensed under Creative Commons Attribution-ShareAlike 4.0. Workshops, schools and clubs are welcome to use it, including in your own handouts and sessions. Just credit “Chris Garrett, Maker Hacks (makerhacks.com)” with a link to the lesson, and share any adapted versions under the same licence. Embedded videos and other people’s content keep their own terms.

Improved a lesson or spotted a mistake? I would love to hear about it: get in touch.

  • 3D Printing
  • CNC
  • Electronics and Hardware
  • Laser Cutting
  • News and Reviews
  • Software and Programming

arduino budget cad cnc diode laser glowforge Hacks Ideas laser cutter linux Makes making python raspberry pi resin Reviews technology tips xTool Lasers

  • YouTube
  • MakerWorld
  • Instagram
  • Threads
  • Bluesky
  • Mastodon
  • Facebook

.

Maker Hacks Blog Copyright © 2026 · All Rights Reserved · Privacy Policy