Arduino hangs/resets sometimes when setting a pin HIGH

I'm trying to control an external motor. To turn the motor on, I have to send a 5V (HIGH) signal to a pin. This triggers a relay inside the machine which starts/stops the motor (powered over a separate 24V source).

The problem is: simply setting the pin HIGH causes my Arduino to behave erratic. Most of the time I can turn on/off the motor, but in about 20% of all cases either 1: the Arduino hangs at a certain point or 2: the Arduino resets itself. This seems to happen without reason.

The grounds are connected. My code is working fine. So I suspect "something" happens when putting the pin HIGH.

Some people told me probably the relay is taking over 20ma from the Arduino port, causing the erratic behaviour.

My questions:

  1. could this be the case? can a relay pull over 20ma just to "flip" on or off?
  2. How can I resolve this problem? Can I add a resistor somewhere?
  1. Yes, you might try to measure it with a scope / multimeter
  2. you could add a mosfet to control the relay

Check these