Go Down

Topic: Coding help (Read 325 times) previous topic - next topic

breaksbassbleeps

Hi everyone.

I'm currently working on a project which uses an Arduino to monitor the water level in a header tank in my attic and open a valve when it gets too low which causes a pressure sensitive pump in an outside water tank to fill it up again.
As I'm new to programming I've hit a brick wall..

The header tank has two float switches in it and I would like it to...
When the water level falls below the lower float switch, the solenoid valve opens and allows water into the tank until the water level reaches the top float switch which closes the solenoid valve, thus stopping the water.

I can write a sketch which just uses the upper float switch which controls the valve but I cant figure out how to write one which uses both like above.

I think it's because I'm trying to use conditional functions but I'm not sure if it's possible with those.

Any help would be much appreciated.
Thanks.

Arrch

Post what you have so far using code tags.

dnwiebe

Sounds like you want something vaguely like this.

  Interrogate the lower switch over and over until it says the tank is empty
  Start filling the tank
  Interrogate the upper switch over and over until it says the tank is full
  Stop filling the tank
  Repeat

However, if the task is really as simple as you describe it, you could probably just design a simple circuit to do it, probably with a double-pole relay as a latch.

breaksbassbleeps


Post what you have so far using code tags.


Here you go..

Code: [Select]
/*
*Header tank control
*/


int led = 13;          // Indicator LED on pin 13
int floatSwitch = 2;   // Float switch on pin 2
int switchValue;
int relay = 5;

void setup()
{
  pinMode(led, OUTPUT);
  pinMode(relay, OUTPUT);
  pinMode(floatSwitch, INPUT);
  digitalWrite(floatSwitch, HIGH);
}

void loop()
{
  switchValue = digitalRead(floatSwitch);
  if (switchValue == HIGH)
  {
    digitalWrite(led, LOW);
    digitalWrite(relay, HIGH);
  }
  else
  {
    digitalWrite(led, HIGH);
    digitalWrite(relay, LOW);
  }
}



Sounds like you want something vaguely like this.

  Interrogate the lower switch over and over until it says the tank is empty
  Start filling the tank
  Interrogate the upper switch over and over until it says the tank is full
  Stop filling the tank
  Repeat

However, if the task is really as simple as you describe it, you could probably just design a simple circuit to do it, probably with a double-pole relay as a latch.


I could do it without an arduino but I'm planning to add more features to it such as datalogging.

Arrch

The logic is trivial:

Code: [Select]
if high switch is active
  turn off relay
otherwise if low switch is active
  turn on relay

JimboZA

#5
Feb 03, 2013, 08:32 pm Last Edit: Feb 03, 2013, 08:37 pm by JimboZA Reason: 1
You' could have two booleans for the switches "top" and "bottom" and another for the state "pumping". Then the sequence is something like:


  • With a full tank, the switches top and bottom are floating and pumping is no.


  • Water runs out.... top is now hanging but don't pump yet....


  • More water runs out.... now bottom is hanging as well, start the pump, pumping is yes


  • Water runs in... bottom float now floating... but keep the pump on, pumping was on, remains on


  • More water runs in, top float now floating, turn pump off and set pumping to no.



Have the switches monitored, and pumping is a state you set.

Then the logic is something like this:


  • If top is floating, set pumping off (and switch the pump off!)

  • If bottom is hanging, switch pump on and set pumping on

  • If bottom is floating and pumping is on, keep on pumping

  •  
Repeal Ohm's Law

No PMs for help please

Go Up