About Me

My photo
They never fall who never climb.

016 SPIN MOTOR WITH TRANSITOR CONTROL


016 SPIN MOTOR WITH TRANSISTOR CONTROL

March 16, 2011    (See also Companion Blog )
[Go BACK to Table of Contents] [ Next Experiment ] [ Last Experiment ]

           To control the speed and operation of a toy motor using a transistor responding to Arduino code.

           This is the first time I’ve used a diode and a transistor in a circuit, so I copied a trusted source: Arduino Experimenter’s Guide CIRC-003. From what I’ve read, the Arduino will supply a tiny voltage to the transistor base, thus causing a larger current to flow through the transistor and control the operation of the motor.

           I scrounged a small motor from a battery powered cassette player. The schematic shows the simplicity of the circuit, but take it from me, it is best to put in the effort to understand this experiment totally. Don’t get lazy here, you will regret it.

           I chose a general purpose transistor that came in a package of assorted numbers. It said they were good for general switching and amplification. Since I find the computer code easy to comprehend, I see that the code (shown below) will test both operations. Pin 9 can emit both a digital signal and a PWM signal which imitates an analog signal.

Theory:
           See the resistor between pin 9 and the transistor base pin? My guess is that it is there to limit the current, the Arduino puts out much more voltage than is needed to operate this transistor. See also the diode? I suspect it is there to prevent the motor from kicking backwards when it stops abruptly.

The microprocessor is programmed in three modes.
           Mode 1. Send a HIGH (5Volt) signal or a LOW (0Volt) signal. This should turn the motor on and off. The resistor is needed t limit the voltage or current from the Arduino, my guess is because 5Volts is just too much.
           Mode 2. Send an analog (PWM) signal telling the Arduino to spin fast for 2500 milliseconds, then spin slow for 1000 milliseconds.
           Mode 3. Send an analog signal telling the Arduino so gradually speed up and slow down.

Practice:
           The circuit worked perfectly in all three modes.

           Mode 1. The most precise is the digital on/off mode where the motor really kicks in on queue. It does not stop instantly because momentum causes it to wind down to a stop. I had to increase the delay speed to ensure it really was stopping. The motor almost instantly went to full speed when electricity flowed.

           Mode 2. The motor responded to quite rapidly to interim speeds. Where the digital was on or off, the analog PWM could select different speeds. I tested various combinations of fast and slow. All performed exactly as predicted. With analog, the motor seemed to take slightly more time to speed up and slow down.

           Mode 3: The code uses a digital counter to vary the motor speed from nothing to maximum. It faithfully did that for loop after loop. The acceleration was completely smooth, in fact smoother than most human operators could control the process.

           I placed a 100KΩ resistor across the base to see how tiny a signal the base would respond to. That resistor was too much, it effectively blocked the current to the transistor base and the circuit remained off. Next, I tried a 4700Ω resistor and it worked okay, but the motor cut off sooner during the loop. My speculation is that resistor caused the transistor to reach its lower threshold sooner.

Conclusion:
           The Arduino allows for precise control of a motor, but it is not as efficient as expected. In analog mode, there is a slight sluggishness to the response. Nobody else knew the purpose of the diode either. I would like to try other devices than a motor and sensor control in place of programming code.

           I added an LED and resistor in parallel to the supply side of the circuit. It perfectly reflected the changing current through the motor in all three situations. The LED responded much better than the motor, which makes sense because the motor is mechanical.

           Here is the code. Remember, there are three modes and you operate than by commenting out any two of the three subroutine calls in the void loop().

// Experiment 016 - Transistor Controlled Motor
// Today is March 15, 2011
// This sketch corresponds to Minutes 016 blog

/* Borrowed from "Interesting Easy Circuits",
* the Arduino Experimenter's Guide CIRC-003.
* This is my first circuit contained a transistor.
* Code is keyed in, not copied from the Internet.
*/
////////////////////////////////////////////////
//Begin Initialization & Variables

int BasePin = 9; //The transistor base lead
int vOnTime = 2500; //Motor on time in milliseconds
int vOffTime = 2000; //Motor off time in milliseconds

int vOnSpeed = 220; //Motor speed (0 - 255)
int vOffSpeed = 55; //Motor speed (0 - 255)


//End Initialization & Variables
/////////////////////////////////////////////////

/////////////////////////////////////////////////
// Begin Main Program
/////////////////////////////////////////////////

void setup()
{
pinMode(BasePin, OUTPUT);
}
//-----------------------------------------------------------------------
//Read Instructions: this program calls three different subroutines
//from the void loop(). Notice that they are selected by commenting
//out any two, leaving the third subroutine to execute.
void loop()
{
//subMotorOnOff(); //calls subroutine “MotorOnOff”
//subMotorOnOffSpeed(); //calls subroutine “MotorOnOffSpeed”
subMotorAccelerate(); //calls subroutine “MotorAccelerate”
}
//-----------------------------------------------------------------------
void subMotorOnOff()
{
digitalWrite(BasePin, HIGH); //pulls 5V to base pin
delay(vOnTime);
digitalWrite(BasePin, LOW); //pulls 0V to base pin
delay(vOffTime);
}
//-----------------------------------------------------------------------
void subMotorOnOffSpeed()
{
analogWrite(BasePin, vOnSpeed); //variable voltage to BasePin
delay(vOnTime);
analogWrite(BasePin, vOffSpeed); //variable voltage to BasePin
delay(vOffTime);
}
//-----------------------------------------------------------------------
void subMotorAccelerate()
{ //Begin subMotorAccelerate()
for (int i = 0; i <= 255; i = i + 1)
{
analogWrite(BasePin, i);
delay(50);
}
//--------------------------------------------------------------------
for (int i = 255; i >= 0; i = i - 1)
{
analogWrite(BasePin, i);
delay(50);
}
} //End subMotorAccelerate()
//--------------------------------------------------------------------

////////////////////////////////////////////////////
// END MAIN PROGRAM
////////////////////////////////////////////////////

// Key entered by Anton da Bassguy 2011
// Verified March 15, 2011.
// Corresponds to meeting minutes project 016
// and Schematic 016 - Spin Motor
////////////////////////////////////////////////////

Go BACK to Table of Contents
Diagrams: C:\Documents and Settings\Do Not Use\My Documents\8000 Series Files\8010 ARDUINO\2000 Minutes\Jpegs 2011\Experiment 016
Code: C:\Documents and Settings\Do Not Use\My Documents\8000 Series Files\8010 ARDUINO\3002 Arduino Saved Sketches\A100414_016SpinMotor