跳到主要内容

Case 05: Water Temperature Detection

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.

Function


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

Picture


Hardware Connection


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

Software Programming


Click "Advanced" in the MakeCode to see more choices.

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.

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.

Program


Initialize the OLED screen as 128×64.

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

Clear the OLED screen and display the water temperature.

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

Result


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