Arduino is resetting when i switch off the relay - LINUX user

Hello Arduino community!!!

This is my first time posting on forum. So please excuse me for everything i do wrong.

I use Linux for programming my ArduinoUno. I've connected it with an 8-channel relay module and i try to control it using serial port. Every time i switch off the relay (after 2 or 3 times) the arduino resets. I'm not sure if this the right word, but technically the port name changes and i can't send data through serial port anymore and i have to change the code for renaming the port (eg from /dev/ttyACM0 to /dev/ttyACM1). I used extra diodes that i correctly soldered and, as far as i know, when i switch off the relay, an opposite current is created and i tried to prevent it from reaching arduinoUno. It didn't work...The strange thing is that Windows doesn't do that and everything works just fine. Any suggestions???

Linux version:
Distributor ID: Ubuntu
Description: Linux Lite 3.8
Release: 16.04
Codename: xenial

My code:

#define RELAY1 8
#define RELAY2 9
#define RELAY3 10
#define RELAY4 11
#define RELAY5 12
#define RELAY6 13

void setup() {

pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
pinMode(RELAY3, OUTPUT);
pinMode(RELAY4, OUTPUT);
pinMode(RELAY5, OUTPUT);
pinMode(RELAY6, OUTPUT);
digitalWrite(RELAY1, HIGH);
digitalWrite(RELAY2, HIGH);
digitalWrite(RELAY3, HIGH);
digitalWrite(RELAY4, HIGH);
digitalWrite(RELAY5, HIGH);
digitalWrite(RELAY6, HIGH);
void loop() {
if(Serial.available()){ //id data is available to read

char val =;

if(val == 'a'){ //if r received
digitalWrite(8, LOW); //turn on red led
if(val == 'b'){ //if b received
digitalWrite(9, LOW); //turn on blue led
if(val == 'c'){ //if y received
digitalWrite(10, LOW); //turn on yellow led
if(val == 'd'){ //if y received
digitalWrite(11, LOW); //turn on yellow led
if(val == 'e'){ //if y received
digitalWrite(12, LOW); //turn on yellow led
if(val == 'f'){ //if y received
digitalWrite(13, LOW); //turn on yellow led
if(val == 'w'){
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(12, HIGH);
digitalWrite(13, HIGH);

p.s. The code is simple for testing perposes and i only use 6 relays.

How do you connect things? (Where are you taking the relays power?)

In most cases with 2 or more relays it turns out to be a voltage / current issue with people trying to draw too much from the limited supply of the Arduinos.

Most people fix that with seperate power rails for the relays and then just a common ground back to the Arduino.

I would agree with vffgaston in that you need to supply a schematic even if it is hand drawn as it sounds like you are tripping the voltage regulator in some way which will in turn reset the board.

I didn't do any complicated connections. Just standard connections, specifically:

Arduino ------->> 8 channel relay Module
5v pin VCC
pins 8-13 in1-In6

I only use 6 relays. So, i power the module directly from ArduinoUno. The problem remains even when i haven't connected any device (eg lamp) to relay module. But i still can tell there is a problem, thanks to the red light that every relay has next to it, which stops responding to serial send. And also Arduino ide sends error.

So your suggestion is to give another power source for the relay module and not the arduinoUno. Am i right?

Yup, that's the correct course of action.

I usually default 2A USB chargers, and those micro USB connector breakouts from ebay. You would connect the 5v from that to the relay module, and the ground to relay module ground, which must also be connected to arduino ground.

So your suggestion is to give another power source for the relay module and not the arduinoUno. Am i right?

Yes. Be careful on connecting grounds, for you need the optocoupler input to be referenced to the arduino. Better if you send a link to the board (or picture).

I used a usb cable from an old computer mouse, which i connected to pc, to power the 8-channel relay module . The same problem remains even though the port changed after a large amount of time (when i powered the relay module from arduino, after 4-5 turn on/off, the port was changing. Now same thing happened after 1 minute). I had started to believe that the problem was gone. I did some tries to send data through serial port without connecting anything else to arduino and there was no prblem. Also there was to problem when i connected the arduino Uno just with the relay module. But the problem started when i also connected the relay module with a lamp (I am not sure if that really is the case or it just happened). I really thought for a while, that the problem was gone... :frowning:

The maximum output from a USB port is normally 500 mA
You might be pushing that limit with 8 relays and be prone to drop outs while the USB resets itself.
That may also affect the USB for the Arduino if it is connected to the same computer.

If you look at the top of the relay you will see the specification for it which you can reference on the internet for its load.
Add to that a small amount extra for switch on surge and other overheads.

I presume that even with the USB power for the relays you also added a SHARED GROUND back to the Arduino ?

I noticed your post because I have a similar problem.

However in my case the relays are not connected to the Arduino at all, but share the same 12 volt (large batteries) supply. The power to the relays is sharing the same wiring loom and run as analogue inputs to the Arduino over a distance of some 5 metres.

One relay powers the stop solenoid on a diesel engine, and the other relay activates the starting motor. Either will reset the Arduino.

I have reduced, but not obviated the problem by wiring a large electrolytic across the power supply close to the Arduino. That, by the way, takes a stabilised 7.5v supply to Vin derived from the 12 volt batteries, with an electrolytic across the power supply (Vin).

Rather than diodes in the relay supply, you could try a 0.1 uf capacitor in series with a 100 ohm resistor directly across the relay coil. I have not yet tried that in my case. I used to do that to suppress radio interference caused by motors in rc projects.

it's a long time since I was at school, college, but you will get a slow build up of current into the relay as it is switched on, followed by a negative spike that decays as it is switched off. Someone else can correct me. It is possibly that spike that is doing the damage and resetting the Arduino.