Hello all!
I'm trying to control power to a 12V pump from a 12V DC source using a TIP120 transistor with Arduino Nano setting the Base pin Low/High. The 12V DC source is also supplying power to the Nano via the Vin pin.
I've written some code that should toggle the pump on when a button is pressed. But when I power up the circuit, the pump stays on regardless.
Is my TIP120 component getting fried? I have tried several and all meet the same fate. Could someone please spot the error(s) in my circuit? Please find the code below and the wiring diagram attached.
int btRxPin = 2;
int btTxPin = 3;
int whiteLedPin = 4;
int blueLedPin = 5;
int pumpPin = 6;
int buttonPin = 7;
bool buttonState;
bool blueLedState;
bool pumpState;
void setup() {
pinMode(whiteLedPin, OUTPUT);
pinMode(blueLedPin, OUTPUT);
pinMode(pumpPin, OUTPUT);
pinMode(buttonPin, INPUT);
digitalWrite(blueLedPin, LOW);
digitalWrite(pumpPin, LOW);
Serial.begin(9600);
Serial.println('BUTTON\tBLUE LED\tPUMP');
}
void loop() {
// turn on pump and blue LED if button is pressed
button_pump_control();
delay(200);
}
void button_pump_control() {
// check if the pushbutton is pressed
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
// turn blue LED on
digitalWrite(blueLedPin, HIGH);
// turn pump on
digitalWrite(pumpPin, HIGH);
}
else {
// turn blue LED off
digitalWrite(blueLedPin, LOW);
// turn pump off
digitalWrite(pumpPin, LOW);
}
blueLedState = digitalRead(blueLedPin);
pumpState = digitalRead(pumpPin);
Serial.print(buttonState);
Serial.print('\t');
Serial.print(blueLedState);
Serial.print('\t');
Serial.println(pumpState);
}