Powering a model elevator with an H Bridge

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.

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;
    }
  }
}

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.

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

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??

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

zoomkat:
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.

hollyjester:

zoomkat:
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?)...

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)...

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.

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

False economy.

AWOL:

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?

Here is a picture of the protoboard.

hollyjester:
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.

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.

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.

The 2N2907 isn't great at saturation beyond about 100mA, BTW, it may just be the wrong part for the job.

I read about the performance of the transistors here: Bipolar Transistor HBridge Motor Driver, Page 4 - Robot Room

it may just be the wrong part for the job.

According to tests on the web (I included a link to one below), 2N2907s seem to work. However, based on the fact that the transistors are heating up so much, I definitely agree with you on the saturation issue. The models I used for making the H bridge never mentioned an Arduino, so the resistors recommended there are probably for a higher amplitude current.