BlogCadre users see no ads!  Popular topics: humor, video, links, cool, wtf.  Go create an account!




Howto: Make A Robot Car - Part 2: H-Bridge Details

robot_car_1.jpgThis is the second part in a howto series about building a relatively cheap robot out of a radio controlled car and an embedded microcontroller such as the Basic Stamp.

In part 1, I glossed over how to interface a microcontroller with the drive and steering systems on a typical, cheap RC car. Today, we'll be looking at the circuit in a little more detail.  I've also added the simple BS2 program that I used in the demo video from the previous article.



The H Bridge
The h-bridge is a simple circuit that you can make to control power to a motor from a low power circuit such as the logical IO from a microcontroller.

RC Car H-Bridge Schematic
Here you can see the circuit I used in my project.  I/O A and I/O B connect to the I/O pins on the Basic Stamp (BS2).  The +6V is the positive terminal on the RC car battery, and at the bottom VSS connects to the BS2 ground and is also grounded to the negative terminal on the battery.

Here's how it works.  When A and B are both off, the PNP transistors at the top of the circuit will allow current to flow, but the NPN transistors at the bottom will not.  Similarly, when A and B are both on, the situation is reversed with the NPN transistors being on and the PNP transistors not allowing current to flow.  In either scenario, there is no path for electricity to get from the battery to ground.

Now if I/O A is on and B is off, the NPN pair at the bottom left and the PNP pair at the top right will both be open.  This creates a circuit that allows the current to flow through from the top-right, through the motor, and down the bottom-left, and down to ground.  This causes the motor to spin in one direction.  Raising pin B and dropping pin A has the opposite effect, causing the motor to spin the other way.

The h-bridge effectively gives us 3 states: off, forward, and backward.  On your car, you can use one of these circuits to control the drive motor, and another h-bridge to control the steering motor.


Components Used

R1, R2, R3 and R4 are all 1K resistors.  In my setup, Q5, Q6, Q9 and Q7 are all smaller signal transistors.  You can probably get away with whatever you can find at your local electronics store.

The important thing is that Q1, Q2, Q3, and Q4 can pass enough power to meet the demands of your motors.  The spec you are looking for is the collector current (Ic).  3A should be quite sufficient for most cheapo RC motors.  These will be the transistors with the attached heatsink.  I used the TIP31 and TIP42 models that I found at the local Radio Shack.

You'll notice that all the transistors are paired up.  These are called Darlington Pairs.  It allows a low current source, such as the BS2 IO, to amplify its current with one transistor, and use that output to saturate the higher power transistor which is used to drive our motor.


Caution

In this circuit, it is very important that the BS2 ground (VSS) and the battery ground (-6V) are connected.  Also, the I/O pins cannot be floating, so you should have the battery disconnected if the BS2 is not running.  Otherwise it will only take a few seconds to smoke your transistors.


A Note On Making Schematics
This is the first schematic I've ever made, so please pardon any sloppiness or common newbie errors.  If you've never done this before and you're interested in making a schematics, I recommend trying Eagle.  I used the freeware Mac version and was pretty happy with it.


Other Ideas
If you're lucky in your hunting you may find PNP and NPN Darlington Transistors in a single package.  Grab those and swap them out for the pairs above and you'll save yourself some wiring.

Robogeek also informs me that the LMD18200 is a pretty fantastic  h-bridge on a single chip.  It can provide 3A continuous with a 6A peak and you can avoid all the messy wiring.  Wicked!  I ordered 5 samples from National and they sent them free of charge and even sent me a thank you letter.  How cool is that?  I'm looking forward to trying these out and I'll make sure to report back.


Programming

At this point, we've got ourselves a fully functional robot platform.  You'll need to add sensors, etc. to make this more autonomous, but you should have everything you need to drive a car around under the control of a teeny microcontroller.

Attached is the program I used for my demo.  As you can see, there's nothing magic here.  There are a few routines to turn the motors on and off, do a 2 point turn in place, etc.  The main routine ties a few of these together to make the robot drive around a little bit.


Get Busy

I'm really excited to see other people make these.  I'm working on a GPS guided version, but there are a lot of other possibilities as well.  This is basically a nice little platform that you can use as a starting point for any mobile robot project.

Make sure to tell us your ideas in the comments.  If you're working on an r/c car robot yourself, let me know about it and we can add it to the series.

Trackback URL for this post:

http://www.blogcadre.com/trackback/686
from MAKE: Blog on November 14, 2005 - 7:44am

Robot Car 1.ThumbnailHere's part two of Jason's HOW TO make a robot car - "This is the second part in a howto series about building a relatively cheap robot out of a radio controlled car and an embedded microcontroller such as the Basic Stamp." Link.

AttachmentSize
rccar-h-bridge.jpg41.11 KB
autodrive.bs2.txt1.53 KB

questions on building

Jason Striegel's picture

I've had a couple people email me about building the control circuit. Here are some tips that may help others. If you have any questions, please post them here. Also, don't hesitate to help eachother out.

The link is also in the attachments above, but here's the schematic for the h-bridge that I used in my setup. There's also a picture (relatively poor, unfortunately) of it breadboarded here.

Basically, you need to make one of these for each motor you want to control. I'd recommend breadboarding one and making sure it works before connecting to your BS2 or building the other h-bridge.

You can test by doing the following:

  • ground both IO wires
  • connect a test motor (or a multimiter) to the two output wires (these are the two in the schematic that point toward the word "motor")
  • connect the power source
  • ensure motor is still and transistors are cool

At this point, the motor should not move and the transistors should remain cool. Be ready to remove the power source quickly in case something is wired wrong.

Make sure the IO pins are grounded (or connected to the positive terminal) whenever the power is connected or the transistors will heat up and become damaged.

So far, so good. Now finish testing the circuit:

  • quickly move either of the io wires
    to the positive terminal and you should see the motor spin
  • put the io wire back to ground and test
    the other one and it should spin the opposite way
  • ensure the transistors run cool in both scenarios

If everything is connected right, the transistors should run cool as long as the io inputs are connected either to ground or to positive and not "floating".

The darlington paired transistors are a bit of a pain to breadboard because the far left and far right pins of the signal transistor need to connect to the middle and left pins of the power transistor. You can sort of cross the middle pin of the signal transistor over the right and have it facing the power transistor (twisted a little)...

If you can find them, I'd recommend getting the single component NPN and PNP darlington transistors instead and save yourself the hassle.

There is a slight voltage drop through this circuit, so your car will not have quite as much power as it did in its previous life as an R/C car. This is normal (and has the side benefit of making it easier to chase down when something goes wrong in your porgramming).

Good luck everyone. Please leave a comment and let everyone else know how your build is going!

robot!

hi

thanks for the info on H bridges!, very strangely i am also building something similar to what you have built, and i want it as a base for other things also. i havent built any of the control circuitry yet, but i spent some time on the base, because i have mono, and im off school, and i have nothing better to do.

at the moment its just going to be R/C controlled, with the posibility of simple beam style interaction- like obstacle avoidance, light following etc..

im very interested in PIC stuff, but i dont know where to start, so this thing will be a base for that, when i can find out more about it.

if anyone could give any info or resources on PIC stuff it would be greatly appreciated.

check out my site for pics off my robot!

(click my name)

Very useful

Nice. :) I was already in the middle of building something similar using a PIC16F877a chip. I already designed and built an adaptor for my PIC16F84a programmer to allow it to work on the bigger chip. Other than that though, it's still very much in the design and planning stages.

The approach I was taking was to interface with the existing RC circuitry and both read the remote input as well as use the motor control circuitry. That way, codes could be signalled in via remote and the microprocessor would interpret these and control the vehicle accordingly. I was also going to add LED headlights and tail lights, which could be controled by the microprocessor for effect, and some IR sensors.

I hadn't thought about building my own H bridge circuitry though. It's always good to see what approaches others have taken.

Regarding your inputs needing to be grounded when disconnected, couldn't you add some 10K pull-down resistors to them so if no input is placed on the pins, they will be automatically grounded? It seems that would be a nice simple solution for that problem.

Hey Jason

Thanks for the link on the LMD18200 tip, My meeting is starting to run down at work so I should be able to get back on the development side of the robot kits we have discussed.

I made a poll, What controller would you like to have in an under $60 Robot Brain?

I am posting a new blog entry with some links for the options so people can research what they would like. I will probably design boards for everything. I just wanted to get a feel for what people would like.

------------------------------------------------
Robogeek
-Black Holes are where God devided by zero.
-Alcohol and Calculus don't mix, never Drink and Derive!
-If you can read this... Thank a Teacher.

chip

thanks for the info on the lmd18200. my teacher got some ordered to the school. :)

what would you suggest for starting out with stamp. from what i can see the BOE stamp2 kit looks good. what do you use?

re: chip

Jason Striegel's picture

They have a discovery kit for $150 that comes with a BS2, the board of education, a bunch of components, and a manual. The BOE bot seems like a good setup, too. It looks to be about the same stuff except that it has the bot skeleton (could make this from an old floppy drive case maybe?) and some wheels.

Actually, come to think of it.. they emailed me a special the other day, where you can get the BOE bot along with a free scribbler robot (for just the price of the BOE bot). Kindof cool because you'd have two BS2s to play around with. The special url is here, and hopefully it'll be available until Christmas.

thnx

thanks for the info and tips. getting a free scribbler looks like a good
deal.

if you use the h bridge chip, please post your circuit because mine isn't really working as it should.

Programing.?¿

I'm using your H-bridge design in a project for my TSA competition. I got it to work some what but I'm having problems w/ the programing. In the post you said there was a link to the programing you used.. It wasn't there or I couldn't find it... some help plz?

whoopss!

Jason Striegel's picture

Sorry! I forgot to list the files. They're added to the post now, and the BS2 program you are looking for is here.

Can you send us a link to your competition? I'd love to see where this is being used.

TSA

The homepage is http://www.tsaweb.org/
- this is the link for a brief description of wat i'm doing..
http://www.tsaweb.org/content.asp?contentid=516
it's under Robotics (Radio Control)

This is the problem i'm having w/ my bot... i need to use the Board of edu. and i wan't to use dc moters insted of servoes.. your h bridge works gate but i'm trying to produce a varying speed moter... i'v been trying to use your h bridge along w/ PWM and i keep overheating the chips (on the h bridge, they haven't burned up but they just got really hot). also using PWM i'm not able to get a high enofe output on the motors. they do move but not as fast as i wan't. any segestions

Re: TSA

Jason Striegel's picture

I haven't tried PWM yet with my robot, so I'm interested in hearing your final setup when you are done (you should make a blogcadre account and do a writeup!) In the meantime, let's try to get to the bottom of your problem. (Robogeek, care to chip in and offer your expertise?)

What are you using to do PWM? I think parallax has a motor controller that will do this, or maybe you just have a routine that turns the motors on and off. I was thinking of experimenting with both. Before you try the PWM stuff, try running the motors at full input and see if there are things going wrong there.

Here are some things to look for:

If the power transistors are overeheating, the signal transistors in the darlington pair might not be saturating them fully. Use signal transistors that are rated for higher current. The power transistors may also be undersuited for the task. Depends on which components you are trying and how much power they need to service your motors. Fix this problem first.

At 100 percent service, the motors are going to run a little slower than normal because their is a slight voltage drop through the h-bridge circuit (1.2v as I recall). You'll have to measure to be sure, but you might be able to get away with increasing the voltage of the power pack to compensate.

You might want to check out the LMD18200 that robogeek mentioned. It's probably much easier in the long run and will give you decent performance. I ordered some samples from National and they came the same week, free of charge (with a thank you letter, no less). Still haven't gotten around to trying them out yet, though, but I will as soon as I get a chance to post the details of my top secret gps guided car ;)

I'll try that monday and if

I'll try that monday and if i have time i'll start my own blog... but i'm really biusy w/ school and my clubs.... i checked out the LMD18200 and it seems to b what i need... but if i can get your's to work i won't have to pay for that chip.... i have the ability to make and produce my own boards here... we use copper w/ bace baths so once i get yours to work i'll make a board.

Starting Out New - From Scratch

I'm looking into building a simple little autonomous rc car, but I have almost no $$$. I've got all the tools and equipment at my disposal, but I don't have a board (looking they are $50+)

Is there a place where I could get a schematic for building my own board?

re: starting out

Jason Striegel's picture

You might want to start with a PIC or PICAXE chip instead of the basic stamp. You can cut costs by skipping the fancy mainboard, and just use the chip in a breadboard with a voltage regulator to power it.

Go with the free sample h-bridges that robogeek mentioned. It'll save you some money and a lot of complexity and you'll end up with a better product.

I have my car driving by GPS now. A receiver will cost maybe $100, though, but maybe you have one already.

Let us know what you decide to do. Budget projects are my absolute favorite. Oh yeah, feel free to make an account here and post your project!

compass

its not GPS but the compass appmod at $30 for bs2 looks pretty cool for this kinda thing.

There on fire..!!

The chips are still heating up alot... i'm using 6v source .. how much power sould be needed to bring the output to 6v... i know it won't ever get to exactly 6v but as close to it as possible..

grounded correctly?

Jason Striegel's picture

Also make sure that the -6V is grounded to the BS2 ground (VSS). One other thing, make sure you don't connect the 6v source until the BS2 is connected and ON. Otherwise your circuit will heat up and become damaged. In my test setup, I turn on my BS2, then I attach the battery. I have a 15 second timer at the beginning of my program to give me time to attach the battery.

What components are you using for your transistors? Any chance you damaged any of them while testing the circuit? If they overheat too much, they can be permamently dead.

Oh yeah, and did you see robogeek's not below about pwm frequency?

try getting sponsors

Visit my webpage at www.mechatronicrobots.bravehost.com as I too compete on Robotics (Radio Control) TSA competition. Try going completely expensive for projects like these. If you're in tune with competition rules you will need a really long arm to place 9-1/2" diameter balls at a height of approximatelly 19.5" high. Reply to my e-mail at HeribertoR88@yahoo.com. I'd help you on one occasion. Get sponsors!!!

frequency?

One other question I have for you is what frequency is your PWM running at if the switching frequency is too fast for the Transistors you have it might not work.

The LMD18200 is good we use it in military projects. It also uses less output pins from your controller.

Robogeek

LMD18200

i'm using a 6v battery will this be enough power to make this chip feasible for my project?

Thanks

thnks for all the help but i can't get it to work properly and it's taking up too much time.. so i'm going to go a different direction.. again thanks and i'll poast my results later.

Hello

Hi all im a seneior student whos trying to build an autonomousa robot from scratch using my large rc truck as a base. So I need help as to what sensors are best for a good self driving robot.
Those tutorials are great too.

Email any ideas to nathan rasmus@nurihs.sa.edu.au

A little trouble

can anyone email me a schematic with the CBE? im going ot end up burning these things up and i need to know the CBE of each transistor. willthiswork89@msn.com is my email if someone could just add it.. thanks

the collector, base, and

the collector, base, and emmitter are different for each transistor you will need to tell us what transistor you're using as well as the package type. sorry this is so brief I am tapping this out on me new dell pda.

Step-By-Step Instructions

A most cool project. I have a very limited background in electronics and was hoping that you could put together a step-by-step list of how to connect the brains to the brawn. I have the RC rig and a Parallax Board of Education with a BASIC Stamp 2 module but I don't know what to do next...

Any help would be much appreciated!

really nice!!

eddouble86's picture

Hi,
I came across this article a few weeks ago and I had to try and make one of these. Forgive me for not having informed you earlier but i wanted to report it with some progress done. I am using an NXP LPC2148 evaluation board for the brains. I haven't got to programming it yet because am still getting the control circuit right. Will report more as i make more progress. Click on my image and you can see my album of what the car looks like now. (the first link only!!)

Thank you for this cool article by the way!

hot transistors!

eddouble86's picture

Me again, I have a problem with setting up the H bridge. When both I/O A and B are grounded, the motor doesn't run and the transistors stay cool but when i connect either one to the positive terminal the transistors heat up really quickly! I have tried re-wiring the circuit over and over again but still no change. Am not sure what am doing wrong but i do know i need help!

re: hot transistors

Jason Striegel's picture

it's hard to tell what's going on without seeing it first-hand, but it sounds like maybe the transistors aren't getting completely saturated or something is wired incorrectly.

some things to check:

- which transistors are getting hot? the signal ones or the power ones? if the transistor is completely saturated, it's resistance drops to near 0, so it shouldn't be warm at all. note that the feet on the small signal transistors are in a different order than the power transistors. (if you can, just grab the single IC darlington transistors. it'll save you a bunch of trouble).

- does the motor turn? make sure the diodes are in the right direction.

- make sure the control circuit and the power circuit share a ground.

- don't leave either of the inputs floating. they should be either grounded or powered.

Thank you

eddouble86's picture

It was the the power transistors heating up and i have also confirmed that the transistors are not getting saturated correctly. I am going to try and look around for the single IC Darlington transistors. thank you for the reply

That's exactly what I was looking for

I was searching for a simple H-bridge to be used with a microcontroller and I'm glad I found this solution. With this circuit a have no chance to do a short circuit. The only thing that could make things wrong is if A and B are not Low (grounded) two transistors on the same side will be on and here comes the heat problem. A simple solution to solve the problem is two replace R1,R2,R3,R4 with high value and add two resistors of 1K on A and B that goes to the ground. Those resistors drain the current coming from Q1 or Q2 and prevent Q3 or Q4 from switching.

Resistors...

So for adding those high value resistors your thinking replacing r1-r4 with something like 10k resistors and then putting 1k's from both a and b pins to ground? i was hoping you would clarify this seeing as i am fairly new to the hardware end of the electronics field (i also had a very shitty teacher in high school electronics, haha). i'm gonna run it like jason has it drawn up and then before i connect it to my micro controller i will try your resistor setup. oh and btw i'm using an armmite evaluation kit from coridiumcorp.com. it seemed to be the best valued 24 i/o micro controller kit. so far i'm happy with it. i'll let you guys know how my project is going later and hopefully get some pics up soon.

spawn

hi there,

i am making a pre-programmed car and trying to use h-bridge as in here, but i am bit confused about the diode you used here are these simple diode or zener diode? what is the alternative for the trinsistor for TIP42 and TIP31?

Diodes...

Hi, I'm just ordering the components for this awesome project and I was wondering what kind of diode can I use/did you use, what type?
Thanks alot..

programming

am trying to design an autonomous car usin pic16f877a gps and ultrasonic sensors.all these are done on a 3 wheeler with one front wheel and 2 back wheels.2 stepper motors are attached to the 2 back wheels.instead of basic stamp,iam using pic 16f877a....so what all changes are to be made in your program.email me at darshan.rc@gmail.com

I must say that overall I am

I must say that overall I am really impressed with this blog.It is easy to see that you are impassioned about your writing. I wish I had got your ability to write. I look forward to more updates and will be returning.
Electronics