1. Project Background
Intelligent home devices play an increasingly important role in modern life. As one of them, intelligent desk lamps have functions like adjusting brightness and color temperature to better meet people's needs for customized lighting environments. This article introduces the design of an intelligent desk lamp based on the STM32 microcontroller, which can adjust brightness and color temperature to provide users with a more comfortable experience.
2. Design Goals
[1] Implement adjustable brightness and color temperature functions.
[2] Add human body sensing module for automatic on/off.
[3] Enable remote control of the lamp with a mobile phone.
[4] Design simple, stable hardware circuits and user-friendly interfaces.
3. System Architecture
3.1 Hardware
(1) MCU: STM32 series with rich peripherals and powerful processing capabilities.
(2) Power supply: stable voltage regulator.
(3) Light source: high-brightness LEDs with diffuser for even and soft lighting.
(4) Human body sensing: infrared sensor to detect human presence and turn on light.
(5) Wireless communication: WiFi/Bluetooth module for remote control with mobile app.
3.2 Software
(1) Embedded software: Keil MDK, embedded C language programs for functions like brightness/color temperature control, human sensing, etc.
(2) Mobile app: remote control of desk lamp functions.
3.3 Hardware Selection
[1] MCU:
STM32F103RCT6
[2] Light source:
(1) High-brightness LEDs
(2) Transparent lamp cover for even lighting
[3] Human body sensing:
(1) High sensitivity infrared sensor
(2) Photoresistor for low light activation
[4] Wireless module:
HC05 Bluetooth module for communication with mobile device.
3.4 Hardware Design
[1] MCU: STM32F103RCT6
[2] Infrared sensor: human presence detection
[3] Photoresistor: ambient light intensity
[4] LED: light source with PWM brightness control
[5] HC05 Bluetooth: communication with mobile app
3.5 Software Design
[1] GPIO config: input pins for sensors, output pin for LED control
[2] External interrupt: detect infrared sensor state changes
[3] PWM: control LED brightness based on ambient light
[4] Bluetooth: serial communication with HC05 and mobile app
[5] Main loop: real-time sensing, automatic on/off, remote control commands
4. Main Functions
[1] Adjustable brightness and color temperature with buttons or knobs. Brightness uses PWM, color temperature uses relative LED brightness.
[2] Automatic on when human presence detected, off after period of no detection.
[3] Remote control from mobile app via Bluetooth, including on/off, brightness, and color temperature.
5. Code Implementation
5.1 PWM for LED Brightness Control
// PWM configuration and control code
void PWM_Configuration(void) {
// Configures PWM on TIM2 and GPIOA
TIM_Cmd(TIM2, ENABLE); // Enables TIM2
}
void main() {
PWM_Configuration();
// Fade LED brightness up and down
for (i = 0; i <= 1000; i++) {
TIM_SetCompare1(TIM2, i); // 0-1000 duty cycle
Delay(5000);
}
for (i = 1000; i > 0; i--) {
// Fade down
}
}
5.2 Main Logic
// Libraries
#define PINS // Pins configured
// Global variables
// Initialization
void setup() {
// Pin modes
// Init Bluetooth serial
}
// Main loop
void loop() {
// Read sensors
// Control LED based on sensors
// Handle Bluetooth commands
}
// Bluetooth command handler
// Main function
int main() {
setup();
while (1) {
loop();
}
}
6. Conclusion
This article introduced the design and implementation of an intelligent STM32-based desk lamp. Features like automatic on/off, brightness adjustment, and remote control via mobile app provide intelligent lighting. The Bluetooth connection enables convenient remote control of the lamp.
Comments