Hi all,
I am having trouble with my project,
I am trying to make an auto fish tank refiller for water using an Arduino Wifi Rev2.
The idea for the code is that there are two float switches that activate when the water reaches their level, they would be the upper and lower limit for the water level. When both switches are off the output connected to a relay, connected to a valve will actuate and fill up the tank. When both switches are on, the relay connected to the valve should turn off. An important detail is that when one of the switches are off and the other is on, no change should happen.
Attached below is the code and the wiring diagram, thanks in advance.
void setup() {
pinMode(A0, INPUT);
pinMode(A1, INPUT);
pinMode(7, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
int LowSwitch = A0;
int HighSwitch = A1;
int Valve = 7;
if ((LowSwitch>0.5) && (HighSwitch>0.5)) {
digitalWrite(Valve, LOW);
} else if ((LowSwitch<=0.5) && (HighSwitch<=0.5)) {
digitalWrite(Valve, HIGH);
}
}
Hi Paul thanks for the help,
I think I've done it wrong again though.
Below is the new wiring diagram I have and this time the relay is constantly on when both switches are open or closed but the relay switches off when one is closed and the other is opened.
I have directly uploaded your code without any changes.
Thanks for the help but I've figured it out now,
I think what was going wrong was how I was defining variables, how I was detecting voltage and switching over to using the digital pins.
Cheers again and the code that's working for me is attached below.
You could do this more simply with a relay ( possibly 2?depending on what contacts are available) operating as a latch off the bottom float switch. Relay operates pump via contact on the top switch and the latch. When water reaches top , stops pump and breaks latch .
It can be instructive to look at logic circuits as alternatives