Devices & Components
Arduino Uno Rev3
Capacitor 1 nF
Capacitor 220 nF
Water Level Sensor
Resistor 680 k Ohm
ESP 32
Water Level Indicator
Software & Tools
Arduino IDE
Project description
Code
Waterlevel_measuring.ino
arduino
ARDUINO Sketch for DIY Water Level Sensor and DIY Water Level Indicator with 5 levels running on a ESP 32 or ARDUINO UNO or similar (with small modifications)
1/* 2 This code for a WaterLevel sensor and a WaterLevel Indicator has been developed and produced by Pierre Pennings (December 2018) 3 This application can be used for various situations where information about the level of water in a reservoir tank is required 4 e.g. in automatic plant watering systems or in caravans or campers where there is no direct visibility on the water reserve in the tank. 5 The DIY WaterLevelSensor uses 6 pieces of copper electricity wire connected to a ladder network of 680K Ohm resistors 6 The DIY WaterLevel Indicator is made with 5 (Neopixel) SMD5050 LEDs with WS2812B controller chips powered with 5 V 7 Every individual LED is adressed from one ARDUINO output pin and the control adress determined by the measured WaterLevel 8 The WaterLevel is measured periodically (during only 200 mili seconds, to avoid corrosion due to electrolysis effects) 9 The WaterLevel Indicator is set to the measured water level 10 The measured WaterLevelValues are not distributed linearly but follow a second grade polynomial 11 Reference values for the measurements are stored in an Array called LEVELarray[] consisting of 6 positions 12 The actual measured WaterLevelValues are compared with the values in the Array and consquently the Water level is determined 13 For this Project, which is part of a bigger plan, an ESP 32 (NodeMCU) is used with 12 Bits ADCs, however an normal ARDUINO UNO (or almost any other model) will do the job 14 (of course the settings in the code will need to be adjusted, e.g. due to 10 Bits ADC and different Pin allocations 15 The ESP 32 device works at 3.3 Volt levels, while the WaterLevel Indicator runs on 5 V 16 The 5 Level LEDs have been built in a separate indicator Display (indicating 1%, 25%, 50%, 75% and 100% levels) 17 The ESP 32 is fed with 5 V power (from a 5V adaptor or 5v powerbank), it has an on-board 3.3V voltage regulator 18 The 5 indicator LEDs get the 5V supply directly from the 5 volt pin of the ESP 32 19 20 This code is licensed under GPL3+ license. 21*/ 22 23#include <Adafruit_NeoPixel.h> 24#define NUM_LEDS 5 25 26 27///////////////////////////////////////////////// initialise the GPIO pins 28const int output27 = 27; // pin 27 sends a "0" or "1" (0 -3.3 V) to the waterlevel measurement circuit 29const int LevelSensorPin = 34; // 12 bits ADC pin 34 senses the voltage level of the waterlevel sensor (values 0 - 4095) 30const int IndicatorPin = 16; // pin 16 sends the control data to the LED WaterLevel Indicator 31 32int WaterLevelValue = 0; // Variable to store the value of the Waterlevel sensor 33int level = 0; // Variable of the WaterLevel 34 35// 0 1 2 3 4 5 36int LEVELarray [6] = {1125,1245,1450,1720,2080,2630} ; // Array with the level reference values to determine the waterlevel 37 // the "0" level is applicable when there is no water in the reservoir 38 // the "5" level is applicable when the reservoir is full 39 40byte color_scheme[] = { 41 0, 0, 0, // no color/ off 42 0, 200, 0, // green 43 100, 200, 0, // yellow 44 250, 150, 0, // orange 45 0, 0, 200, // blue 46 200, 0, 0 // red 47}; 48 49Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, IndicatorPin, NEO_RGB + NEO_KHZ800); 50 51/////////////////////////////////////////////////// the setup code that follows, will run once after "Power On" or after a RESET 52void setup() { 53 Serial.begin(115200); 54 55 pinMode(output27, OUTPUT); // Initializes the power output pin (3.3 V) for the WaterLevel Sensor circuit 56 digitalWrite(output27, LOW); // Set output27 to LOW; this will send 0 V to the measuring circuit 57 58 pinMode(LevelSensorPin, INPUT); // Initializes the water level sensorpin 59 pinMode(IndicatorPin, OUTPUT); // Initializes the output pin for the WaterLevel Indicator 60 61 strip.begin(); // Initialize all LEDs to "off" 62 63 for (int t = 0; t < 5 ; t++) 64 { 65 strip.setPixelColor(t, 100, 100, 100); // After Power On the WaterLevel Indicator LEDs are tested once 66 strip.show(); // note that the order of colors of the WS2812 LED strip is R,G,B 67 delay (200); 68 strip.setPixelColor(t, 0, 0, 0); // And back to off 69 } 70 for (int k = 4; k > -1 ; k--) 71 { 72 strip.setPixelColor(k, 100, 100, 100); // blink for 0,2 seconds going top down and then off 73 strip.show(); 74 delay (200); 75 strip.setPixelColor(k, 0, 0, 0); 76 } 77} 78 79/////////////////////////////////////////////////// the loop code that follows, will run repeatedly until "Power Off" or a RESET 80void loop(){ 81 82 MEASUREWATERLEVEL (); 83 INDICATEWATERLEVEL (); 84 delay(1000); // Check for new value every 1 sec; 85 //this value is just for demonstration purposes and will in a practical application be far less frequent 86} 87//////////////////END of LOOP//////////////////////////////////////////////////////////// 88 89 90/////////////////////////////////////////////////// Hereafter follows the Function for measuring the WaterLevel (called from within the loop) 91 92void MEASUREWATERLEVEL () { 93 digitalWrite(output27, HIGH); // make pin 27 HIGH 94 delay(200); // allow the circuit to stabilize 95 WaterLevelValue = analogRead(LevelSensorPin); //Read data from analog pin and store it to WaterLevelvalue variable 96 97 for (int i = 0; i < 6 ; i++) 98 { 99 if ((WaterLevelValue > (LEVELarray[i] * 0.96)) && (WaterLevelValue < (LEVELarray[i] * 1.04))) // allow a margin of 4% on the measured values to eliminate jitter and noise 100 { 101 level = i; 102 } 103 digitalWrite(output27, LOW); // make pin 27 LOW 104 Serial.print(" LEVELarray: "); Serial.print(level); Serial.print(" = "); Serial.print(LEVELarray[level]);Serial.print(" WaterLevelValue: "); Serial.print(WaterLevelValue); Serial.print(" Level: "); Serial.println(level); 105 // uncomment this code for determining the values to be put in the LEVELarray [] using the serial plotter and/or serial monitor or the ARDUINO IDE 106 } 107 } 108 109/////////////////////////////////////////////////// Hereafter follows the Function for Indicating the WaterLevel (called from within the loop) 110 111void INDICATEWATERLEVEL () { 112 113for (int t = 0; t < 6 ; t++) 114 { 115 strip.setPixelColor(t, 0, 0, 0); // turn off all LEDs on the WaterLevel Indicator 116 strip.show(); 117 } 118 119int redVal, greenVal, blueVal; // Set the WaterLevel Indicator LED with a color defined in the Array color_scheme 120 redVal = color_scheme[level*3]; 121 greenVal = color_scheme[level*3 + 1]; 122 blueVal = color_scheme[level*3 + 2]; 123 124 strip.setPixelColor(level-1, strip.Color(redVal, greenVal, blueVal) ); 125 strip.show(); 126 } 127 128
Downloadable files
Water Level Sensor and Level Indicator
This diagram shows the set up of a system for measuring waterlevels with a DIY sensor and a display for level indication in combination with an ARDUINO
Water Level Sensor and Level Indicator
Water Level Sensor and Level Indicator
This diagram shows the set up of a system for measuring waterlevels with a DIY sensor and a display for level indication in combination with an ARDUINO
Water Level Sensor and Level Indicator
Documentation
template for Water Level Indicator
template for drilling holes and printing text for the Water Level Indicator
template for Water Level Indicator
template for Water Level Indicator
template for drilling holes and printing text for the Water Level Indicator
template for Water Level Indicator
Comments
Only logged in users can leave comments