I am working on an automated dispensing project where I intend to control ten different 12V 600mA DC pumps with an arduino. A computer transmits messages over usb connection to the arduino in the following form:
lh = pumps off
0h = pump 0 on
1h = pump 1 on
etc.
The arduino gives power to the pumps by activating a TIP120 npn resistor connected to a 12V 2A DC power supply. Only one pump will be running at any given time.
When I test this by powering LEDs, the serial connection works flawlessly. However when I try it with a pump, the arduino begins to respond sluggishly to commands, and eventually I lose serial connection with the arduino. I can only imagine that there is some sort of power issue causing the arduino to lose connection. Any ideas where I am going wrong?
Arduino Code:
#define PUMP5 5 //pin for turning transistor on/off
const byte numChars = 32;
char msg[numChars];
void setup()
{
Serial.begin(9600,SERIAL_8N1);
Serial.println(msg[0]);
pinMode(PUMP5, OUTPUT);
}
void loop()
{
read_msg();
command_pumps();
}
void read_msg()
{
char rc;
if (Serial.available() > 0) {
rc = Serial.read();
msg[0] = rc;
}
if(Serial.available() > 0) {
rc = Serial.read();
msg[1] = rc;
}
Serial.print("msg[0]: ");
Serial.println(msg[0]);
Serial.print("msg[1]: ");
Serial.println(msg[1]);
}
//PUMP5 is used for each of the scenarios since I am only testing with one pump
void command_pumps(){
if (msg[0] == 'l'||msg[1]=='l')
{
digitalWrite(PUMP5, LOW);
}
else if (msg[1] == 'h')
{
if(msg[0]=='0')
digitalWrite(PUMP5, HIGH);
else if (msg[0]=='1')
digitalWrite(PUMP5, LOW);
else if (msg[0]=='2')
digitalWrite(PUMP5, HIGH);
else if (msg[0]=='3')
digitalWrite(PUMP5, HIGH);
else if (msg[0]=='4')
digitalWrite(PUMP5, HIGH);
else if (msg[0]=='5')
digitalWrite(PUMP5, HIGH);
else if (msg[0]=='6')
digitalWrite(PUMP5, HIGH);
else if (msg[0]=='7')
digitalWrite(PUMP5, HIGH);
else if (msg[0]=='8')
digitalWrite(PUMP5, HIGH);
else if (msg[0]=='9')
digitalWrite(PUMP5, HIGH);
}
return;
}
