Lesson 6 - Smart Window: Temperature-based Control System

Lesson 6 Smart Window: Temp-based Control System

 

image3.png Challenges: 6-1, 6-2

Students learn how to control the roof windows based on temperature.

image5.png I can read the temperature data and show them on the display.

image5.png I can clearly name a variable that represents the threshold value.

image5.png I can change the variable’s value and perform operations on its values.

Engage

image7.png 2 min.

Everyone has a different idea of a comfortable temperature. Some people find 26°C perfect, while others think 25°C is already too warm.

image9.png

How can we create a system that allows us to flexibly adjust this “comfortable” temperature threshold?

Background

image7.png 13 min.

DHT11 Temperature & Humidity Sensor

This sensor allows our device to sense the temperature and humidity of its environment, just like a thermometer.

image10.png

The temperature read block reads the current temperature from the sensor connected to pin P0.

image11.png

Creating a variable

image12.png

The set variable block is to assign a value to a variable. Here, we create a variable named my variable and set its starting value to 0.

image13.png

The change variable block retrieves the value stored in the variable, increments it by 1, and stores the updated value back into the variable.

image14.png

Build and Connect

image15.pngNo new build is required. We will use the same setup from Lesson 5 (window mechanism with servo motor)

Program

image16.png 25 min.

image17.png Challenge 6-1: Reading and Reacting

image19.pngAsk students to connect the DHT11 sensor to the P0 of the UNIHIKER K10.
Have students prepared for programming and load the program6-1-1.
Guide students to predict what will happen and run the program to test their predictions.
image20.pngimage21.png
Students will need to set the value in the comparator, which is a little bit higher than the room’s temperature condition.
Encourage students to modify the if-then-else block. They need to:Add the cache text block and set servo angle blocks inside the correct sections.
Here is the sample of program6-1-2:

image22.png Introduce the key vocabulary variables.

In the program above, the number 28 is our threshold. It's hard-coded, meaning it's fixed in the program. What if we want to change it easily? This is where variables become powerful. A variable is a named container that holds a value (like our threshold of 28). We can give it a clear name, like threshold, and change its value in buttons to affect the whole program.

image17.png Challenge 6-2: Making the Threshold Adjustable

image24.pngAsk students to create a new variable named threshold or another clear name, and set its starting number in the on start function as the starting value only needs to be set once.
Prompt students to show the value of the variable on the UNIHIKER K10’s screen.
image25.pngimage26.png
Discuss the question below:How could we change the threshold setting while the program is running?Encourage students to explore other blocks from the variable category and change the variable’s value using buttons.
Part of the code is provided below.
image27.pngimage28.png
Challenge students to use the variable in the if condition to control the window and texts.
Here is the sample of program6-2-2:

image22.png Conclusion:

hard-coded values: only be modified in the code before uploading; unchanging values when the program is running.

Variables: Named, flexible, and reusable; ideal for adjustable values.

Extra Practice

image16.png 5 min.

Create a variable to record the maximum temperature.

NOTE: every time you read the current temperature in the forever loop, if the value is higher than the variable, update it to the new one, which is the higher one.

image29.png

 

Next Class: Lesson 6

Current Tutorial: Click Here

icon Lesson 6.zip 1.8MB Download(1)
License
All Rights
Reserved
licensBg
0