Introduction: Water Level Measurement Tube

Possibilities

The water level measurement tube can measure the water level and monitor the water level in partly filled pipes, barrels or rivers. It can approximately measure the water level (-/+ 10 cm). The water level measurement tube is a relative cheap way to monitor the water level automatically and it warns (through email and/or a red light) if the water level is below or above (you can decide yourself) a self-set water level.

Supplies:

- A PVC 80 by 77 mm tube (circa 1.3 meters high)

- Several wooden plates and shelfs (see the in step 1 and 2 pictures for the amount and there size)

- Cap (circa 1 cm wide)

- Photon

- Led (3mm LEDs use a resistor in series when hooking them up to the Particle device. ( 220 ohms to 1K ohms))

- Resistor (see above)

- Mini pushbuttons

- Force Sensing Resistor (FSR 402)

- Some screws, bolts etc. (to put the wooden plates together)

- Electric cable

- Some wires (photon)

- Tape

- A computer that runs particle dev

Step 1: Put the Balance Together

- Make a wooden plate (9 cm - 9.5 cm)

- Put the cap at the centre of the wooden plate (with a screw or glue)

- Make a box where the wooden plate fits in (only 1mm space between the box and the plate is allowed, otherwise the cap is not aiming downwards) Make sure there is a small gap at the side of the box for the force sensing resistor (FSR).

- Solder the electric cable and the FSR together and place it in the centre of the box with tape. Make sure the cap is directly positioned on the FSR when you place the wooden plate in the box.

Step 2: Put the Holder Together

The type of holder you want depends on the location where you want to measure the water level. You need to take into account that the tube and the water level needs to be at the same level. This means if you want to measure a water level in a river with the tube, you need to put the tube partly underground. (see the illustration)

This is how our holder looks like (we used it for testing) :

- Make the PVC tube watertight at one side (leave the other side open) Make sure the watertight side has a smooth head.

- Take several shelfs and put it together just like in the pictures below. (make sure you put a gap in the wood with a drill, before you start to screw, to avoid creaking (as you can see we had a small problem with that)

- Mount the holders of the PVC tube in the wood just like the pictures. Make sure they stand exactly above each other and make sure the PVC tube is free to move up and down, without resistance.

Step 3: Put the Photon Together

The water level is measured with the FSR. You need a circuit to be able to read out the measurement values. For safety and clarity the wires have their own colour. The wires that are connected to the voltage (3.3V) are chosen red and the wires connected to the ground are chosen black or blue. The circuit for measuring the water level can be made as follows:

- First connect a (red) wire with the 3.3V. A suggestion is to connect the wire with the red plus side(s) of the photon to make connecting easier later on.

- Then connect a resistance of 10k ohm to the 3.3V and the other end to a row with free space available (for example row 30).

- In the same row (row 30) as the resistance use a wire to connect this row to the analog pin A0. The measured values will be read from the analog pin.

- Connect one side of the FSR also to the same row (row 30) and the other side to a row next to it (row 29)

- Finally connect the end of the FSR (row 29) to the ground to complete the circuit.

Then a mini pushbutton is added such that when the mini pushbutton is pressed the particular measurement at that moment is set as zero measurement. That means that the measured values after pressing the mini pushbutton is subtracted from the zero measurement.

The circuit for this can be made as follows:

- Put the switch on the photon such that two pins are connected to the analog side and two to the dialog side (for example row 26 and 28).

- Connect one pair of pins with a wire to the ground (row 26 or 28)

- The other pins (row 26 or 28, dependent on previous step) can be connected to a dialog port to define the zero measurement which can be used in the formula for the water level later on.

The last part consists of a warning system. A LED will blink when a certain water level will be exceeded. (See step 4: program the photon) The circuit for this is simple:

- Connect a LED to a dialog port (for example D0) and the other side to a free row (for example row 24)

- Connect a resistance of 330 ohm (orange-orange-brown-gold) to the same row as the LED (row 24) and the other side to the ground.

Step 4: Program the Photon

In this step there will be described how the program works.

First the measurement values will be generated with the FSR. A condition is made such that when the switch is pressed that particular measurement value will be the zero measurement. This value will be subtracted from the rest of the values generated. The water level will be computed with a polynomial function which describes the water level as function of the measurement values quite well. When the water level exceeds a certain level a condition is implied to let the LED blink by setting the dialog pin High and Low with a certain delay. Since the polynomial function does not describe the function well at all values, the condition that the measurement value should be lower than a certain value is implied as well.

The code used to determine the water level is given below, comments are added for clarity.

Code:

//Define which pins will be used as what type of pin

intmeasurementPin = A0;

intlampPin = D0;

intknopPin = D5;

//Set the initial values at zero

intanalogValue = 0;

float measurementValue = 0.0;

float measurementValue2 = 0.0;

float offset = 0.0;

float waterlevel = 0.0;

//Define timer parameters

Timer measurementTimer(10000,pubMeas);

Timer serialTimer(500,serialMeas);

void setup(){

//Start the timers

measurementTimer.start();

serialTimer.start();

//Define which pins will be as what

pinMode(measurementPin, INPUT);

pinMode(lampPin, OUTPUT);

pinMode(knopPin, INPUT_PULLUP);

//Start the serial communication

Serial.begin(9600);

}

//Start the loop, here values will be continuously generated

void loop(){

//Read the measurmentvalue from the analogpin (A0)

measurementValue = analogRead(measurementPin);

//measurementvalue2 is the value of the measurment after defining the zeromeasurement(offset)

measurementValue2 = measurementValue - offset;

"define water level again as zero (not needed???)"

waterlevel = 0.0;

//((float) measurementPin)

//When KnopPin is pressed ofset is the current measurementvalue, this is the zeromeasurement

if (digitalRead(knopPin)==LOW){

offset = measurementValue;

}

//If measurementvalue is higher than 1000 the tube is not installed so these waterlevels will not make sense

if(measurementValue<1000.0 ) {

//If the zeromeasurement has not been fulfilled the waterlevel will still be 0cm.

if(offset > 0.01 ) {

//Make only use of the formula to compute waterlevel when AND the tube is insalled AND the zeromeasurement

//(measurement belonging to the installation of the tube) is fulfilled

waterlevel = 0.0003*measurementValue2*measurementValue2 -0.0017*measurementValue2 +2.745;

}

"define water level again as zero (not needed???)"

else{

waterlevel = 0.0;

}

}

delay(1);

//When the waterlevel >75.0 the LED blinks, if you want to change the terms for blinking the light you can do that in the line below.

if(waterlevel>75.0 ) {

//And when measurementValue<1000.0, otherwise the LED will blink before the zeromeasurement due to use

//of a polynomial function which cannot define the waterlevel in a good way above certain measurementValues

if(measurementValue<1000.0 ) {

//Let the LED blink

digitalWrite(lampPin, HIGH); // sets the LED on

delay(200); // waits for 200mS

digitalWrite(lampPin, LOW); // sets the LED off

delay(200); // waits for 200mS

//Close all of the loops

}

}

}

//Publish the result on the website: https://dashboard.particle.io/user/logs

void pubMeas(){

Particle.publish("HennoMeting",String(waterlevel,3),PRIVATE);

}

void serialMeas(){

//Print the measurementValue for confirmation and the waterlevel because this is WHAT you want to measure

Serial.println(String(measurementValue,3));

Serial.println(String(waterlevel,3));

}

Flashing

After you connected the Photon with your computer, you need to flash this code on it. If you don’t know how this works, follow the next instructions:

https://learn.sparkfun.com/tutorials/photon-develo...

Step 5: Measurements

- Put the balance under tube. Make sure the tube stands straight.

- Run the program on the photon. (so make sure it has power and a Wi-Fi connection)

- Push the mini pushbutton on the photon

- You are ready to measure the water depth in the tube now.

- If you connect the water in the PVC tube with a other open water system (like an irrigation tank or a river) through for example a hose, you can measure and monitor the water level of that open water system.