Arduino Restarting when firing relay

Hello All - I have a project I have been working on for sometime. I finally got it to the test phase and everything worked fine except I had relay chatter on startup. So on startup, the pin 13 relay would chatter and intern fire a solenoid valve on and off. This is a bottling machine and this might make a real mess so after reading that pin 13 should not be used, I moved my relay wire from pin 13 to pin A3 (17). Since it is a complicated project I have written mini programs to test each piece of hardware. After moving the relay to pin 17, when I power up the arduino, the relays go high as programmed. Then when I tell them to go low, they do. Then when I tell them to go high, they go high and then the arduino resets. I am using an arduino pro mini 3.3v board with the relay. I have 5v hooked to the JD-VCC connection with the jumper removed. I commented out 3 of the 4 relays each respectively to test that way and still the same result. The funny thing is it worked with pin 13. I do not have mosfets or transistors between the arduino and the relay. But it did work before I moved the pin. Any help would be appreciated.

Anthony

relay
http://yourduino.com/sunshop//index.php?l=product_detail&p=201

Relay wiring:

Pin 17 to relay in 1
Pin 14 to relay in 2
Pin 15 to relay in 3
Pin 16 to relay in 4
VCC 3.3v from arduino to relay VCC in next to relay in 4
grd to grd - not isolated so not fully opto isolated
JD-VCC 5v from 5v supply with jumper removed

int IN_PIN = 17;
int IN_PIN_A = 14;
int IN_PIN_B = 15;
int IN_PIN_C = 16;
void setup() {
  pinMode(IN_PIN, OUTPUT);
  pinMode(IN_PIN_A,OUTPUT);
  pinMode(IN_PIN_B,OUTPUT);
  pinMode(IN_PIN_C,OUTPUT);
  digitalWrite(IN_PIN, HIGH);
  digitalWrite(IN_PIN_A,HIGH);
  digitalWrite(IN_PIN_B,HIGH);
  digitalWrite(IN_PIN_C,HIGH);
  Serial.begin(9600);
  delay(1000);
  Serial.println("Enter 1 to turn on lamp, 0 to turn off"); 
}
void loop() {
   while (Serial.available()) {
    char inChar = (char)Serial.read();
    if (inChar == '1') {
     digitalWrite(IN_PIN, HIGH);
     digitalWrite(IN_PIN_A,HIGH);
     digitalWrite(IN_PIN_B,HIGH);
     digitalWrite(IN_PIN_C,HIGH);
      Serial.println("Lamp is Off!");
    }else if(inChar == '0'){
      digitalWrite(IN_PIN, LOW);
      digitalWrite(IN_PIN_A,LOW);
      digitalWrite(IN_PIN_B,LOW);
      digitalWrite(IN_PIN_C,LOW);
      Serial.println("Lamp is On!");
    }else{
      Serial.println("Invalid input!");
    }
  }
}

Show us a good schematic of your circuit.
Show us a good image of your wiring.
Give links to components.
Posting images:

FYI

To prevent relay chatter on startup, you must write a HIGH to the pin BEFORE you set the pin to OUTPUT.

void setup() {
  digitalWrite(IN_PIN, HIGH);
  digitalWrite(IN_PIN_A,HIGH);
  digitalWrite(IN_PIN_B,HIGH);
  digitalWrite(IN_PIN_C,HIGH);
  pinMode(IN_PIN, OUTPUT);
  pinMode(IN_PIN_A,OUTPUT);
  pinMode(IN_PIN_B,OUTPUT);
  pinMode(IN_PIN_C,OUTPUT);

Relay VCC needs 5volt for reliable switching, even with a 3.3volt Arduino.
5volt on relay VCC is ok for a 3.3volt pin, because of the ~3volt internal drop of the opto LED and indicator LED.
How is the 3.3volt ProMini powered.
And what are you switching. Are you using snubber circuits (AC) or diodes (DC) on the contacts/loads.
Leo..

On many Arduinos pin13 has an opamp driving the led, or used to (haven't bought a board in a while now).

GoForSmoke:
On many Arduinos pin13 has an opamp driving the led, or used to (haven't bought a board in a while now).

Small boards (ProMini) don't have that opamp, only the bigger ones do.
And some Arduinos flash that LED during bootup.
Best to avoid pin13 if you don't fully understand the board you're using.
Leo..

Thanks for the replies everyone. I am driving a solo kid valve directly from the relay contacts. No snubber or anything. The Arduino is driven by 5v to the raw pin from a 7508 circuit with some filtering. That same 7805 circuit is driving the rally vcc next to the fd pin with no jumper. I do have 3.3v going to the vcc from the Arduino next to relay in pin 4. No do have an 817 opto coupler that I could put inbetween the Arduino and the relay.

Anthony

Last time.

Show us a good schematic of your circuit.

Show us a good image of your wiring.

Give links to components.

Posting images:

Please see attached the images and a rudimentary image of the wiring.Scanned_from_a_Lexmark_Multifunction_Product08-16-2019-134648.pdf (256 KB)

Scanned_from_a_Lexmark_Multifunction_Product08-16-2019-134648.pdf (256 KB)

pic1.jpg

pic2.jpg

pic3.jpg

Could there be too much draw on the arduino? Would this cause a rest? I had everything working until I decided to move a relay off of pin 13. As I was wiring the project, I tested each part of the system. A small program to test the switches, the oled, the relay, the load cells. I them put it all together and was able to get the machine working. I them moved the really off pin 13 o A3 (17) and retested with the simple relay program above and the arduino now resets every time the relays fire high except for the HIGH fire in the void setup section.

Anthony

pic1.jpg

pic2.jpg

pic3.jpg

links to products

mini pro - 3.3v

relay

solonoid valve 12v

7805 regulator

switch (4 pcs)

load cells (4 1 kg)

potentiometer

couple of caps
12v 3 amp wall wort i had around

Thank you for suppling the needed information!

As alluded to by Wawa, a 3.3v Arduino is going to difficult time picking your 5v relay.

On the relay board, there are two LEDs in series with the signal from the Arduino.

If these LEDs have a forward voltage of 2v (4v total) the Arduino 3.3v output voltage will have difficulty in operating your relays :wink: .

JD-VCC has to be connected to 5v.

Get a 5v Arduino.

Wire the new Arduino as shown in the post #1.

Add a reversed biased snubbing diode across your external 12VDC solenoid.

Clean up your wiring too, keep inductive load wires away from the Arduino and the wiring going to it.

Highly suggest you use an isolated 12v solenoid power supply.

FYI

Larry - I do have 5v connected to the jd-vcc.

When I run the script with the relays set to high all the relay leds are off. When I send them low, all turn off, when i then send them high, they turn off, the first part of the serial print show on the screen and then the arduino resets.

If I set the relays to low in the setup, all leds are red and then if i tell it to go high, they go high and the first part of the serial goes to the screen and then it resets. I find it strange that I do not get a continual reset condition happening when the void setup turns everything high.

are these the leds you are talking about? I do not see any other leds on the board.

I can definitely put a 5v board in but man that is a lot of soldering. can i do something with this 817 board?

https://www.google.com/search?q=817+optocoupler+shield&rlz=1C1CHBF_enUS733US733&oq=817&aqs=chrome.3.69i57j0j69i59l2j0j69i65.3392j0j4&sourceid=chrome&ie=UTF-8

or a few transistors or mosfets i have at home?

"Larry - I do have 5v connected to the jd-vcc. "

I was referring to the drawing in your post#8, it doesn't show the VD-VCC connection :wink: .

"When I run the script with the relays set to high all the relay leds are off. When I send them low, all turn off, when i then send them high, they turn off, the first part of the serial print show on the screen and then the Arduino resets."

Our point is you are running the hardware with less voltage than required for proper operation. You will run into problems, possibility intermittent problems if you do not use a 5V Arduino.

"If I set the relays to low in the setup, all leds are red and then if i tell it to go high, they go high and the first part of the serial goes to the screen and then it resets. I find it strange that I do not get a continual reset condition happening when the void setup turns everything high."

You appear to have a power supply problem. You must use an appropriately rated 5V external power supply to power the relay coil (sounds like your simple 7805 is not doing the job). And yes you still need to use a 5v Arduino to get 0-5V output levels.

"are these the leds you are talking about? I do not see any other leds on the board."

On your relay PCB, one LED is inside the opto-coupler itself, the other LED will be one of the 4 indicator LEDs.
See image below:

And just so you didn't miss what was being said, the 12VDC solenoid p.s. should be isolated from the other power supplies.

Summary, you need:

  1. New 5V Arduino 'with it's own' 5V isolated power supply.

  2. 12VDC solenoid, isolated power supply.

  3. New 5V relay coil, isolated power supply.

You could used the 12VDC power supply to generate the external 5V relay coil power supply.

Lots of adjustable buck converters on eBay, ~$4.00.

Thank you for the information. I will start working on it. I do have a question about power supply isolation. I tried googling it but have not quite figured it out. Do I need two seperate power supplies? One at 12v and one at 5v? At some point in the wall wiring are they not isolated again?

“Do I need two seperate power supplies?”

Yes

As long as the power supplies do not have their GND (0v) lines connected to earth ground they will be isolated from each other.

A DVM can be used to confirm there is no connection the earth.

You will need a 5 volt power supply for the 5v Arduino.

You will need a 12 volt power supply for the solenoid.

The 12v power supply output can be sent to a buck converter (adjust to 5v out) then connect the buck converter to
JD-VCC and GND on the relay card. Note this is not be ideal, but will work. If a buck converter is ‘not’ used get a second 5v power supply dedicated to the relay coil terminals of the relay card.

will do - thank you for all the help