Valve connected to Arduino causing acquisition problems

First, a brief explanation about the project:
I have 6 LDR aligned with 6 LED. An object passes between them and the intensity of light received by the LDR decreases. This variation is acquired through analog pins A0-A6. The solenoid valve pushes the object between the LDRs/LEDs, digital pin 4 is turning the valve ON/OFF. I’m also measuring room conditions with a HTU21D sensor (image attached). The instructions are given in python through pymata and firmata.

The problems are (image attached to show what I mean):
-The acquisition rate starts to fail. The system should always acquire at about 64Hz. But sometimes the time period between readings is not the same.
-The HTU21D sensor starts to give 999 reading (CRC is bad) when the solenoid valve is ON and after a while it gives 999 reading continuously.
If I remove the valve+relays from the circuit, the problems disappear.

I read (here) that solenoid valves can cause troubles, and that they should be powered independently from the rest od the circuit. So:
-The LDR, LED and HTU21D circuits are being powered by Arduino’s GND / 5V.
-The valve is connected to a 24V power supply.
-The relay is being powered by a independent power supply. Basically I removed the jumper and connected the GND / JD-VCC pins (before, I had the relay connected to the Arduino’s GND / 5V, I changed it after reading the link above).

I also read (here) that a flyback diode should solve the problem, but the board where I have the relays (here) already has a diode as well as an opto isolation circuitry, which gives electric isolation (here).

All the links to solutions where of problems with the Arduino restarting whit the valve. In this case, the Arduino does not restart, so it is probably not the same problem, but it was the most similar thing I found.

I also tried ferrite beads (image attached of what I could find), between the relay COM and the valve like they did with this lamp: here

The problems persist :confused: . Any ideas?

Thank you in advanced.

Can you please describe the point in developing your project where you FIRST encountered the problem? What was the last change you did that began the problem?

Paul

Before, I pushed the object manually. The system was the same but with no relay and no valve. Acquisition was fine.

But I wanted to push the object in an automatic way, so I put a valve that controls an air flux that pushes the object when pin 4 is HIGH.
When I added this part (valve + relay) acquisition started to fail.

alve:
Before, I pushed the object manually. The system was the same but with no relay and no valve. Acquisition was fine.

But I wanted to push the object in an automatic way, so I put a valve that controls an air flux that pushes the object when pin 4 is HIGH.
When I added this part (valve + relay) acquisition started to fail.

Ok, please confirm we are still at the point you just described.

Do you have ALL the 24 volt wires and all the wires controlling the relay placed as far as possible from the wires to the sensors?

Paul

Ok, please confirm we are still at the point you just described.

Yes, I confirm.

Do you have ALL the 24 volt wires and all the wires controlling the relay placed as far as possible from the wires to the sensors?

No, they are very close. How far should they be from each other?

alve:
Yes, I confirm.

No, they are very close. How far should they be from each other?

AS FAR AS PHYSICALLY POSSIBLE! And twist the ground and + wires together using about 1 tern per inch.

Paul

Do you have a diode across the VALVE COIL?

AS FAR AS PHYSICALLY POSSIBLE! And twist the ground and + wires together using about 1 tern per inch.

IT WORKED! THANK YOU! I don't have much space to keep things away, but managed to find enough to solve the problem. Since I have space constraints, is there any other way to avoid this problem?

Do you have a diode across the VALVE COIL?

I'm not sure where the coil in the valve is :blush: never worked with a valve before.

alve:
IT WORKED! THANK YOU! I don't have much space to keep things away, but managed to find enough to solve the problem. Since I have space constraints, is there any other way to avoid this problem?

I'm not sure where the coil in the valve is :blush: never worked with a valve before.

Putting the power wires in grounded metal conduit will also solve the problem and then you don't need twisted wires.

Paul