Lab #8 Motors


Parts we used:
H-bridge, diode (brownish red colored little fellow), TIP-120 transistor (three legged black square), small DC motor, 10 µF capacitor (the black cylinder). We also used the breadboard, hook up wire, Arduino, potentiometer, switch, 1K Ohm resistor, 10K Ohm, resistors (or similar), wire stripper, multimeter.

HOOKING UP ARDUINO BOARD, ADDING POTENTIOMETER
Hooked up the Arduino to the breadboard, and then we added a potentiometer with the middle «output» wire connected to analog pin 0.

ADDING MOTOR
We soldered wires to the motor, and connected the motor wires to power and to the center collector pin of the TIP120 transistor. Then we connected the output end of an LED to the same center collector pin of the transistor. Then we added a diode with the input end of the attached to the right-side emitter pin of the transistor. This diode will prevent a spinning motor’s “blowback” current from shorting out the circuit.

We connected a 1K ohm resistor to the left-side base pin of the TIP120 transistor. We wired the other end of that resistor to Arduino digital pin 9. To reduce noise in the circuit, we put a 10µF capacitor between the power and ground rails of the breadboard. The circuit was completed by connecting the right-side emitter pin of the TIP120 to ground. This is what it looked like:

UPLOADED CODE
Uploaded the following code to translate the analog input into digital output that moves the motor.

int motorPin = 9; // motor connected to digital pin 9
int analogPin = 0; // potentiometer connected to analog pin 0
int val = 0; // variable to store the read value
void setup()
{
pinMode(motorPin, OUTPUT); // sets the pin as output
}
void loop()
{
val = analogRead(analogPin); // read the input pin
analogWrite(motorPin, val / 4); // analogRead values go from 0 to 1023, analogWrite values from 0 to 255
}

LOOK, it works, and we made a 6 seconds video to prove it!

ADDED A SWITCH
Removed all components except the motor and the wires connecting power between Arduino and the breadboard, and then hooked up a regular switch (SPST) to the breadboard.

ADDED AN H-BRIDGE
By adding a bunch of wires to different places on the breadboard all of a sudden an H-bridge was hooked up. Amazing. This is what such an H-bridge looks like all wired up:

This H-bridge combined with the code below was supposed to let us control the motor to go in different directions depending on the switch being in ON or OFF position. We didn’t actually make it happen, and we are not sure why – even after troubleshooting for a while. However, we are pretty sure the answer is hidden somewhere within the delicious spaghetti of wires surrounding the H-bridge.

const int switchPin = 2; // switch input
const int motor1Pin = 3; // H-bridge leg 1 (pin 3, 1A)
const int motor2Pin = 7; // H-bridge leg 2 (pin 7, 2A)
const int enablePin = 9; // H-bridge enable pin
const int ledPin = 13; // LED
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);
// set enablePin high so that motor can turn on:
digitalWrite(enablePin, HIGH);
// blink the LED 3 times. This should happen only once.
// if you see the LED blink three times, it means that the module
// reset itself,. probably because the motor caused a brownout
// or a short.
blink(ledPin, 3, 100);
}
void loop() {
// if the switch is high, motor will turn on one direction:
if (digitalRead(switchPin) == 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 {
digitalWrite(motor1Pin, HIGH); // set leg 1 of the H-bridge high
digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge low
}
}
/*
blinks an LED
*/
void blink(int whatPin, int howManyTimes, int milliSecs) {
int i = 0;
for ( i = 0; i < howManyTimes; i++) { digitalWrite(whatPin, HIGH); delay(milliSecs/2); digitalWrite(whatPin, LOW); delay(milliSecs/2); } }

2 Responses to “Lab #8 Motors”

  1. Hi to all, the contents existing at this web page are
    really amazing for people knowledge, well, keep up the
    good work fellows.

  2. They making you fewel fuller leting you eat fewer your next meal while they leave you
    feeling satisfied. o Most indikviduals are overweight due to processed food consumption. Exercise is the one other important
    aspect how ever there is no need to slave for the treadmill for a long time at
    a time for weight reduction. http://fabiandsft036blog.isblog.net/the-best-ways-to-reduce-weight-fast-the-man-s-way-1489663

Leave a Reply