Lesson 4 - Home Lighting: Staircase Light Upgrading

Lesson 4 Home Lighting: Staircase Light Upgrading

 

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

Students will learn to use different methods to trigger the LED strip.

image5.png I can use buttons to turn an LED strip on and off.

image5.png I can explore various input methods beyond physical buttons.

image5.png I can use the map block to convert an input range to an output range.

Engage

image7.png 2 min.

The automatic stair light at home can already be programmed to light up! Besides the PIR motion sensor we learned about before, what other ways could we control the stair light?

image9.png

Background

image7.png 13 min.

The UNHIKER K10 has a built-in light sensor. The value it reads represents illuminance, and its unit is lux.

0 lux: Complete darkness.

300–500 lux: A typical well-lit classroom.

>10,000 lux: Full daylight.

image10.png

In programming, we can set up actions to occur when specific events happen. The on button A pressed block is a function that runs its code only when Button A on the UNIHIKER is pressed.

image11.png

image12.png

More blocks of build-in sensors can be found in the UNIHIKER K10 library under the sensors category.

image13.png

The map block is a common operator that takes a number from one range and converts it to a corresponding number in a new range.

Here is a code example and its explanation:

image14.png

It takes the light sensor reading, which might be between 0 and 1500 lux, and converts it to a brightness value between 0 and 255 for the LED strip.

Program

image15.png 25 min.

image16.png Challenge 4-1: Button & Gesture Control

image18.pngAsk students to make hardware connections.
Have students prepared for programming.
image19.pngimage20.png
Guide students to rebuild the program to control the LED strip by the buttons.
image21.pngHave students discuss the question below:How many states does a button have? What are they?Encourage students to explore when button A released block.
Challenge students to modify their program so that the lights turn on only while holding down button A and turn off when released.
image22.pngGuide students to upload program4-2 and read the program, and predict what will happen.
image23.pngimage24.png
Challenge students to expand the program so that different gestures change the LED strip to different colors or modes.
Students can expand this logic like this:

image16.png Challenge 4-2: Light-Sensitive Brightness

image25.pngRun the program. Cover the light sensor with your hand. What happens to the brightness?Guide students to cover the light sensor slowly and observe the brightness of the LED strip at the same time.
image26.pngIntroduce the map block after testing and sharing:In mathematics, it describes a rule that takes an input and gives you a specific output.
In this program, it takes the light sensor reading (between 0 and 1500) and maps it to a brightness value (between 0 and 255).

Extra Practice

image15.png 5 min.

What is the light (lux) reading in your classroom? How to show it?

image27.png

Adjust the from High value in the map block to match your environment for the smoothest brightness control.

image28.png

How can you make a stair light whose brightness changes with the ambient light, but with an inverse relationship? (The darker the room, the brighter the light, and the brighter the room, the dimmer the light.)

Possible Solution:

image29.png

 

Next Class: Lesson 5

Current Tutorial: Click Here

icon Lesson 4.zip 755KB Download(0)
License
All Rights
Reserved
licensBg
0