A Voice-Controlled Desk Lamp Based on the Tianwen ASRPRO
Video walkthrough:
Abstract
To address the limited interaction and nighttime inconvenience of traditional desk lamps, this paper presents the design and implementation of a voice-controlled desk lamp based on the Tianwen ASRPRO offline speech-recognition chip. With the ASRPRO as the control core, the system integrates a BH1750 digital ambient-light sensor, an infrared beam-break (obstacle-avoidance) sensor, and a DHT11 temperature-humidity sensor, and drives a common-cathode RGB lamp for color mixing and flowing-light effects. The system operates in two modes. In manual mode, the user wakes the device with "你好小智" (Hello Xiaozhi) and controls the lamp directly with Chinese command words such as "open the red light," "change color," and "flash fast," and can also query temperature and humidity by voice. In auto mode, the system samples ambient light and obstruction status once per second; when illumination is insufficient and an obstruction is detected (i.e., someone approaches at night), the lamp lights up white automatically and turns off when the person leaves. Any lighting command instantly returns the system to manual mode. Tests show that keyword recognition and execution are stable, the temperature and humidity announcements are accurate, and the auto-mode on/off logic behaves as expected.
Keywords: ASRPRO; offline speech recognition; RGB color mixing; DHT11; BH1750
1 Introduction
The desk lamp is one of the most frequently used household lighting devices, yet conventional lamps rely on buttons or touch controls, which are inconvenient when your hands are full or when groping in the dark at night. As the cost of offline speech-recognition chips keeps falling, bringing "speak-and-control" to the desk lamp has become a low-cost improvement.
Compared with cloud-based voice solutions, the offline approach has two clear advantages. First, recognition runs locally, so it does not depend on a network connection — responses are fast and no audio is uploaded, which addresses privacy concerns. Second, the keyword set is fully developer-definable, which suits small command scenarios such as on/off, color change, and temperature queries. This project uses the Tianwen ASRPRO V2.0 board as the controller: it integrates speech recognition and MP3 playback on-chip and provides enough GPIO, PWM, and software-I2C resources to close the entire "recognize — announce — actuate" loop on a single chip.
2 Overall System Design
2.1 Functional Requirements
The system is required to provide:
- Wake-up and keyword recognition: the wake word "你好小智" (Hello Xiaozhi), after which the device listens for command words;
- Lamp control: single-color commands (red, green, blue, yellow), a "change color" command that picks a random color, and "flash fast / flash" effects that rotate colors every 1 s or 2 s for 10 seconds;
- Temperature and humidity announcement: saying "current temperature / current humidity" triggers a synthesized voice announcement of the value;
- Volume control: voice commands step the announcement volume up or down within levels 1–10;
- Dual-mode operation: in auto mode, the lamp lights up white when illumination is insufficient and an obstruction is detected; any lighting command switches the system back to manual mode.
2.2 System Architecture
The ASRPRO sits at the center of the system, with peripherals organized into three layers: the sensing layer (BH1750 ambient light, infrared beam-break obstruction detection, DHT11 temperature/humidity), the actuation layer (the RGB lamp), and the interaction layer (microphone and speaker). Internally, the ASRPRO runs a recognition engine on top of FreeRTOS; recognition results enter the command dispatcher as an interrupt ID (snid). A 1-second software timer handles auto-mode polling and the flowing-light pacing.
The mode-switching logic is designed as a one-way automatic fallback: "auto mode" is an ordinary command word (snid=19) and the only one that does not switch modes; every other command first sets the running mode back to manual before executing. The benefit is that the user can never get "trapped" in auto mode — the moment they start giving manual lighting commands, the system follows.
2.3 Component Selection
| Module | Model | Key Specifications | Role |
|---|---|---|---|
| Controller | Tianwen ASRPRO V2.0 | On-chip offline recognition + MP3 playback, multiple PWM channels | Recognition, announcement, and control core |
| Ambient light | BH1750 | I2C, 1–65535 lx, address 0x23 | Ambient illumination sensing |
| Obstruction | IR beam-break (obstacle) module | Low level when an obstacle is detected | "Someone approaching at night" detection |
| Temp/humidity | DHT11 | 1-wire, ±2℃, ±5%RH | Data source for voice announcements |
| Lighting | HW-479 common-cathode RGB lamp | Three PWM channels | Illumination and color-change actuator |
元器件套装购买:https://item.taobao.com/item.htm?ft=t&id=1060015770713
3 Hardware Design
3.1 Pin Assignment
| Peripheral | ASRPRO Pin | Resource | Notes |
|---|---|---|---|
| RGB red | PA5 (pin5) | PWM3 | Common-cathode anode PWM |
| RGB green | PA6 (pin6) | PWM4 | Common-cathode anode PWM |
| RGB blue | PA2 (pin2) | PWM0 | Common-cathode anode PWM |
| BH1750 SDA/SCL | PA1 / PA0 | Software I2C | Address 0x23 |
| IR beam-break output | PA3 (pin3) | Digital input | Low = obstruction present |
| DHT11 data | PC4 | 1-wire | Official DHTxx library |
| Debug UART | PB5/PB6 | USART 115200 | Log output |
All three RGB channels output PWM at 1 kHz with the full-brightness duty cycle set to 80% (0.8/1.0), balancing brightness against current-limiting safety. Because each color channel currently takes only two levels, 0 or 1, the duty cycle switches between 800 and 0; extending to full color mixing later only requires widening 0/1 to a 0–255 grayscale.
3.2 Reading the BH1750 over Software I2C
Since the ASRPRO's hardware I2C pins are limited, the design uses a software-I2C library (asr_softiic.h) to bit-bang the timing on PA1/PA0. Initialization sends the power-on command 0x01 followed by the continuous high-resolution mode command 0x10; on each read, the high and low bytes are fetched in sequence and converted to lux using the datasheet formula (multiply by 10, divide by 12):
uint16_t bh1750_read_lux(){
softiic.start((BH1750_ADDR<<1)|1);
uint8_t h = softiic.read(0);
uint8_t l = softiic.read(1);
softiic.stop();
return (uint16_t)(((uint16_t)h<<8|l)*10/12);
}
The beam-break module has an open-collector output, so PA3 reads it via the internal pull-up: high when the path is clear, pulled low when an obstruction is detected. The firmware treats digitalRead(IR_PIN) == LOW as "someone is nearby."
4 Software Design
4.1 Keyword Model and Command Dispatch
The speech model is generated on the Tianwen Block platform. The command set is:
| Command | snid | Action |
|---|---|---|
| 你好小智 (Hello Xiaozhi) | — | Wake up, replies "I'm here" |
| 当前温度 / 查看温度 | 1 / 8 | Announces "The current temperature is xx degrees" |
| 当前湿度 / 查看湿度 | 2 / 9 | Announces "The current humidity is xx%" |
| 加大音量 / 减小音量 | 6 / 7 | Steps volume up/down within 1–10 |
| 打开红/绿/蓝/黄灯 | 11/15/12/13 | Stops flashing and switches to that color |
| 变颜色 | 16 | Switches to a random color |
| 快速闪动 / 闪动 | 17 / 18 | Rotates colors every 1 s / 2 s for 10 s |
| 关闭灯光 | 14 | Turns the lamp off |
| 自动模式 | 19 | Enters auto polling mode |
All commands are dispatched by snid in ASR_CODE(). Except for snid=19, every command executes run_mode = MODE_MANUAL first, realizing the "speak to take over" mode fallback.
4.2 Auto-Mode Polling Logic
The auto-mode decision is consolidated into a single polling function, invoked uniformly by the 1-second timer callback:
void auto_mode_check(){
if(run_mode != MODE_AUTO) return;
uint16_t lux = bh1750_read_lux();
uint8_t obstacle = (digitalRead(IR_PIN) == LOW) ? 1 : 0;
if(lux < 50 && obstacle){
set_rgb(1, 1, 1); // dark and someone present: white on
} else {
set_rgb(0, 0, 0); // condition not met: lamp off
}
}
The light threshold is set to 50 lux: typical indoor daytime illuminance is far above this value, while a room at night with the lights off usually sits below 10 lux, so the threshold separates "daytime" from "nighttime" reliably. The lamp lights only when "nighttime" and "obstruction detected by the beam-break sensor" hold simultaneously, preventing false triggers from people passing by during the day.
4.3 Timer and Flowing-Light Effects
The system creates a 1-second FreeRTOS software timer with two duties: calling auto_mode_check() for auto-mode polling, and driving the flowing-light (flash) effects. Flashing has a fast mode (color change every 1 s) and a slow mode (every 2 s); once the counter reaches 10 seconds the effect stops automatically and holds the current color. Color rotation walks sequentially through a preset table of seven colors — red, green, blue, yellow, purple, cyan, and white — incrementing the index modulo the table length on each change, which guarantees two consecutive colors are never identical and looks more even than pure random selection.
One detail in the temperature announcement deserves mention: play_num() can only announce integers, and the DHT11 itself outputs integer-only temperature, yet the firmware multiplies the float by 100, rounds it, and plays it in a one-decimal format — leaving the interface ready for higher-precision sensors such as the DHT22.
5 Testing and Analysis
| Test Item | Method | Result |
|---|---|---|
| Wake-up and recognition | Speak every command word 5 times at normal volume within 3 m | Wake-up and all keywords recognized correctly, no false triggers |
| Single-color control | Say "open the red/green/blue/yellow light" in turn | Colors switch accurately, no flicker on repeated commands |
| Color change and flowing light | Say "change color," "flash fast," "flash" | Random color change works; effect stops after 10 s and holds the color |
| Temp/humidity announcement | Compared against a thermo-hygrometer | Temperature consistent, humidity accurate, no skipped readings |
| Volume control | Repeat "volume up/down" to the limits | Maximum/minimum announced with a prompt, no overrun |
| Auto mode | At night with lights off, block the IR sensor by hand | White light within 1 s; off after the hand is removed; no trigger in daytime |
Analysis: the keyword set is small and all commands are short phrases of about four syllables, so recognition performs well. Under the combined "50 lux + low-level obstruction" condition the auto mode acts decisively, with roughly one second of latency from trigger to light — attributable to the timer polling period and entirely acceptable for a desk lamp. Boundary handling (volume limits, sensor read-failure prompts) is fully covered.
6 Conclusion and Future Work
This paper implemented an offline voice-controlled desk lamp based on the Tianwen ASRPRO, completing keyword recognition, RGB color mixing with flowing-light effects, voice announcement of temperature and humidity, volume control, and automatic lighting when "insufficient light + someone nearby" are both satisfied. The entire system fits on a single chip with a simple peripheral circuit and low cost.
Future work can proceed in two directions: widening the RGB duty cycle from two levels to a continuous 0–255 grayscale for arbitrary color mixing and stepless brightness; and adding sustained human-presence detection to auto mode (for example, turning off automatically after a timeout with nobody present) plus a breathing-light fade-in, bringing the night-light experience closer to commercial products.