Turn pump 1 on until it has drained 15% of water out of my fish tank, then turn on pump 2 to refill the tank with 15% of water. I am using a ultrasonic sensor to give me the percentage value.
I can get the two pumps to turn on at the given value, but they are doing it at the same time. This means that they would never drain or fill the tank because there on at the same time.
I hope I have explained this enough lol.
Any advice or help would be great.
I have tried switch statements but not sure if have coded them correct.
You will use this to turn on and off the pumps. Easy to use.
So you have an on/off switch to turn pump #1 on.
Pump #1 runs drains water
Sensor detects water at the 15% level (no idea what sensor you are using here)
Sensor input to arduino changes. Program detects it.
Turn drain pump off.
Turn filler pump on.
Water fills.
SECOND sensor detects water is filled.
Turn pump #2 off.
Thats the basic flow. There is some complexity here in that sensor #1 is gonna keep going off until the water is above %15. But you can solve that problem later
Yes I have the relays to control the pumps I have the 2 channel but am sure there the same?
The sensor I am using is HC-SR04.
I am using the sensor as the switch to turn the pumps on/off.
I want pump 1 to turn on when I push a button to start the cycle, that starts the drain pump. This pump takes out 15% of the water then stops.
Pump 2 should then start and refill the 15% of the water and stop.
The program should then go back and wait till the button is pushed to start the cycle again.
The problem I am having is the two pumps are both seeing the same value from the sensor at the same time so both turn on and off at the same time were I need them to work independently.
Railroader:
How do You do this? By mind Control? I don't see anything to analyze.
Which means, you haven't posted any code - so no one can offer any advice about what might be wrong. You haven't posted a schematic either. It's good to post what you're using but it still comes down to "What determines when the pump is commanded to run/stop?"
Why do people need to be smart about this. All am looking is help with what am doing wrong I though this forum would have been the place but I must be wrong.
if (percentage >= 85)
{
digitalWrite(relay1, LOW);
}
else
{
digitalWrite(relay1, HIGH); // Drain pump needs to turn off when 15% of the water has been removed.
}
// Fill pump on
if (percentage <= 100)
{
digitalWrite(relay2, LOW);
}
else
{
digitalWrite(relay2, HIGH); // Fill pump needs to turn off when 15% of the water has been replaced.
}
Starting with a full tank (~100%) - percentage is > 85% so the drain pump comes on. On a subsequent time around loop, percentage will be let's say 99%. That's less than 100%, so the fill pump comes on. From then on, drain and fill are fighting each other. Probably one is marginally stronger than the other and you'll eventually get back to full or down to 84% when one or other pump will turn off very briefly.
You need a mode variable, a boolean would do, to tell you whether you are filling or draining. Use it to tell you which pump you should be operating and make sure the other is off. When the pump has done its job, you can change the boolean so the other pump gets a turn.
When this is done, you will have a system that constantly drains and then fills, so you will at least be replacing 15% of the water each cycle. At that point, you will probably want to inject some timing into it so that it only runs once every 24 hours perhaps.
A state machine q.v. is often suggested for this, but your needs are pretty simple and you can likely hack this together without having to learn them if you prefer not to.
As to "All I'm looking for is help...". Well sure, but the folks in the forum will help you for free but we would like you to help us to help you, hence the things you've been asked and links that have been posted.