Last lesson, we learned about the principles and functions of the accelerometer. In this lesson, we will learn about a new sensor on the UNIHIKER K10, and use its functions to make a smart night light that automatically adjusts the brightness of the LED light based on light intensity.
Project Objectives
Knowledge Objectives
1. Understand sensor concepts.
2. Understand light sensor principles.
3. Master UNIHIKER K10 light sensor usage.
4. Understand UNIHIKER K10 onboard sensors.
Practical Objective
Make a smart night light that can display the current light intensity data and the light's status on the screen: when the light is dim, the light turns on with high-brightness white light; when it is bright, the light turns off automatically.
Materials List

Preparations
Hardware
Connect the LED module to the UNIHIKER K10's P0 pin via a module cable, then connect the UNIHIKER K10 to a computer with a USB cable.

Software
Open Mind+ v2, switch to“Upload Mode”, connect the UNIHIKER K10 as shown in the figure below, and load the UNIHIKER K10 library.

Hands-on Practice
Next, we will first learn to read the light intensity value, then control the light's on/off based on changes in light intensity.
Task 1:Read the Light Intensity Value
First, we will read the light intensity value and display the corresponding intensity on the screen.
Task 2: Make a Smart Night Light
Then, we will use light intensity to control the on/off of the LED light and build the smart night light.
Task 1:Read the Light Intensity Value
Code
Measuring the light intensity of the UNIHIKER K10 requires the light sensor. Location as follows:

Note: See the Knowledge Base for the introduction to the light sensor.
To read the light intensity value, we need to use the “read light”block under the”Sensors”in the UNIHIKER K10 library, as shown in the figure below:

The complete reading code is shown in the figure below:

Run the Code
Click the“Upload”button,and once the upload is complete, change the light intensity (for example, by covering the sensor with your hand or shining a flashlight on it). Then, observe the light intensity values and how they change.

Code Review
Category | Blocks | Function |
![]() | Get the ambient light from the onboard light sensor in Lux. |
Task 2: Make a Smart Night Light
Code
First, use the “digital (P0) output (LOW)”block under the “pin operation” category in the UNIHIKER K10 library to control the LED's on/off.
Then use the “if() then()”block to control the LED's on/off. The condition filled in after "if" is related to light intensity, which varies with the surrounding environment. So detect the light intensity in advance to set the threshold condition.
In my natural environment, the light intensity is about 500; it drops to around 50 when the sensor is covered. So the threshold is set such that light intensity above 450 means sufficient light, and intensity below 50 means the light needs to be turned on for supplementary lighting.
The complete reading code is shown in the figure below:

Run the Code
Click the“Upload”button. After the upload is complete, change the light intensity and observe the corresponding intensity value and LED status.

Code Review
Category | Blocks | Function |
![]() | Set pin output high or low level. |
Have a Try
After building the smart night light, we can simulate the auto-brightness function of mobile phone displays: the screen background dims when light brightness drops, and brightens when it rises.
Note: Use the“set background color (white)” block under the “Screen” module in the UNIHIKER K10.
Reference code as follows:

Knowledge Base
Next, let's learn and summarize the hardware knowledge used in this lesson.
Concept of Sensors
1.Definition of Sensors
Sensors act as a bridge between the physical and digital worlds, sensing physical quantities (e.g., temperature) or chemical quantities (e.g., gas concentration) and converting them into electrical signals and other forms for output. Known as the "five senses" of machines, they allow devices to "see", "hear", "touch" and "smell", and are core components of the IoT, automation control and intelligent devices.

2. Principle of Sensors
The principle of a sensor is divided into three steps: Perception → Conversion → Processing, accomplished by four components working together:
(1) Sensitive Element: It directly contacts the measured quantity (e.g., temperature, pressure), and generates corresponding physical changes (e.g., minor deformation, characteristic alterations).
(2) Transducing Element: It converts the aforementioned physical changes into electrical signals recognizable by electronic devices (e.g., weak voltage).
(3) Signal Conditioning Circuit: It refines the electrical signals—amplifying weak signals, filtering out interference, and refining them into a standardized and usable form.
(4) Auxiliary Power Supply: Like a power adapter, it provides the operating power required for the transducing element and the circuit.

3. Applications of Sensors
Sensors' applications are deeply integrated into daily life, healthcare, industry, transportation and other fields, serving as the core of devices' "perception of the world".Please refer to the figure below for specific applications.

Working Principle of the Light Sensor
The working principle of the light sensor can be simplified into three steps: Light Signals → Electrical Signals → Digital Data, specifically as follows:
(1) Light Signals → Physical Characteristic Changes (Photosensitive Element): The photosensitive semiconductor of the UNIHIKER K10 converts light signals into resistance(R)/current(I) changes through the"Internal Photoelectric Effect".
① Strong Light → More Photons → More Carriers → R↓/ I↑
② Weak Light → Fewer Photons → Fewer Carriers → R↑/ I↓

(2) Physical Changes → Analog Voltage (Signal Conditioning Circuit): The core is a "constant current source + series resistor" circuit, which converts R / I changes into a weak 0-3V analog voltage(V) (Ohm's Law: U=IR).
① Strong Light → High Current → High Voltage across the Series Resistor (Nearly 3V)
② Weak Light → Low Current → Low Voltage (Nearly 0V)
(3) Analog Voltage → Digital Quantity (Signal Conditioning Circuit): Through "Amplification → Filtering → A/D Conversion", it converts the analog voltage into a digital quantity ranging from 0 to 4095 (12-bit A/D precision of the UNIHIKER K10). (3V corresponds to 4095, 0V to 0)

(4) Digital Quantity → Lux → Screen Display: The firmware of the UNIHIKER K10 converts digital quantities into Lux values using the "Standard Light Intensity Calibration Formula"; then you can use the relevant blocks in the code to display the corresponding light intensity on the screen.
Onboard Sensors of the UNIHIKER K10
The onboard sensors of the UNIHIKER K10 are integrated directly on its motherboard, including the light sensor, accelerometer, microphone, and temp& humi sensor. Their specific positions are as shown in the figure below.

The corresponding blocks for each onboard sensor are as follows:

Challenge Task
Our smart night light only has on/off states now. Modify the program to add four brightness levels for it (daily lights have multiple levels).
Tip: Add more “if() then()” blocks and use PWM to adjust the LED brightness.
Reference code as follows:













