TEMPERATURE MEASUREMENT OF A LIQUID
Temperature measurement is possible with many sensors. Here we will use the DS18B20 sensor which is available in a waterproof version to measure for example the temperature of the water in a swimming pool.
Connect as shown in the diagram the DS18B20
- black = ground
- yellow = data on pin PA14
- red = 3.3v
- A 4.7kohm resistor between the 3.3v and the yellow data wire
One Wire bus activation
The DS18B20 provides temperature measurements on a “1-wire” serial bus. You have to configure the armbian system by running ‘armbian-config’, the equivalent of ‘raspiconfig’ on Raspberry.
Go to the “system” section and select “Hardware” then activate w1-gpio.
You must add the corresponding “overlay” in
The pin used is also specified. Here PA14 on an Orange pi-Zero. The 1wire bus requires a + pull-up resistor. We can add uses that of the orange-pi which is much higher than the 4.7kOhm.
To manage the dialogues on the 1-wire bus, it is essential to have control over the execution time of the processor. To do this, you need to be able to temporarily “freeze” the OS’s ability to preempt by adding modules to the Linux kernel.
We define these modules in the configuration file
We can also add them by command
After a reboot of the system, you can check the presence of the probe by:
The answer should look like the one below with a code 28 in mind which corresponds to a temperature sensor.
Check that the modules loaded in memory are correctly taken into account
w1_therm et w1_gpio should be listed.
We can check that the gpio pin is correctly taken into account by
gpio-14 ( |onewire@0 ) out hi gpio-17 ( |orangepi:red:status ) out lo
The measurements are in folder 28 … located:
Read the w1-slave file, it contains 2 lines. There is the result in hexadecimal and the CRC check to validate the result.
98 01 55 05 7f a5 81 66 64 : crc=64 YES
98 01 55 05 7f a5 81 66 64 t=25500
At the end of the second line the temperature t = …. to be divided by 1000 gives the temperature of ° Celsius.
The measurements are performed periodically by the linux kernel. The w1_master_timeout file gives 10s base. This value adapts depending on the number of sensors on the line and the quality of the responses. A script written for example in python will read the w1-slave file and display the measurements or send them to a web client. A file named temperature in the same folder gives the last known value.