• 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

Controlling DC Motors with the L293D H-Bridge Chip

You are here: Home / Robotics Course / Controlling DC Motors with the L293D H-Bridge Chip

As we discussed previously, to control a DC motor with speed and direction, we need something more than to apply pulses of 5v. This is where our H-Bridge comes in, and one of the most popular is the L293D.

The L293D is reasonably cheap, easy to get a hold of, and is robust enough (600mA tolerant) for most of the projects you are going to do in the beginning. You are not going to win a professional heavy weight robot battle with this hardware, but you are going to learn a lot and have a lot of fun for the price!

L293D H-Bridge
L293D H-Bridge

This chip has 16 pins, 8 down each side. If you place it in your breadboard with the notch facing up, the left-hand side (pins 1 to 8, top to bottom) works as follows:

l293d
  1. “Enable” – This pin can be powered to turn off or on, or you can control speed with it too.
  2. Input Pin 1
  3. Output Pin 1
  4. Ground
  5. Ground
  6. Output Pin 2
  7. Input Pin 2
  8. VCC2, the motor supply (4.5V up to 36V, from your battery pack)

The pins have a matching set the other side, so you can run two motors with one chip. Either way you will also need to connect pin 16, VCC1, which is across from the pin 1 enable pin. That one powers the chip’s own logic and takes 5V from your Arduino. Keep the two supplies straight: 5V logic on pin 16, motor battery on pin 8, and all the grounds joined together.

Pay close attention to the “notch” in the L293D chip (Click to zoom in)

(The video that went with this lesson is no longer available.)

Code

In this example, using the serial monitor we enter f or r for forward and reverse, followed by a comma, then the speed. So if you want to go forward and fast, you would enter “f,200”.

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 popular L293D H-Bridge chip.

 Enter f or r, followed by a comma, then the speed (eg. 200)

 */
   

// input pins
int pin1 = 9;          // the pins the inputs are attached to
int pin2 = 6;

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

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

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

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

  // 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 Forward and Reverse with ServosCourse contentsNext Using Motor Drivers, Shields and Breakouts

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