Friday, May 4, 2012

Transistor and H-Bridge

The transistor lab went fairly smoothly.



The H-Bridge on the other gave me a bit of trouble. I'm fairly positive that I had everything wired up properly, especially since I'd rewired it about four times..

using the code from the lab:


  const int switchPin = 2;    // switch input
  const int motor1Pin = 3;    // H-bridge leg 1 (pin 2, 1A)
  const int motor2Pin = 4;    // H-bridge leg 2 (pin 7, 2A)
  const int enablePin = 9;    // H-bridge enable pin

  void setup() {
    // set the switch as an input:
    pinMode(switchPin, INPUT);

    // set all the other pins you're using as outputs:
    pinMode(motor1Pin, OUTPUT);
    pinMode(motor2Pin, OUTPUT);
    pinMode(enablePin, OUTPUT);
    //pinMode(ledPin, OUTPUT);
    Serial.begin(9600);

    // set enablePin high so that motor can turn on:
    digitalWrite(enablePin, HIGH);
  }


  void loop() {
    // if the switch is high, motor will turn on one direction:
    if (digitalRead(switchPin) == HIGH) {
      Serial.println("high");
      digitalWrite(motor1Pin, LOW);   // set leg 1 of the H-bridge low
      digitalWrite(motor2Pin, HIGH);  // set leg 2 of the H-bridge high
    }
    // if the switch is low, motor will turn in the other direction:
    else {
      Serial.println("low");
      digitalWrite(motor1Pin, HIGH);  // set leg 1 of the H-bridge high
      digitalWrite(motor2Pin, LOW);   // set leg 2 of the H-bridge low
    }
  }

- I noticed that i was able to get HI and LO responses from the switch, and so the corresponding If conditions should have been executed, and yet the motor remained motionless. I was also sure to check that the motor was still working quite a few times. I'm thinking that something might be wrong with the H-bridge, as it would get incredibly hot any time I'd plug pin 8 to the power source, so I may have plugged something in wrong one of the first times around, and done some damage?


No comments:

Post a Comment