Relay shield lock up when connecting a motor.

Hi!

I have an Arduino Uno and a relay shield described here: Relay_Shield_for_Arduino__SKU_0144_-DFRobot

I have a small progam that allows me to switch a relay on an off like so:

void setup()
{
  pinMode(2, OUTPUT);      // sets the digital pin as output
  Serial.begin(9600);
}

void loop()
{
  if(Serial.available() > 0)
  {
    byte readbyte = Serial.read();
    
    if(readbyte == 49)
    {
        digitalWrite(2, HIGH);
    }
    else if(readbyte == 50)
    {
        digitalWrite(2, LOW);
    }
  }
 
  delay(100);
}

If I send the ASCII value 1 (decimal 49) to the arduino, the relay switches on. If I send the value 2 (decimal 50) the relay switches off. This works perfectly when the relay does not power anything. I hooked up a small motor to relay 1, powered by four 1,5 volt batteries (ie. 6 volts) and that is when things started falling apart.

The motor starts when the value 1 is sent to it, but after that the program becomes unresponsive. If sending the values through the arduino IDE I get a Java.io.exception when trying to send the value 2 to stop the motor. I have to disconnect the arduino and reconnect it to gain access to it again. Sometimes (about every other time) the relay shield automatically switches the power of the motor off after a few seconds (even when not sending the value 2), and sometimes the motor keeps running until I disconnect power to the arduino.

Any ideas what might be wrong? Is the relay shield defective, or am I doing something wrong?

Just for the record, running the example code found in the wiki article above works correctly. The motor switches on and off every second. The problems seem to be related to receiving stuff from the serial port while running the motor. I have not had any problems with the serial port with this arduino before.

EDIT: Just tried with another relay on the shield. Same thing... :frowning:

Can you post a schematic? I suspect you have some connection or connections between the switched circuit (battery, relay contacts, motor) and the main circuit, and that is causing the problem.

I am really a newbie when it comes to electricity and circuits, but this is basically my setup:

  1. The relay shield connected directly onto the arduino (obviously)
  2. A 9v DC battery plugged into the relay shield (black to GND, red to 9V)
  3. A cable directly from the motor battery pack (black) to the motor
  4. A cable from the motor battery pack (red) into NO1 on the relay shield. (NO stands for "normally open" AFAIK)
  5. A cable from the motor COM1 to the other pole on the motor.

Do you see any problems with this?

That sounds good to me. Keep the motor and motor battery pack some distance away from the Arduino and relay shield, and preferaby twist the 2 wires that go to the NO and COM terminals of the relay around each other until they are some distance from the shield and the Arduino. This will help avoid transient currents in the motor circuit inducing signals in the rest of the system.

Thanks for the tips. I did as you asked, and I now have a pretty long cable between the relay and the rest of the circuit, but the same thing keeps happening. I don't know if this is relevant, but if I disconnect one battery but keep the circuit connected to the relays, everything seems to work (but the motor does not start obviously). It seems to be more random now though. I can usually start and stop the motor a few times if I do it fast enough, but keeping the motor running for more than say two seconds always makes the program stop responding to commands.

You could try to eliminate the interference which the motor may generate by soldering a capasitor from each motorterminal to the case of the motor, and further on capacitor between the legs.

A capasitor of 47nF should do it.

OK, if it's running the motor that causes the problem (rather than switching it on and off), then you need to reduce the interference generated by the running motor. A capacitor connected directly across the motor terminals will probably fix it, otherwise try Erni's suggestion of 3 capacitors. You may need to use more than 47nF.

Thanks guys, I will try with a capacitor.