Pages: [1]   Go Down
Author Topic: Coding help  (Read 300 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3384
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Post what you have so far using code tags.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 6
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 15
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Post what you have so far using code tags.

Here you go..

Code:
/*
 *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.
Logged

California
Offline Offline
Faraday Member
**
Karma: 88
Posts: 3384
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The logic is trivial:

Code:
if high switch is active
  turn off relay
otherwise if low switch is active
  turn on relay
Logged

Johannesburg. UTC+2
Offline Offline
Faraday Member
**
Karma: 99
Posts: 4430
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
« Last Edit: February 03, 2013, 02:37:00 pm by JimboZA » Logged

The Elders of the Internet know who I am
I'm on LinkedIn: http://www.linkedin.com/in/jimbrownza

Pages: [1]   Go Up
Jump to: