Skip to main content

Case 05: Water Temperature Detection


  • 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.


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


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.


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.



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