Arduino controlling 2 x 12Vdc Solenoid valves

Hello!
I have this project where I have 2 solenoid valves powered by a 12Vdc power supply and I want to control them with an arduino nano supplied by that same 12Vdc and a relay. I also added some 1N4001 Flyback diodes to the valves, but I am having a problem. Once I connect the 12Vdc power supply the valves open at the same time during 5 seconds and close during 5 seconds as programmed but as time passes the valves open and close faster and faster until I have to disconnect them, this happens in less than a minute. If I power the arduino and the valves from different power supplies this does not happen but I would like to use only the 12Vdc if possible, how can i solve this problem?
Here is a picture and the code I am using:


const int openTime = 5000;
const int closedTime = 5000;

void setup() {


CODE:
  
  pinMode(3, OUTPUT);

}

void loop() {

  digitalWrite(3, HIGH);   
  delay(openTime);             
  digitalWrite(3, LOW);    
  delay(closedTime);              

}


one 10k resistor between signal pin of relay module and GND, otherwise pin is like antenna - receives EMP.
for both pins

Hello @kolaha I added the 10k resistor as in the picture and the setup behaved in the same way...

i said both pins

is it correct?
зображення

is module active LOW?

Pin S1 is not being used, but I will place a resistor too, and try again. The pins are written correctly.

try instead of GND connect to +5V too

Pin S1 is not used, but relay is powered

Same results with this configuration:

i know.


it is active LOW, so resistors should be between S and +5V.
and show where you connect S on Arduino board

I tried this configuration now, but with the same results... The S pin is connected to Digital pin 3


pull jumper on module out

the relay stops working if I pull out the yellow jumper.

If you are powering the Nano with 12V through the VIN pin then pulling relay current through the 5 volt regulator, it may be overheating and causing resets.
The relay module needs a separate 5 volt supply.

Will a step down converter do the job?

yes. connect extern 5V to RY-VCC pin. don't install jumper in this case

Yes but make sure it's wired correctly, remove the Vcc - JDVcc jumper, separate 5V+ to JD-Vcc pin, separate 5V- to GND on relay board, no connection from Arduino GND to relay.
6m95zlV

Ok, it is not working I guess there is something wrong with the wiring. Here is a picture of the wiring on the relay module and a schematic of the wiring right now.


Connect all the GND's up with each other.

I just checked continuity and they actually are all connected together.

Did you connect the Arduino Vcc (5V) pin to the relay board Vcc pin?
Look at the picture I posted.

I forgot to conect it, but just did it. But now it opens and closes the really 2 times and then stops. The difference I have is the GND of the arduino is also connected to the GND of the relays through the Step down converter...