Now that we have learned how to make a simple bot and a not-so-simple bot involving a mechanical slider crank, let us add something new to our repertoir. In this project we are going to be using a special type of circuit called an H-bridge to change motor direction. Changing motor direction is one of the most important aspects of robotic electromechanical control. It allows you to move something in one direction, and then reverse that action and move it back to where it came from.

This bot uses the most crude version of an H-bridge, which is basically a mechanical switch. As the legs of the robot are rotated by the motor, it flicks the switch back and forth and continually flips the motors direction. Basically, the motor is flicking it's own direction switch back and forth continually. In robotics, you will not find much more basic motor direction control than this.


To build this project you will need:

(x1) continuous rotation servo modified for direct drive**
(x1) 3 x AA battery holder
(x1) DPDT toggle switch
(x4) scrub brushes
(x1) small plastic container
(x1) ballpoint pen
(x1) 1-1/2" x 3/8" corner brace
(x1) assorted zip ties

**The modification of the motor is covered in steps 13 through 17 of the Basic Electronics Skills for Robotics lesson.

Types of Switches

However, before we get into the build, let's take a moment to understand switches. This is crucial knowledge for creating the H-bridge used to move this bot's brush legs back and forth.

There are many types of switches. You can find switches with levers, buttons, arms, keys, dials, and numerous other mechanisms. In this class we will be largely using lever switches. This type of switch has a little knob that can be toggled back and forth. You likely have encountered these before numerous times.

While toggle switches all more or less look the same, and have roughly the same functionality, their capabilities do differ. Switches have what are called "poles" and "throws."

You can think of poles as inputs into the switch. A switch with a single pole has one input. A switch with a double pole has two inputs. At that, each input is its own seperate circuit. The poles never connect with one another inside the switch.

Throws, on the other hand, are outputs. They are the terminals the pole (input) gets connected to when the switch lever is toggled. For instance, in a switch with a single pole and single throw (SPST), there is only one connection that can be made. When the switch is toggled, a connection is made or a connection is broken. Basically, it is either on or off.

On the other hand, a single pole switch with a double throw (SPDT) has no off position. When one connection isn't being made, a different one is. It basically toggles between two different connections.

Given all of that, a switch with double poles and double throws (DPDT) is basically two seperate pairs of SPDT switches in a single package. When the switch is toggled, the connections switch between two sets of different connections.

H-Bridge Basics

An H-bridge is a circuit that allows a motor's direction to be reversed. More advanced H-bridges - like the kind found inside of servo motors - also allow you to control the speed of the motor.

Essentially, an H-bridge consists of four switches. There is a switch between each pole of the motor and ground. There is also another set of switches between each pole of the motor and power.

When these switches are drawn out in a diagram, they look kind of like an “H”. That is how the circuit gets the name H-bridge.

The H-bridge consists of two sets of switches. When the set of switches labeled with “A” is closed, power flows through the motor in such a way that it spins clockwise.

When the other “B” set is closed, power flows the opposite direction and the motor spins counterclockwise.

However, both sets cannot be closed at the same time, or power and ground will be directly connected, and you will have a short circuit.

As well, if you mix and match the switches such as closing A1 and B2, you will also create a short circuit. It is important that either the “A” switches get closed or the “B” switches. Never both or some combination thereof.

Wiring an H-Bridge Switch

WIth a DPDT switch you can make the most basic H-bridge imaginable.

Basically, if wired correctly, a motor connected to the switch will spin in one direction when toggled one way, and the opposite direction when toggled the other.

To begin wiring this, solder the red wire from a 3 X AA battery holder to one of the center pins on the DPDT switch and the black wire to the other center pin.

Select one of the pairs of outer pins. Solder a red motor wire to the switch terminal in line with the center pin with the red wire already attached. Next, solder a black motor wire to the other outer pin.

Now, when the switch is toggled, the motor is either powered by the battery pack and spinning clockwise or doing nothing at all. We are halfway there. All we need to do is have the motor change direction when it is in what is currently the 'off' position.

To accomplish this, we need to wire it in such a way as to reverse the power to the motor. This may seem complicated, but is really easy. All we need to do is connect criss cross wires from the unused set of switch terminals to the terminals connected to the motor.

Basically, when the switch is toggled to make this connection, the black wire from the the battery pack is connected to the red wire from the motor, and the red wire from the battery pack gets connected to the black wire from the motor. By crisscrossing the wires, we have effectively reversed the power supply to the motor.

In this configuration, the H-bridge A1 and A2 connections are the first set of terminals connected directly to the motor. The B1 and B2 connections on the H-bridge are the other outer terminals where the crisscross wires are connected when the switch is flipped.

Drill the Horn

Drill an 1/8" hole into each of the four corners of the servo horn.


Pass two zip ties down through the front two holes in the servo horn.

Next, pass them through the two adjacent center-most holes in the corner bracket.

Then, pass the zip ties through the hanging holes in the brush handle.

Finally, zip tie everything firmly together.

Drill the Legs

Use the two free holes in the L-brackets as guides for drilling downward through each of the brushes.


Securely zip tie the brushes to the L-bracket.

For extra support, zip tie the brush handle mounting ring to the unused back holes of the servo horn.

Cut the Lid

Center the backside of your servo near one of the short edges of the plastic container lid.

Trace the outline of the back of the servo and then cut out the shape with a razor blade.

Finally, pass the motor wires through the hole and slide the plastic container lid down over the servo.

Drill and Fasten

Drill 1/8" holes in the plastic container lid that line up with the mounting holes of the servo.

Zip tie the motor firmly in place.

Trim away the excess zip tie ends if you haven't done so already.

Center and Drill

Center the battery holder over the underside of the plastic container and use the holder's mounting holes as drill guides.

Drill two 1/8" holes.


Place the battery holder inside the plastic container and fasten the two items together using nuts and bolts.

Measure and Drill

Take the two remaining scrubbers and measure 1" in from the edge and make a mark.

Drill a 1/8" hole down through the handle where you made this mark.

Attach the Legs

Turn the plastic container upside down. Mark, drill, and zip tie the two remaining scrub brushes to the front of the plastic container such that they meet at a 90 degree angle, and point evenly downwards towards the direction of the plastic container opening.

In other words, make two even-length front legs for your bot.

Mount the Switch

Drill a 1/4" centered hole near the other short edge of the plastic container lid.

It's important to get it roughly on center because the robot's legs will be flipping the switch back and forth. If it is off center, the robot will rotate it's leg much more in one direction and drift to one side.

Pass the DPDT switch through so that the shaft is pointing at the scrubber legs and then fasten it on with a nut.

Wire It Up

Now is time to wire the switch up as shown earlier in the H-bridge wiring example.

Wire together the opposite corners of the DPDT switch.

Solder the red battery wire to one of the center pins of the DPDT switch and the black battery wire to the other.

Turn the switch so that there are only two pins facing you (as opposed to three). Solder the black motor wire to the DPDT pin closest to you on the right. Solder the red motor wire to the other pin on the left.

Note: If, when you power it up, the switch isn't making the motor move back and forth, remove the batteries. Next, detach the motor wires and reverse the switch pins they were connected to.


Take apart a pen and cut about 1-1/2" from the end of the pen tube.


Now we want to extend the length of the toggle switch lever to ensure the rotating scrub brush legs are able to make contact and toggle it.

Make certain the switch is positioned between the two scrubbers.

Fill the pen cap with hot glue and quickly slide it onto the switch's shaft. Be careful not to get any hot glue inside the switch. This could prevent it from working.

Hold the tube in place until it begins to set.


Put some batteries into the holder and the legs will start to go.

Case Closed

Quickly close the plastic container and let the bot go free.


Share a photo of your finished project with the class!

Nice work! You've completed the class project