Using Transistors and Batteries to Power Motors

posted Mar 14, 2016, 11:56 AM by Tony Farley   [ updated Mar 14, 2016, 12:53 PM ]
Today you are going to use something called a transistor to power your robot's motor with batteries.

A transistor works like a faucet. When you turn the knob on a faucet, it allows water to flow. A simple turn on a firehose valve can result in a big stream of water.
Transistors are electrical valves.

You will be using pin 9 of your arduino to "twist" the valve. A larger voltage sent out of pin 9 will result in a greater flow of electricity from the batteries to the motor.

Create the circuit shown below. The flat side of the transistor should face in the direction shown.
An image of the robot is below


Here is the program to run to make one wheel turn faster then slower over and over again.

int ledPin = 9;    // LED connected to digital pin 9

void setup() {
  // nothing happens in setup
}

void loop() {
  // fade in from min to max in increments of 5 points:
  for (int fadeValue = 100 ; fadeValue <= 255; fadeValue += 5) {
    // sets the value (range from 100 to 255):
    analogWrite(ledPin, fadeValue);
    // wait for 300 milliseconds to see the dimming effect
    delay(300);
  }

  // fade out from max to min in increments of 5 points:
  for (int fadeValue = 255 ; fadeValue >= 100; fadeValue -= 5) {
    // sets the value (range from 255 to 100):
    analogWrite(ledPin, fadeValue);
    // wait for 300 milliseconds to see the dimming effect
    delay(300);
  }
}

Take a picture or your robot and a video of your robot wheel spinning faster then slower.
post the video to youtube, then to your website.
Explain using text under the video and image what your robot is doing and how a transistor works.


Comments