Controlling a fan with a TIP120 Transistor

I am trying to control a fan using a TIP120 transitor and the fan only turns on but never off? I'm new to using arduino as well so if anyone can help explain it in a simple way that would be appreciated.

Pictures:



Code:

const int motorPin = 13; // Connect to the base of the transistor
void setup() {
 pinMode(motorPin, OUTPUT);
}
void loop() {
 // Motor speed varies from 0 (off) to 255 (full speed)
 analogWrite(motorPin, 128); // Set motor speed to half (for example)
 delay(2000); // Keep the motor on for 2 seconds
 analogWrite(motorPin, 0); // Turn off the motor
 delay(2000); // Wait for 2 seconds before the next cycle
}

Also if it's hard to see the wiring, here are the instructions I am following:

PWM (Pulse Width Modulation) setup to control the DC motor (for higher currents): use the TIP 120 NPN transistor, a 220-ohm resistor and a 1N4148 diode. Connection: the base (B) of the TIP120 to a digital pin on the Arduino (e.g., pin 9). Connect a 1kΩ resistor from the base (B) of the TIP120 to the same row where the base is connected. Connect the collector (C) of the TIP120 to the positive rail of the breadboard. Connect the emitter (E) of the TIP120 to the ground (GND) rail of the breadboard. Connect the anode of the diode to the positive rail of the breadboard. Connect the cathode of the diode to the same row where the collector (C) of the TIP120 is connected. Connect the cathode of the diode to the positive terminal of the DC motor. Connect the negative terminal of the DC motor to the ground (GND) rail of the breadboard. Connect the ground (GND) of the Arduino to the ground (GND) rail of the breadboard. Connect the positive (5V) of the Arduino to the positive rail of the breadboard. Connect the external power source to the positive and negative terminals of the motor

also- another weird thing: when I disconnect all the wires connected to the arduino and try to upload it, it works, but then if I have the wires plugged into the arduino and try to upload it, the port doesn't show up on my computer?

You've done this

tip

You undoubtedly don't know much about electronics...

1 Like
  • 13 is not a PWM pin.

  • Connect your circuit similar to B1 below (power supply voltage must match the motor).

  • Do not use the Arduino 5v pin to power motors, use an external power supply, common GND going to the Arduino GND.

Hi @humayunpi ,

I am not saying that this is the solution but you use an Arduino UNO and pin 13 with analogwrite(). That will not work.

See https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.