7. Case 05: Water Temperature Detection#

7.1. Introduction#


  • Fishes are poikilotherm whose body temperature changes as the ambient water temperature changes, thus, the water temperature plays a vital role in the growth of fishes.

7.2. Function#


  • Dectect the water temperature with the DS18B20 sensor and display them on OLED screen.

7.4. Picture#


../../_images/microbit-Smart-Agriculture-Kit-case-01-02.png

7.5. Hardware Connection#


Connect DS18B20 to P1 and the OLED to IIC on IoT:bit.

../../_images/microbit-Smart-Agriculture-Kit-case-05-03.png

7.6. Software Programming#


Click “Advanced” in the MakeCode to see more choices.

../../_images/microbit-Smart-Agriculture-Kit-case-01-04.png

For programming, we need to add a package: click “Extensions” at the bottom of the MakeCode drawer and search with “iot-environment-kit” in the dialogue box to download it.

../../_images/microbit-Smart-Agriculture-Kit-case-01-05.png

Notice: If you met a tip indicating that some codebases would be deleted due to incompatibility, you may continue as the tips say or create a new project in the menu.

7.7. Program#


Initialize the OLED screen as 128×64.

../../_images/microbit-Smart-Agriculture-Kit-case-05-07.png

Set DS18B20 sensor to connect to P1 and save the returned value as variable “Temp”.

../../_images/microbit-Smart-Agriculture-Kit-case-05-08.png

Clear the OLED screen and display the water temperature.

../../_images/microbit-Smart-Agriculture-Kit-case-05-09.png

Link: https://makecode.microbit.org/_Jx2d4JgU6iWj

7.8. Result#


  • The OLED displays the water temperature and refreshes every 5 seconds.