I'm using a 240v relay to control the motor from a coffee grinder. Everything is connected correctly. The relay turns on and off when the motor is unplugged and the motor turns on when it is plugged in, but once the motor starts I lose serial communication with the Arduino. After restarting the Arduino, everything works.
This is the error that the serial monitor gives me when the Arduino stops responding:
Error inside Serial.serialEvent()
java.io.IOException: Bad file descriptor in nativeavailable
at gnu.io.RXTXPort.nativeavailable(Native Method)
at gnu.io.RXTXPort$SerialInputStream.available(RXTXPort.java:1532)
at processing.app.Serial.serialEvent(Serial.java:215)
at gnu.io.RXTXPort.sendEvent(RXTXPort.java:732)
at gnu.io.RXTXPort.eventLoop(Native Method)
at gnu.io.RXTXPort$MonitorThread.run(RXTXPort.java:1575)
Does anyone know why activating the relay would kill the serial port, but nothing else?
Are you possibly drawing too much current from the Arduino board when the relay is engaged ? This will reset the Arduino board and of course also kill serial communication.
Another possibility is that electric noise from the relay / motor is messing up the serial communication.
When you say the board will reset due to having too much current drawn from it, are you referring to the USB fuse which protects the computer or something else?
Once the connection is lost, I can't reestablish it until I manually reset the Arduino, i.e. by unplugging it from the USB port and plugging it back in. Would this not indicate that the board isn't simply resetting, but undergoing some other problem?
Additionally, the motor doesn't stop. If the board were to reset, it should turn the relay off and kill the motor once it restarts. Instead, everything continues to operate, but the Arduino refuses all serial communications.
I haven't tested for noise yet, but does any of this behavior point toward a clear solution?