Full disclosure, I'm a ME trying to do my best to fake my way through some electronics. I am also brand new to the Arduino board.
My project I'm working on is controlling a 110VAC solenoid valve with an Arduino Uno. I have a relay controlled by the arduino that is triggered from a float switch in a jug of water. Everything works as it should before the 110VAC is introduced.
The problem: 70% of the time that the relay is supposed to switch off the solenoid it clicks and the solenoid valve remains open. I can wiggle the solenoid wires around and eventually get the relay to switch off the solenoid but it is not consistent. (This will be used when I am not home so it needs to be as reliable as possible)
I feel as though its something fairly simple but my lack of experience is making troubleshooting difficult. Is there a voltage spike from the 110?, do I have a faulty component? Or am I missing something?
Any help or advice you could provide would be much appreciated.
Come on, no engineer of any type would just wind some wires together and pray. At least use wire nuts and then tape them for protection.
My irrigation system is nearly identical to your test system and has worked flawlessly for three years. Use a SSR, solid state relay for your mains switching.
That is common when you are playing around with mains.
What is the current rating of your solenoid and what is the current rating of the relay contacts?
Without knowing you run the risc of welding the contacts together.
Not from the 110 but from the solenoid itself. When you turn off an inductive load you get a great big voltage spike in your case probably in the order of many hundreds of volts. This also could weld the relay contacts. What you need is a snubber circuit in series with the solenoid. Look it up.
This involves high voltage non polarised capacitors which are expensive.
Let's hope you live that long because as others have pointed out your setup is lethal at the moment.
const int Float=3;
const int Valve=8;
void setup() {
// put your setup code here, to run once:
pinMode(Valve, OUTPUT);
pinMode(Float, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(Float)==LOW)
{
digitalWrite(Valve, HIGH);
delay(3000);
}
else
{
digitalWrite(Valve, LOW);
}
}
Hi, @keeks26
Welcome to the forum.
To add code please click this link;
Can you please post link to specs of your relay module and the solenoid?
A couple of images of your components and how you have them wired will also help.
Does the relay module have an LED on it to show when it is energized?
I edited my above post and replaced the screenshot with actual code.
I did some research on snubbers and found that lead times for them are 10-14 days, so I guess I will get one on order and be patient.
The relay has an led on it. This is how I knew that the sensor and Program were controlling the relay correctly. When the relay fails to shut the solenoid, I can hear it click, the led flashes very quickly then stays on until the delay comes back around where it trys to shut the solenoid off again.
I had a sort of epiphany this morning and added a 1 second delay at the end of my code so the relay can not instantly trigger again. I have cycled the solenoid about 20 times and it has worked perfectly. As of now I'm moving forward with the build as I think I have found my solution, but I don't fully understand it. The relay worked flawlessly with the original code until the external power was added. Could anyone explain to me why the external power supply required the 1 second delay at the end of my code? This may be helpful for future projects. As I stated in the original post this is my first Arduino project and maybe the delay at the end is common practice and I just missed it.
Updated Code which as of now has zero issues:
const int Float=3;
const int Valve=8;
void setup() {
// put your setup code here, to run once:
pinMode(Valve, OUTPUT);
pinMode(Float, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(Float)==LOW)
{
digitalWrite(Valve, HIGH);
delay(3000);
}
else
{
digitalWrite(Valve, LOW);
delay(1000);
}
}
True, the LED indicates whether the relay board is receiving the signal to operate the relay, but does not necessarily mean that the relay is being actually actuated if the "5V" supply is inadequate.
I see no actual indication of how your system is powered by 5 V. In particular, you cannot use "Vin" or the"barrel jack" to power it when you have devices such as relay modules connected to the "5V" pin as the on-board regulator is severely limited (no heatsink) as to how much current can be drawn before it starts to shut down.
If powering via the USB port, you can generally get away with drawing some 450 mA.
For AC, a "snubber" consists of a capacitor (rated to the AC voltage) and a (series) resistor (also suitably voltage rated, which means generally at least half a Watt).
While you can get these as a single component, it will generally be easier and cheaper to just get the separate components.
Hi,
Good that it is functioning as you want it.
How long are the wires between the UNO and the float switch?
Have you kept the float switch wiring away from the 110Vac wiring?
You are using the relay backward, using the NC contact to switch the solenoid instead of the NO. Connect the 110 to the NO contact and solenoid to COM and reverse your program logic. You also should have a snubber across the solenoid to suppress contact sparking.
const int Float=3;
const int Valve=8;
void setup() {
// put your setup code here, to run once:
digitalWrite(Valve,HIGH); // turn Valve OFF before setting to OUTPUT
pinMode(Valve, OUTPUT);
pinMode(Float, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(Float)==LOW)
{
digitalWrite(Valve, LOW);
delay(3000);
}
else
{
digitalWrite(Valve, HIGH);
}
}
The Arduino isn't a power supply. Relay coils pull current and can cause spikes when the coil is turned off. The relay module may have a snubbing diode to deal with this and the current required for a single relay probably isn't significant. Once you get into multiple-relay boards though, you may need to power the coils separately.
I wouldn't trust that SSR.
Got one like that last week and found out that the circuit board trace creep distance between mains power and Arduino is only 1.5mm. Certainly not designed to safely use with 240volt A/C.
Leo..
It's only the fuse near the opto coupler via.
Would have been easy to design the fuse layout with a lot more spacing.
Also not that hard to cut/move that fuse (looks like green through-hole resistor).
Leo..