Do you mean analogWrite? analogRead won't control the transistor. Also, the analog output is accomplished using PWM, which simulates analog using pulses. It won't actually control the current to the transistor base, but will "stutter" the current to the motor, making it run faster or slower.
We'll need some additional information.
What type of transistor are you using?
How is it connected (schematic)?
Let us see the code. Paste it in a reply, select it, and press the # button above to format it in a code block.
Using the TIP120 or TIP122 is no problem.
But you should have used used the resistor and the diode, as in the example.
Something might already be broken.
If your Arduino seems to be working, the output to the transistor might be blown. So use another output pin and use the resistor and the diode. And use also a new transistor.
Edit: the TIP127 is a PNP, we don't want that. TIP120 or TIP122 is NPP and is okay.
Try disconnecting the control wire from the Arduino and connect the base lead (with a 1k or 2.2k resistor) to the Arduino 5v to see if the transistor is working. Also, double check the wiring- you might have the transistor connected backwards.
Always use a diode across the motor to protect your transistors and the Arduino from reverse high voltage spikes.
Always use a resistor between the Arduino and the transistor base to protect the transistor.
The 127 is a Darlington PNP transistor. It's a different type - don't use that; you need an NPN like the 120, 121, or 122.
If its wired correctly, you might have a faulty transistor, or damaged it somehow.
Darlington transistors have much larger gain factors than other transistor types. The -122 has a gain of 1000+ as opposed to a 2N2222 that has a gain closer to 100. Buy a pack of small transistors from Radio Shack, or somewhere similar, and try it again. Pick up some diodes and 1k resistors too when you are there!
What you might be experiencing is the transistor amplifying noise. Disconnect the base lead again, but connect it to ground. That should stop the motor. If not, there is a different problem.
Diodes are placed backwards across the leads of inductive devices to short circuit their reverse voltage spikes when they turn off.
The electric coil develops a strong magnetic field when it is energized. When turned off, the magnetic field converts back to electricity with a reverse polarity to what generated it. This reverse voltage can damage the electronics and needs to be stopped. The backwards diode short circuits this reverse voltage back into the coil and not to the electronics.
the transistor got too hot and burnt my finger .
is it because im not using a resistor?
it was even smoking
and the funny thing is, the motor stopped with TIP122(that means everything worked), for sometime, but i dunno what happened; after a while, it was back to the same problem .
#define fadePin 9
void setup(){
pinMode(fadePin, OUTPUT);
}
void loop(){
for(int i = 0; i<360; i++){
//convert 0-360 angle to radian (needed for sin function)
float rad = DEG_TO_RAD * i;
//calculate sin of angle as number between 0 and 255
int sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
analogWrite(fadePin,sinOut);
if(sinOut==0)
delay(200);
delay(15);
}
}
im 100% sure that the code is not wrong(its too basic to go any wrong !)
Yes, the code looks fine. I even tested it myself to make sure that the sinOut variable went the full range from 0-255, which it does.
Motors have a very low resistance and require a lot of current (which is why the 3904 got so hot). This is why the project plan required the high-current Darlington transistor.
If you haven't yet - go back to your original design with the TIP-120 or -122 and make sure you include the resistor and diode. If you can, try a fresh transistor:
What’s the diode used for?
This circuit is pretty simple. This type of transistor is switched by current and not voltage, so we need to make sure to supply the correct current to the base to switch it, so a resistor is connected from the Arduino to the base to limit the current to the proper amount.
You can see that in ... illustrations, there is a diode parallel to the device we are powering. Any time you are powering a device with a coil, such as a relay, solenoid, or motor, you need this guy, and don’t leave home without it. What happens is when you stop powering the coil, a reverse voltage, up to several hundred volts, spikes back. This only lasts a few microseconds, but it is enough to kill our transistor. So this diode (only allows current to pass one way) is normally facing the wrong direction and does nothing. But when that voltage spikes comes flowing the opposite direction, the diode allows it to flow back to the coil and not the transistor. We will need a diode fast enough to react to the kickback, and strong enough to take the load. A rectifier diode like the 1N4001 or SB560 should do the job. If you are looking for extra protection you could use an optoisolator between the Arduino and the transistor. An optoisolator optically isolates both sides (high and low power) of the circuit so the high-voltage can not possibly come back to the microcontroller.
Just make sure that protection diode is facing the correct way (stripe facing the V+ of device). If it is facing the wrong direction, the device you are trying to power will not work as the diode will just allow the current to bypass it.