Pages: [1] 2   Go Down
Author Topic: Powering a model elevator with an H Bridge  (Read 1945 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is the code I am using in school to run a model elevator using a DC motor. I have a potentiometer to select floors, and then a push button switch to confirm the floor. Then an H bridge made from four transistors is used to power the DC motor. When I go from a lower floor to a higher floor, the LEDs light up to show motion, but the motor won't run. Further inspection shows that the PNP transistors also heat up A LOT. Then if I try to go back down, the motor runs fine, LEDs light up, and the transistors don't heat up. The H bridge works both way fine in a debugging code I wrote for it. So I am guessing it is a software problem, not the H bridge. Attached is my code. Any suggestions are welcome. Thanks.

Code:
int potvalue = 0;
int potmap = 0;
int butval = 0;
int butprev = 0;
int currentfloor = 1;
int destfloor = 0;
int runtime = 0;
boolean press = false;

void setup () {
  pinMode (A0, INPUT);
  pinMode (A1, INPUT);
  pinMode (2, OUTPUT);
  pinMode (4, OUTPUT);
  pinMode (6, OUTPUT);
  pinMode (9, OUTPUT);
  pinMode (11, OUTPUT);
  Serial.begin (9600);
}

void loop () {
  potvalue = analogRead (A0);
  potvalue = map (potvalue, 0, 1023, 1, 6);
  butval = analogRead (A1);
  if (press == false) {
    switch (potvalue) {
      case 1:
        digitalWrite (2, HIGH);
        digitalWrite (4, LOW);
        digitalWrite (6, LOW);
        break;
      case 2:
        digitalWrite (2, LOW);
        digitalWrite (4, HIGH);
        digitalWrite (6, LOW);
        break;
      case 3:
        digitalWrite (2, HIGH);
        digitalWrite (4, HIGH);
        digitalWrite (6, LOW);
        break;
      case 4:
        digitalWrite (2, LOW);
        digitalWrite (4, LOW);
        digitalWrite (6, HIGH);
        break;
      case 5:
        digitalWrite (2, HIGH);
        digitalWrite (4, LOW);
        digitalWrite (6, HIGH);
        break;
      case 6:
        digitalWrite (2, LOW);
        digitalWrite (4, HIGH);
        digitalWrite (6, HIGH);
        break;
      default:
        digitalWrite (2, LOW);
        digitalWrite (4, LOW);
        digitalWrite (6, LOW);
    }
    if (((butval - butprev) > 30) && (butprev != 0)) {
      press = true;
      destfloor = potvalue;
      digitalWrite (2, HIGH);
      digitalWrite (4, HIGH);
      digitalWrite (6, HIGH);
    }
    butprev = butval;
  } else if (press == true) {
    runtime = (destfloor)-(currentfloor);
    if (runtime < 0) {
      for (int i = 0; i < abs(runtime); i++) {
        digitalWrite (9, HIGH);
        digitalWrite (11, LOW);
        digitalWrite (2, HIGH);
        digitalWrite (4, LOW);
        digitalWrite (6, LOW);
        delay (250);
        digitalWrite (2, LOW);
        digitalWrite (4, HIGH);
        digitalWrite (6, LOW);
        delay (250);
        digitalWrite (2, LOW);
        digitalWrite (4, LOW);
        digitalWrite (6, HIGH);
        delay (250);
        digitalWrite (2, HIGH);
        digitalWrite (4, HIGH);
        digitalWrite (6, HIGH);
        delay (250);
      }
      currentfloor = destfloor;
    } else if (runtime > 0) {
      for (int i = 0; i < abs(runtime); i++) {
        digitalWrite (9, LOW);
        digitalWrite (11, HIGH);
        digitalWrite (2, HIGH);
        digitalWrite (4, LOW);
        digitalWrite (6, LOW);
        delay (250);
        digitalWrite (2, LOW);
        digitalWrite (4, HIGH);
        digitalWrite (6, LOW);
        delay (250);
        digitalWrite (2, LOW);
        digitalWrite (4, LOW);
        digitalWrite (6, HIGH);
        delay (250);
        digitalWrite (2, HIGH);
        digitalWrite (4, HIGH);
        digitalWrite (6, HIGH);
        delay (250);
      }
      currentfloor = destfloor;
    } else {
      digitalWrite (9, LOW);
      digitalWrite (11, LOW);
      press = false;
    }
  }
}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25874
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
So I am guessing it is a software problem, not the H bridge
I'm largely immune to guesswork, so I'd like to see a schematic and which pins are wired to what.
Pin numbers alone don't convey much information.

Analogue pins used as analogue inputs don't need to have their pin mode set.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Tesla Member
***
Karma: 141
Posts: 9470
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is your elevator counter weighted to take most of the load off of the motor?
Logged

Consider the daffodil. And while you're doing that, I'll be over here, looking through your stuff.   smiley-cool

Topsham, Vermont USA
Offline Offline
Edison Member
*
Karma: 32
Posts: 1867
... in The Woods In Vermont
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

HI, You need to tell us both the motor voltage/current and the driver information. 

Are you using PWM to "soft start" the motor? Or just instantly turning it on??

Logged

Regards, Terry King terry@yourduino.com  - Check great prices, devices and Arduino-related boards at http://YourDuino.com
HOW-TO: http://ArduinoInfo.Info

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

Thanks for the responses! I attached a PNG of the schematic. The motor is instantly turned on, there is no PWM control used. Could there be problems with my for loops?

Thanks


* Elevator Schematic 1.png (26.99 KB, 1951x1161 - viewed 37 times.)
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is your elevator counter weighted to take most of the load off of the motor?

Yes it is. However, I am just testing the code, so the motor is not hooked up to the model yet. It is running freely, so there is no load on it.
Logged

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 5557
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Is your elevator counter weighted to take most of the load off of the motor?

Yes it is. However, I am just testing the code, so the motor is not hooked up to the model yet. It is running freely, so there is no load on it.

Is that -really- how you have the h-bridge hooked up, because to me, it looks wrong.

R6 should go to Q2 and R8 should go to Q1

You turn on opposite sides to get the current to flow thru the motor; I'm really not sure how you're getting it to run at all (can you show us that debug code?)...
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Phoenix, Arizona USA
Offline Offline
Faraday Member
**
Karma: 39
Posts: 5557
Where's the beer?
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Also - looking at the schematic again - can you tell us what values your base resistors are, as well as why you didn't put any back-EMF diodes in place? Your transistors might already be dead (unless you have them and omitted them from the schematic)...
Logged

I will not respond to Arduino help PM's from random forum users; if you have such a question, start a new topic thread.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did not use diodes because my teacher gave us a budget. However, due to the low voltages, I figured it wouldn't matter too much. My debug code has no physical input. It simply declares pin 9 as HIGH and pin 11 as LOW in the code. I change the values in the code to obtain the reverse direction. I can verify that the transistors still work. Later I will post a picture of the entire circuit to show you how I hooked it up. The schematic I drew might be wrong.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25874
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I did not use diodes because my teacher gave us a budget.
False economy.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I did not use diodes because my teacher gave us a budget.
False economy.

Talk to my teacher. Most of the budge came out of my pocket. The diodes couldn't be the reason, right?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Here is a picture of the protoboard.


* Photo Jun 12, 12 38 10 PM.jpg (1901.48 KB, 2592x1936 - viewed 13 times.)

* Photo Jun 12, 12 37 58 PM.jpg (1967.85 KB, 2592x1936 - viewed 13 times.)
Logged

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11730
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did not use diodes because my teacher gave us a budget. However, due to the low voltages,

Without the diodes the voltages will be _high_ voltages - inductances/motors generate as high a voltage as they need to to pass current through the external circuit - without the diodes to provide a safe current path those voltages may damage the transistors.  Even 1N4148 diodes would probably do as they have a pulsed current rating of 450mA, and they are cheap.

Another issue with the H-bridge is that it has shoot-through (both NPN and PNP are on simultaneously (briefly) during the switch-over, directly shorting the supply rails together).  If you use 4 pins to control the 4 transistors you can introduce dead-time to prevent this.
If not using PWM then it won't be wasting much power though.  Bipolar transistors carrying large currents can take several microseconds to turn off, much slower than the turn-on, due to minority carrier storage effects.

However the issue of the transistors getting hot is most likely because there's not enough base current to drive them into saturation (current gain drops off rapidly at higher collector currents, and saturation requires more current still)  Try base resistors of 220 ohms.
Logged

[ I won't respond to messages, use the forum please ]

Offline Offline
Newbie
*
Karma: 0
Posts: 9
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
However the issue of the transistors getting hot is most likely because there's not enough base current to drive them into saturation (current gain drops off rapidly at higher collector currents, and saturation requires more current still)  Try base resistors of 220 ohms.

So you recommend lowering the resistance? I am using 1K resistors, and elsewhere I read that a lower resistance should not be used. I will try what you are suggesting though. So the current from the battery is moving into the PNP transistors, but there is not enough current from the pins to move the higher voltage current through to the motor? Correct me if I am understanding this incorrectly.
Logged

0
Offline Offline
Shannon Member
****
Karma: 200
Posts: 11730
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The basic operation of a transistor is that the base current controls the collector current, with the ratio being the current gain (often called beta or Hfe).  However this only applies if the collector is several volts higher than the emitter, and only at small currents.

At higher currents the gain drops quite markedly (a transistor with a gain of 200 might end up with a gain of 25 at its full rated current, for instance).

Also to saturate a transistor (pull the collector to 0.1V or less above the collector) takes even more base current - otherwise the transistor might have a volt or so across it and dissipate a lot more power than needed.

The limit for Arduino pins is 40mA absolute max, lets be cautious and use 20mA to the base, thats (5 - 0.7)/0.02 = 215 ohms.

Most switching transistors should be able to happy carry 200 to 400mA or so at saturation for 20mA of base current, some can do significantly better (but they cost more).  The 2N2907 isn't great at saturation beyond about 100mA, BTW, it may just be the wrong part for the job.
Logged

[ I won't respond to messages, use the forum please ]

Pages: [1] 2   Go Up
Jump to: