我正在一個自動化點膠項目,我打算控制十個不同的12V 600mA直流泵與Arduino。一種計算機在以下形式的USB連接到Arduino發送消息:控制電機與Arduino串行連接使用電腦
lh = pumps off
0h = pump 0 on
1h = pump 1 on
etc.
阿爾杜伊諾通過激活連接到12V 2A直流電源TIP120 npn型電阻器提供了電源泵。在任何給定時間只有一臺泵將運行。
當我通過爲LED供電進行測試時,串行連接完美無缺。然而,當我嘗試使用泵時,Arduino開始對命令做出遲鈍的反應,最終我失去了與Arduino的串行連接。我只能想象,會有某種權力問題導致Arduino失去聯繫。任何想法,我錯了?
Arduino的代碼:
#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;
}
你在電源上做了什麼?它有足夠的容量嗎? – barny
可能是二極管放置。請參閱https://electronics.stackexchange.com/questions/31014/where-should-i-put-the-kickback-diode-in-a-transistor-switch –
您能向我們展示該圖嗎?聽起來就像你在這裏丟失了適當的反激式二極管。 – user3411864