Like many other home builders, I want to measure the level in my rainwater tank. The evaluation of the sensor is done with a Siemens Logo. The conversion from the fill level to the fill volume confronted me with the somewhat cumbersome implementation of calculations in the Logo, which I will discuss below.
I decided to use a "China sensor", which makes a very robust impression and has done his job perfectly so far.
The sensor works according to the 4-20mA standard and is actually a pressure sensor. 4mA corresponds to 0bar and 20mA corresponds to 0.5bar for this sensor. By a trick the sensor measures the relative pressure to the ambient air. The atmospheric pressure is transmitted to the sensor under water via a thin tube inside the connection cable. In this way, only the pressure built up by the column of water hydrostatic pressure of 0.0981bar per metre is measured. The sensor can therefore measure filling heights up to about 5m.
The sensor is connected to an analogue Logo input as follows:
Since my 5000l water tank only has a maximum filling height of 120cm, a maximum of 120cm/500cm * 16mA + 4mA = 7,84mA will flow. To increase the measuring accuracy, I therefore used a 1kΩ resistor instead of a 500Ω resistor. Thus the input voltage rises approximately up to 7.84mA * 1000Ω = 7.84V instead of only up to 3.92V.
Calculate the fill level in the Logo:
The maximum input voltage of 10V is mapped in the logo with a value of 1000. Since the relation between level and input value is linear with this sensor, two measuring points are sufficient to obtain the corresponding conversion formula. In my case, the Logo reads in the value 394 when the sensor is is out of the water (this corresponds approximately to the 4mA) and the value 752 when the tank is filled to 120cm.
With the help of the freeware Geogebra, you can get the conversion formula even without knowledge of mathematics. However, it may be necessary to increase the accuracy of the displayed decimal numbers via the menu item Settings/Rounding.. Here you can download the Geogebra file and adapt it to your sensor.
So from geogebra we can read that:
In the Logo, this can be implemented as follows:
The analogue input value AI4 is first fed to a mean value block to smooth out the fluctuations in the sensor's measured value. I let the Logo take 5 measurements within within 5 seconds and then average them. If the enable input is inverted, then the block is permanently active.
I then give the averaged value to the "Arithmetic instruction" block. This block takes a little getting used to. In principle, it can be used to perform three successive arithmetic operations between 4 values. Via the priority parameter you can influence the position of the brackets. The 4 values can either be entered as fixed values or taken over from other analogue blocks. The exact calculation is displayed in the last green line below the block for checking purposes. You can also invert the enable input on this block.
Now it is important to know that the arithmetic block can internally display results with decimal numbers, but the input, output and parameter values must be integers. So in our case, the number 0.335 must first be calculated by by dividing 335 by 1000 before the result can be multiplied by the input value. can be multiplied. Finally, 132 is subtracted and thus we have successfully implemented the formula.
The simulation confirms (see above) that the input value 752 is converted into the output value Aq 120(cm) and stored in the analogue flag AM2. The analogue flag AM1 is only necessary because otherwise an error message occurs when the programme is uploaded to the Logo.
The analogue value AM2 can now be shown, for example, on the display of the Logo or on the text display LOGO! TDE. However, it is more contemporary to display the value e.g. with the help of LogoControl over the network and display it on its website.
Convert filling height to filling volume: (for advanced users)
If the tank is not exactly in the category of square, practical, good, then the conversion from filling height to filling volume with the logo is a bit of a challenge. The manufacturer of my tank kindly of my tank kindly sent me the filling curve, which I then used to determine reference points.
With the help of the trend line function in Excel, I have been able to determine the approximate function from the interpolation points, which describes the dependence between filling level h and filling volume V. To obtain a coefficient of determination R2 close to 1, a third-degree polynomial was necessary. Instructions for inserting and parameterising the trend line can be found on the Internet.
Sollten die zu verrechnenden Werte deutlich größer oder kleiner sein als der angegebene Bereich, dann müssen diese Werte zunächst künstlich vergrößert oder verkleinert werden und das Ergebnis entsprechend korrigiert werden.
Wenden wir uns nun aber dem oberen Polynom zu. Ich werde die drei Terme des Polynoms zunächst einzeln berechnen lassen und abschließend summieren. Die Multiplikation mit -0,0051 im ersten Term muss mit Hilfe von ganzen Zahlen ausgedrückt werden. Dies geht ganz einfach indem man -51 durch 10.000 teilen lässt. Alternativ kann man die Multiplikation mit -0,0051 auch durch eine Division mit 1/(-0,0051) = -196 ersetzen. Dies hat den Vorteil, dass für die Berechnung des ersten Terms nur 4 Zahlen benötigt werden und somit nur eine arithmetische Anweisung dafür benötigt wird. Hier die Umsetzung:
Everyone who knows how to programme knows that in any programming language, only one line is needed to implement this function. As much as the graphic programming of the Logo simplifies many automation tasks, the block concept makes a mountain out of a molehill. Nevertheless I would like to show below how this polynomial can be implemented in Logo.
As already described above, the input, output and parameter values of the block "Arithmetic Instruction" can only be integers between -32768 and 32767. You have to keep this value range in mind if you want to get reasonably correct values.
If the values to be calculated should be significantly larger or smaller than the specified range, then these values must first be artificially enlarged or reduced and the result corrected accordingly. the result must be corrected accordingly.
But let us now turn to the upper polynomial. I will first calculate the three terms of the polynomial individually and then sum them up. The multiplication by -0.0051 in the first term must be term must be expressed with the help of integers. This can be done quite simply by dividing -51 by 10000. Alternatively, the multiplication by -0.0051 can also be expressed by a division by by dividing with 1/(-0.0051) = -196. This has the advantage that for the calculation of the first term only 4 numbers are needed and therefore only one block is needed. Here is the implementation:
The analogue input AI8 cannot be directly connected to the value inputs of the arithmetic instruction because the value range does not fit. Therefore, I simply connect an analogue amplifier with a gain of 1 in between. The result of the first polynomial lies at the maximum expected input value of 120 at -8816. This is within the valid range of values.
If we proceed in the same way for the other two terms, we obtain the following calculation circuit, which calculates the correct filling volume of 5451 litres from the filling level of 120 cm.
If you want to display the filling volume in LogoControl, it is much easier to do the conversion directly there. The whole polynomial circuit can then be completely omitted.