Lesson 4 Home Lighting: Staircase Light Upgrading
Challenges: 4-1, 4-2
Students will learn to use different methods to trigger the LED strip.
I can use buttons to turn an LED strip on and off.
I can explore various input methods beyond physical buttons.
I can use the map block to convert an input range to an output range.
Engage
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?

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

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.


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

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:

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
25 min.
Challenge 4-1: Button & Gesture Control
![]() | Ask students to make hardware connections. Have students prepared for programming. |
![]() | ![]() Guide students to rebuild the program to control the LED strip by the buttons. |
![]() | Have 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. |
![]() | Guide students to upload program4-2 and read the program, and predict what will happen. |
![]() | ![]() 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: |
Challenge 4-2: Light-Sensitive Brightness
![]() | Run 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. |
![]() | Introduce 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
5 min.
What is the light (lux) reading in your classroom? How to show it?

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

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:

Next Class: Lesson 5
Current Tutorial: Click Here


















