Motors and transistors

Turning a transistor on and off is just a matter of applying voltage.

Use the Blink example code to turn the motor on and off every second, or try the Fade example to vary its speed.

Here’s the wiring for a p2n2222 transistor (the kind you have in your kit) :

p2n2222a_TransistorMotor_bb

Below is the schematic for a  TIP120 transistor (the kind we have in the lab) :

TIP120_TransistorMotor_bb

 

A H-bridge (fund in the lab, not in your kit) allows you to turn the motor in either direction. Use the code below with this schematic :

HBridge_motor_bb

const int motor1Pin = 9;    // H-bridge leg 1 (pin 2, 1A)
const int motor2Pin = 8;    // H-bridge leg 2 (pin 7, 2A)

void setup() {
    // set pins you're using as outputs:
    pinMode(motor1Pin, OUTPUT);
    pinMode(motor2Pin, OUTPUT);
  }

void loop() {
      // turn the motor in one direction:
      digitalWrite(motor1Pin, LOW);   // set leg 1 of the H-bridge low
      digitalWrite(motor2Pin, HIGH);  // set leg 2 of the H-bridge high
      delay(1000); // wait for a second
   
      // stop the motor spinning :
      digitalWrite(motor1Pin, LOW);   // set leg 1 of the H-bridge low
      digitalWrite(motor2Pin, LOW);  // set leg 2 of the H-bridge high
      delay(1000); // wait for a second
 
      // turn the motor in the other direction :
      digitalWrite(motor1Pin, HIGH);   // set leg 1 of the H-bridge low
      digitalWrite(motor2Pin, LOW);  // set leg 2 of the H-bridge high
      delay(1000); // wait for a second

      // stop the motor spinning :
      digitalWrite(motor1Pin, LOW);   // set leg 1 of the H-bridge low
      digitalWrite(motor2Pin, LOW);  // set leg 2 of the H-bridge high
      delay(1000); // wait for a second
  }

For inspiration of different gears and things, look at http://robives.com/mechs and http://robives.com/techniques

Leave a Reply