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?