Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Error Checking Solenoid Valve Switching Mechanism

Status
Not open for further replies.

Peterold

New Member
I'm switching between 4 different sets of solenoid valves. They fill a tank, the rising water flips a float switch, it shuts off/drains the current tank, and begins filling the next. If 2 valves flip on at the same time, all of the valves shut off because the current load is too high for the arduino. In any normal circumstances there will never be 2 sets of valves on at a time, but I want to have a reset in case 2 switches flip and the system shuts off.

I can read every time a switch flips, so my idea was to have the arduino count to some time (say 30 min) and if no switches had flipped within that amount of time it would reset the process. I thought this sounded easy, but I can't seem to make it work. I'm not that familiar with arduino, and I've mostly been using if loops. Is there a function designed for this application?

Here's the code for switching solenoid valves:

if (voltage0 > 2.5) //Tank 1: If voltage is high (tank is full), arduino waits 5 sec for siphon to start. Then opens Tank 2 valve and closes Tank 1 valve.
{
delay(5000);
digitalWrite(valvePin0, LOW);
delay(3000);
digitalWrite(valvePin1, HIGH);
}

if (voltage1 > 2.5) //Tank 2: If voltage is high (tank is full), arduino waits 5 sec for siphon to start. Then opens Tank 3 valve and closes Tank 2 valve.
{
delay(5000);
digitalWrite(valvePin1, LOW);
delay(3000);
digitalWrite(valvePin2, HIGH);
}
....
 
I'm not familiar with the syntax of Arduino. However, I think you need a while loop. Something like,
Code:
unsigned int count;

// replace the ifs with this
count=0;              //reset counter
while(voltage0<2.5){
    delay(1000);     //count seconds
    count++;
    if (count>900)   //has 30 mins elapsed?
        reset;
}

Mike.
 
[Solved] I tried using the while loop, but the arduino only runs one function at a time. With the while loop going, everything else would pause and I couldn't get around that. The fix ended up being really simple. Every time the arduino would reset (when 2 sets of valves are open at the same time) it goes through the initialization process again, so I just moved the "system initiation step" to be a parameter on startup (under void setup instead of void loop) instead of something that happens inside the loop.
 
What else did it have to do so you couldn't use while. The while loop above waited for the limit switch while counting time and reseting if 30 mins had passed.

Mike.
 
Normally the arduino turns a solenoid on -> waits for the tank to fill (float switch to flip HIGH) -> turns on next solenoid and turns off previous solenoid

During the while loop's counting I wasn't able to make the arduino simultaneously look for the next float switch to flip. So the while loop would just count up to 30 min and not register when the switch flips that it should switch to the next valve. Thinking about it now, I guess I could have put a condition in the while loop to check all the float switches after every count, but I came to the above solution before I thought of that.
 
If 2 valves flip on at the same time, all of the valves shut off because the current load is too high for the arduino.
Sounds like there's something wrong with your setup. Normally, solenoid valves would be driven by power switches (e.g. MOSFETs), not directly by an Arduino (which in itself can't source or sink much current)?
 
What provides the '12V output'?
Have you got good power supply decoupling and a 'star' ground system? If not, heavy current due to the solenoids could pull down the +ve supply to the Arduino, or else could pull up the ground line of the Arduino. Either scenario could cause the Arduino to malfunction/reset.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top