Today we will look at another H-Bridge motor controller. This one uses MOSFETs and is a great replacement for the L298N.

Follow along and learn how to use the TB6612FNG H-Bridge with your Arduino projects.


Controlling the speed and direction of DC motors is a very common application for both microcontrollers and microcomputers. You can probably think of many projects that you could build using these devices, from robots to cat toys.

But if you’ve ever tried connecting a DC motor directly to a microcontroller like an Arduino you’ll quickly find out that it isn’t feasible. Not only will it not work, as the Arduino cannot provide enough current for the motor, but you will also probably find yourself in the market for a new Arduino very soon!

TB6612FNG H-Bridge

DC motors require more current than any microcontroller or microcomputer can directly provide, and many of them operate on different voltages that your processor can’t deal with. So obviously some sort of interface is required.

The most common method of controlling a DC motor is to use a device called an H-Bridge. This type of controller allows you to control both the speed and direction of a DC motor, and a pair of H-Bridges can also be used to control a bipolar stepper motor.

We have used H-Bridges in many of our projects. They are relatively inexpensive and are pretty simple to work with.  And the most common H-Bridge we’ve used thus far is the L298N.

The L298N is a very common component and it is used in hundreds, if not thousands, of Arduino designs. It’s inexpensive and, once you understand how it works, is quite simple to use. But it does have its flaws, which I’ll go into in a minute.

Today we will work with a better H-Bridge, one that can replace the L298N in many applications.  It’s called a TB6612FNG and after using it I think you’ll agree that it is a much better choice than the old L298N.

H-Bridge Recap

Before we get started, it might be a good idea to recap how an H-Bridge works, just in case it’s still a mystery to you.

The following diagrams came from the article Controlling DC Motors with the L298N Dual H-Bridge and an Arduino that I wrote a few years ago. If you want a more in-depth explanation of DC motor and H-Bridge operation I would urge you to check it out.

You can visualize an H-Bridge as an arrangement of four switches. As you can see the switches are arranged in a pattern that looks a lot like the letter “H”. thus the name ”H-Bridge”.

H-Bridge Configuration

The motor is placed in the middle of the “H” as illustrated in the diagrams.  With the switches off the motor receives no current, as you would expect.

H-Bridge Counter-Clockwise

If we close a couple of switches, as illustrated above, you can see that the current is allowed to flow through the motor, causing it to rotate clockwise. Obviously you don’t want to close more than two switches at a time as doing so could cause a short circuit.

H-Bridge Clockwise

Closing the other two switches also applies current to the motor, but in the opposite polarity. This causes the motor to spin counterclockwise.

While you could construct an H-Bridge using physical switches it isn’t done very often. In most cases, the switches are replaced with semiconductors, like bipolar junction transistors (BJTs) and MOSFETs.

Replacing the switches with semiconductors has an additional advantage – it allows you to regulate the motor speed as well.

Pulse Width Modulation (PWM)

Pulse Width Modulation, or PWM, is essentially what it sounds like. A pulse is sent to the transistors controlling the H-Bridge, which turns the electronic “switch” off and on at a pretty rapid rate.

The width of the pulse can be changed to set the ratio of “on” versus “off”. This has the effect of controlling the speed of the motor.

PWM Diagram 1

PWM is a much better way of regulating the speed of a DC motor than just changing its supply voltage. With PWM the motor operates at full torque throughout the speed range, as opposed to the reduced torque you’d experience at lower speeds using voltage control.

TB66121FNG H-Bridge

Now let’s look at our “better” H-Bridge module.

The TB6612FNG H-Bridge is a small and inexpensive dual-channel H-Bridge controller that uses MOSFETs to achieve it’s great performance.

Made with MOSFETs

MOSFETs have an enormous advantage over bipolar junction transistors or BJTs. 

A typical BJT has a voltage drop of approximately 0.7 volts when it is “on”, and since an H-Bridge requires the current to pass through two BJTs the total voltage drop is 1.4 volts. At low voltages this can really make a difference, if you supply the H-Bridge with 6-volts then the output to the motor will only be 4.6-volts. In this example, almost 25% of the voltage is lost in the H-Bridge.

The energy from that voltage needs to go somewhere, and it does – it is dissipated as heat. This is why most BJT-based H-Bridges require a big heatsink.

With a MOSFET you don’t have a fixed voltage drop. Instead, the MOSFET has a very small resistance when it is on, typically a fraction of an ohm.  Even with two MOSFETs turned “on” in an H-Bridge design the total resistance is very low, in fact, if you’re using long thin-gauge wires for your power supply you may have more resistance in the wires than you do in the H-Bridge.

The result is an extremely low, almost negligible, voltage drop. This means that nearly all the voltage from the power supply is delivered to the motor.  And, with very little voltage drop to deal with, there is very little heat to dissipate. 

If you’d like to learn more about working with MOSFETs and Bipolar Junction Transistors please check out the article and video Arduino High-Current Interfacing – Transistors & MOSFETs.

TB6612FNG Specifications

The TB6612FNG has the following specifications (the specs are for each of the two H-Bridges in the package):

  • Motor supply voltage of 2.5 to 13.5 volts DC.
  • Logic supply voltage of 2.7 to 5.5 volts DC.
  • Output current of 1.2 amperes continuous, 3.2 amperes peak.
  • Built-in thermal shutdown.
  • Standby power mode.

This device is a surface-mount chip that is available in many common modules, shields for the Arduino and HATs for the Raspberry Pi.

The pinouts of a typical TB6612FNG module are illustrated below:

TB6612FNG Pinout

One thing to note about the module layout is that all of the input pins are on one side and all of the output and power pins are on the other side.  Notably absent from this dual H-Bridge module is a heatsink, although you can affix a small heatsink to the surface-mount chip if you desire.

Controlling the TB6612FNG

The TB6612FNG can be operated in four modes:

  1. Clockwise Rotation
  2. Counterclockwise Rotation
  3. Short Brake
  4. Stop

In order to control the H-bridge you use the AI1 (or on some models marked “AIN1”)  and AI2 (AIN2) pins for the Motor A output. The B input control leads are used in a similar fashion for the Motor B output.

The following table shows how this works:

Input 1 (AI1 or BI1) Input 2 (AI2 or BI2) Mode
HIGH HIGH Short Brake
HIGH  LOW Clockwise
LOW HIGH Counterclockwise

The PWMA and PWMB inputs are used to control the motor speed using Pulse Width Modulation.

One thing to note is that for the TB6612FGH to operate you must hold the Standby input HIGH.  You can tie it to VCC or use an output from your Arduino to control it.

A second noteworthy observation is that the Clockwise and Counterclockwise control signals are identical to the ones used in the popular L298N H-Bridge. This makes it pretty simple to use the TB6612FNG as a direct replacement in many situations.

TB6612 vs. L298N

The key phrase in the last paragraph is “In many situations”. There are some instances, such as higher voltage motors, where the TB6612FNG can’t be used. But for many designs, including ones using 6 and 12-volt motors, it is an ideal substitute that offers improved performance.

Take a look at the specifications of the TB6612FNG and the L298N viewed side-by-side.

TB6612FNG vs L298N

If you have a motor that requires over 13.5 volts then that eliminates the TB6612FNG. However, if your motor is a low-voltage (i.e. 3-volt) device then the L298N is out of the picture.

Although the L298N can handle almost twice the continuous current that the TB6612FNG does, it is about even when it comes to peak current, in fact the TB6612FNG has a slight edge.

But after that the TB6612FNG is the clear winner.

  • It is much smaller, in fact, most TB6612FNG modules are less than a quarter of the size of L298N modules.
  • No heatsink, making it even smaller. However, it is a good idea to allow some airflow around the device.
  • The efficiency is where the TB6612FNG really shines. There really is no contest here, something to strongly consider when building a battery-powered device.
  • Virtually all of your motor supply voltage will get to the motor when you use the TB6612FNG. The L298N will drop 1.4-volts, as it uses BJTs.
  • The TB6612FNG has a low-current standby mode that the L298N does not have.

I think that for my new designs I’ll be switching to the TB6612FNG. Even though I have a drawer full of L298N modules!

TB6612FNG with Arduino

Since the TB6612FNG uses a similar control arrangement to the L298N you can easily repurpose your old sketches to use the new controller. In fact, that’s exactly what I did for the first demo.

If you want to compare check out the “two motor with potentiometers” experiment in my article about the L298N.  You should definitely see the similarities between the two.

TB6612FNG Hookup

For this experiment you will need the following components:

  • An Arduino, I used an Arduino Uno but any Arduino will work.
  • Two potentiometers to control speed. I used 10K linear pots, any linear pot with a value over 5K will suffice.
  • A TB6612FNG dual H-Bridge motor controller.
  • Two small DC motors. I used two 6-volt motors, the yellow ones you get with those small robot car kits.
  • A power supply for the motors. As I used 6-volt motors my supply was 6-volts, consisting of 4 type AA batteries.

The hookup is as follows:

TB6612FNG Arduino Hookup

Use the table on the side of the hookup diagram to connect the TB6612FNG to the Arduino. And remember to tie the STBY (Standby) lead to +5-volts, or nothing will work.

TB6612FNG Arduino Sketch

After you hook up everything you’ll need to run a sketch to get it going. The following sketch should do the trick:

It’s a very simple sketch, and if you took a peek at the “2 potentiometers” sketch in the L298N article you’ll see it’s virtually identical.

We begin by defining variables that represent the Arduino pins we’ve connected our TB6612FNG motor controller to, the IN1 and IN2 pins as well as the PWM pins.

Next, we define variables to represent the analog connections to the potentiometers, as well as variables for the motor speed.

In the Setup, we simply define all of our pins as outputs, and then we move into the Loop.

We start the Loop by setting the direction of the two motors. If you wish you can use the table above to reverse the direction of one or both motors.

Next, we read the value from the two potentiometers, and as this value will range from 0 to 1023 we use the Map function to change the range to 0-255.

Finally, we use the analogWrite function, which produces PWM, to write out PWM pulses to the motor controllers, thus setting their speed.


Load the sketch up to your Arduino, connect the motor power supply and play with the two potentiometers. You should be able to control the motor speed with them.

TB6612FNG Robot Car Base

For our final experiment with the TB6612FNG, I’ll be using the TB6612FNG H-Bridge to drive the motors in a small robot car. 

You could actually have used the last experiment to do exactly this, controlling the motors with the two potentiometers. But this time I want to do the programming a bit differently.

This time we will use a library.

Sparkfun Library for TN6612FNG

Sparkfun has released a library made specifically for the TN6612FNG, which you can download from GitHub

This library simplifies using the motor controller. It provides functions to move the motor at any speed and in both directions, as well as functions to brake and stop.

And, as a bonus, the Sparkfun library comes with an example sketch that is perfect for our robot car. In fact, I only needed to modify one line to get it working.

Robot Car Hookup

I used one of those popular acrylic Robot Car kits, the ones you can easily get on eBay or Amazon for 10 – 20 dollars. These kits come with a base, a couple of motors, some matching wheels, a battery holder and all of the hardware you need to put it together.

The electrical hookup of our robot car is very similar to the hookup we just used. The connections between the Arduino and the TB6612FNG are identical, with the addition of a connection from the Arduino to the Standby pin.  And I’ve removed the two potentiometers.

TB6612FNG Arduino Car Hookup

I’m still using the four AA cells to power the motors, and I used a 9-volt battery for the Arduino. Another great choice for powering the Arduino would be to use a USB power bank.

In my case I kept the wiring on the solderless breadboard and only used a single standoff to hold the Arduin. As a result I believe I created the world’s ugliest robot car! 

You can do MUCH better by wiring everything permanently and properly mounting and balancing the Arduino and battery holders. In my case the unit was out of balance, so I attached a small C-clamp to add a bit of weight in the back!

Robot Car Sketch

Before you can run the robot car sketch you’ll need to install the Sparkfun Library. The easiest way to do that is to download the library as a zip file.  Save it somewhere on your computer where you can find it later, your Downloads folder is an obvious place.

Now open your Arduino IDE and click on the Sketch menu item at the top of the page. Select Include Library, this will open up a sub-menu.

In the sub-menu the second item from the top will be Add ZIP Library. Select that and a dialog box will open. Use the dialog box to navigate to the location you saved your library ZIP file and select it.

The library will be installed, along with the sample sketch.

To run the sample sketch in your Arduino IDE you need to select the File menu from the top, and then Examples. This will bring up a sub-menu. Scroll down the sub-menu until you see Examples from Custom Libraries, near the bottom. Below that you will see an alphabetical list of examples. Look for the Sparkfun TB6612FNG Motor Library and select it.

There is only one example sketch included with the library called MotorTestRun. Open that sketch, it’s the one we will use for our robot car.

If you hooked up the Arduino and TB6612FNG as per the drawing above there is one change you will need to make to the sketch, this is because Sparkfun didn’t use the same Arduino pins as I did for the hookup.

Sparkfun used pin 2 for the AIN1 (AI1) connection whereas I used pin 3. So you can handle this two ways:

  • Change line 28 of the sketch to read #define AIN1 3. This is the way I handled the difference.
  • Keep the sketch as-is and just change the connection from pin 3 to pin 2.

Here is the sketch, modified to use pin 3.

Using the Sparkfun library makes working with the TN6612FNG very simple. After defining all of the motor controller connections we setup two objects, one for each motor, named motor1 and motor2. Note how all the motor parameters are passed when creating the objects.

No need for anything in the Setup as the library takes care of defining the pins as outputs.

The Loop is essentially a demonstration of the functions the library provides. It is very well documented so you should have no problem adapting it to your needs.  The functions include:

  • Drive – This function sets the speed and direction of the motor (you apply it individually to each motor). You pass it the speed as either a positive or negative number, a negative number causes the motor to spin in the opposite direction. You may also specify the duration in milliseconds that you wish the motor to operate.
  • Forward – This function allows you to drive both motors in a forward direction. It takes the speed as an optional parameter. Again a negative speed can be used, which will cause the motor to go backward.
  • Back – As you might suspect this is the opposite of Forward.
  • Brake – This stops the motor(s). If you didn’t specify a duration for the previous commands then you’ll need to use this to bring the robot to a halt.
  • Left – This takes both motors as parameters and causes the robot to turn left. It also uses the speed as a parameter.
  • Right – The opposite of Left of course!

The code in the Loop just exercises the robot car using a number of these functions. It actually is designed to have the car end up in the same place, but my ugly robot car is so unbalanced it never had a chance of doing that.  Perhaps you’ll do better with your car!

TB6612FNG Robot Car

You can experiment with the code and change or add more functions to control your car.


The TB6612FNG is an inexpensive dual H-Bridge motor controller that is easy to use and that can directly rep[lace the L298N in many applications.  It’s small size and low heat dissipation makes it ideal for small robot cars and other battery-powered equipment.

You’ll be seeing a lot more of this little board in future projects.  And if you know anyone who needs a drawer full of L298N’s please let me know!

TB6612FNG H-Bridge with Arduino – Better Than L298N?
TB6612FNG H-Bridge with Arduino - Better Than L298N?
Article Name
TB6612FNG H-Bridge with Arduino - Better Than L298N?
The TB6612FNG is a MOSFET-based dual-channel H-Bridge which has a number of performance advantages over the popular L298N. Today we will see how to use this versatile device. We will even build the world's ugliest robot car with it!
Publisher Name
Dronebot Workshop
Publisher Logo

If you have a question...

Comments about this article are encouraged and appreciated. However, due to the large volume of comments that I receive, it may not be possible for me to answer you directly here on the website.

You are much more likely to get answers to technical questions by making a post on the DroneBot Workshop Forum. Your post will be seen not only by myself, but by a large group of tech enthusiasts who can quickly answer your question. You may also add code samples, images and videos to your forum posts.

Having said that, please feel free to leave constructive comments here. Your input is always welcome. Please note that all comments may be held for moderation.

Newest Most Voted
Inline Feedbacks
View all comments
Mouka Zwina
1 year ago

What software did you use to illustrate how the wiring to the Arduino is done?

Erik Peterson
9 months ago

Really appreciate the complete explanation and perspective. Very helpful to compare with LN298N both pros and cons. Thanks!

Shreekant Patel
8 months ago

Dear sir,
NC is mentioned on my tb6612fng instead of pwmA,pwmB and vcc.
Is it same? I’m trying it with my Nano and its not working.
Does l329d shield will work with Nano? To drive 4 motors.
Thank you.

Greg Bloor
3 months ago

Looking from top Orange chip towards you


NC PWMB Pin 6 B01 To motor

Bin2 Pin 8 B01 To motor

Bin1 Pin 7 A02 To motor

Stdby Pin 9 A01 To motor

Ain1 Pin 2 GND Ground

Ain2 Pin 4 NC VCC to Microcontroller

NC PWMA Pin 5 VM Power Source

6 months ago

Shouldn’t the GPIOs be defined as output at the setup()?

4 months ago

I really enjoy all great DroneBot Workshop tutorials. They are so well-written with detailed instructions and photos. Thank you very much for being such a wonderful educational resource.

Ian Avery
1 month ago

Very clear project, worked perfectly for me

1 month ago

Thanks again for pulling me out of my problem. Your workshops are so well done.

Peter Hailes
13 days ago

Is it possible to use a “for” loop to control and vary the speed of TB6612 ( as in L298n) instead of writing a set PWM speed.?

IE for(int i=0, i<200, i++)
analogWrite(enA, i);

I can’t make this work!

Many thanks

Would love your thoughts, please comment.x