Lesson 12 DS18B20 Temperature Sensor

Share for us


In this lesson, we will use a temperature sensor and a buzzer to make a high temperature alarm device.


Programming Steps

Step 1

After creating a new project, click on the Simulation icon on the left side of the page to enter the Simulation page.

Step 2

Connect the buzzer to P0 and temperature sensor to D7(the  temperature sensor must be connected to D7) of the Ezblock Pi. Then connect the VCC and GND to 3.3V and GNDrespectively.

Step 3

Click Create variable in the Variables category to create a variable called temVal.

Step 4

The temperature value of DS18B20 is read and stored in the variable temVal. There are two units of temperature, which can be selected by clicking in the drop-down menu. Then use print block to display the temperature on the Debug Monitor.

Step 5

Step 6

After you click the run button, drag the slider to set the reading value of sensor. If the reading value is > 30, the buzzer will ring, indicating that the codes are correct. Now save your project, connect the Bluetooth and click Flash to compile and download the code.