2018-11-08, 12:36 PM
(2018-11-07, 07:10 PM)abarrow Wrote: Sure, I'll have to dig up the Arduino sketch I used, but it's extremely simple. Let me see if I can put something together for you.Thank's alot for the information! It will be perfect to monitor my water tank. I do have a arduino uno that I can use and "millions" of small led lights in different colours. I don't need to know exactly the amount of liters, just something that tells me that it's time to fill it up and when then tank is full when I fill it up.
It may not be super quick as my boat just came out of the water and I need to be at the yard to do work on it!
I found the sketch. Basically, for a sensor, you get a piece of plastic rod the depth of your water tank, and put rings of copper on the very bottom, then at three other places farther up the rod (low, med, full...). Those come back to your Arduino (the bottom contact is ground). As the water level rises, each sensor contact is brought low, which activates the associated LED. Also on your arduino, you attach LEDs to indicate levels. In my case, I used Green, Green, Yellow and Red in a descending row in a little box.
I'm sure this can be made to interconnect with OP, I just never got around to doing it!Code:*
Level Sense
This is a water level detector for a tank. It uses a plastic rod with contacts up the length
*/
// set pin numbers:
//Below bottom sensor
const int ledPinRed = 13;
//Above bottom sensor
const int ledPinYellow = 12;
//Above middle sensor
const int ledPinGreen1 = 11;
//Above top sensor
const int ledPinGreen2 = 10;
//Sensors
const int sensorPinLow = 9;
const int sensorPinMed = 8;
const int sensorPinHigh = 7;
int sensorTotalValue = 0;
int sensorValueLow = 0;
int sensorValueHigh = 0;
int sensorValueMed = 0;
void setup() {
pinMode(ledPinRed, OUTPUT);
pinMode(ledPinYellow, OUTPUT);
pinMode(ledPinGreen1, OUTPUT);
pinMode(ledPinGreen2, OUTPUT);
pinMode(sensorPinLow, INPUT_PULLUP);
pinMode(sensorPinMed, INPUT_PULLUP);
pinMode(sensorPinHigh, INPUT_PULLUP);
Serial.begin(9600);
Serial.println("Welcome to the level sensor");
}
void loop() {
//Reset the sensors
// int sensorValueLow = 0;
// int sensorValueHigh = 0;
// int sensorValueMed = 0;
// read the state of the sensor values:
if (digitalRead(sensorPinLow) == HIGH) {
sensorValueLow = 1;}
else {
sensorValueLow = 0;
}
if (digitalRead(sensorPinMed) == HIGH) {
sensorValueMed = 1;}
else {
sensorValueMed = 0;
}
if (digitalRead(sensorPinHigh) == HIGH) {
sensorValueHigh = 1;}
else {
sensorValueHigh = 0;
}
sensorTotalValue = sensorValueHigh + sensorValueMed + sensorValueLow;
Serial.print("Sensor Value: ");
Serial.println(sensorTotalValue);
// make sure all the lights are out
digitalWrite(ledPinRed, HIGH);
digitalWrite(ledPinYellow, LOW);
digitalWrite(ledPinGreen1, LOW);
digitalWrite(ledPinGreen2, LOW);
// then turn on the right lights
switch(sensorTotalValue) {
case 3:
//Absolutely low. Flash the red led
digitalWrite(ledPinRed, LOW);
delay(500);
digitalWrite(ledPinRed, HIGH);
delay(500);
break;
case 2:
//Yellow Light only
digitalWrite(ledPinYellow, HIGH);
break;
case 1:
//First green light and yellow
digitalWrite(ledPinYellow, HIGH);
digitalWrite(ledPinGreen1, HIGH);
break;
case 0:
//Two green lights and yellow
digitalWrite(ledPinYellow, HIGH);
digitalWrite(ledPinGreen1, HIGH);
digitalWrite(ledPinGreen2, HIGH);
break;
}
}
//Patrik