I'm using Arduino UNO, and I need to control 24VAC motor via serial port.
I have relay board with 2 opto-isolated relays and separate 5V PS to trigger them, those two relays are controlling AC motor (CW and CCW).
I'm using Arduino Serial monitor to send commands to arduino, as follows: 1 - CW , 2 - CCW , 3 - turn off motor.
Sometimes everything works great for hours, but at random serial port just freezes and TX light stays on.
I need to restart PC or unpplug arduino to make it work again.
I think there is some problem in code, because all wires are "clean and separated(shielded).
You need to put all the stuff about responding to serial command inside the if-statement,
otherwise it'll just repeat the last command indefinitely. incomingByte should be local
to the if:
int ccw = 8;
int cw = 9;
void setup()
{
Serial.begin(9600);
pinMode(ccw,OUTPUT);
pinMode(cw,OUTPUT);
}
void loop()
{
if(Serial.available() > 0)
{
int incomingbyte = Serial.read();
if(incomingbyte == '1'){
if (digitalRead(ccw) == HIGH){
digitalWrite(ccw,LOW);
}
delay(100);
digitalWrite(cw,HIGH);
}
if(incomingbyte == '2'){
if (digitalRead(cw) == HIGH){
digitalWrite(cw,LOW);
}
delay(100);
digitalWrite(ccw,HIGH);
}
if(incomingbyte == '3'){
if (digitalRead(cw) == HIGH){
delay(100);
digitalWrite(cw,LOW);
}
if (digitalRead(ccw) == HIGH){
delay(100);
digitalWrite(ccw,LOW);
}
}
}
}
Can't see obvious problem that would jam the serial line, could be software related
on the PC, could be hardware related (running the serial cable near other wiring)
MarkT:
You need to put all the stuff about responding to serial command inside the if-statement,
otherwise it'll just repeat the last command indefinitely. incomingByte should be local
to the if:
if(incomingbyte == '3'){
if (digitalRead(cw) == HIGH){
delay(100);
digitalWrite(cw,LOW);
}
if (digitalRead(ccw) == HIGH){
delay(100);
digitalWrite(ccw,LOW);
}
}
}
}
Can't see obvious problem that would jam the serial line, could be software related
on the PC, could be hardware related (running the serial cable near other wiring)
Unfortunately, same thing happens even with this code..
I'm using latest Arduino IDE,.
I was thinking to put 1N4007 diode to motor power supply, but I'm not sure how to wire it.
AC motor has three wires, one is common and other two's are connected to 25VAC (I'm switching phase(direction-CCW,CW) with capacitor on those two wires).
Where should I put diode, or eventually 0.1uF capacitor?
Thanks.
You will not find a 100uF cap capable of working at mains voltage.
You do not need diodes.
Fit a small capacitor 0.1uF as close to the motor terminals as possible.
You might want to look at snubber circuits that include inductors and capacitors that make the phase not so disruptive.
You can also try winding some of the wiring through ferrite rings.