Design of a Bluetooth APP Smart Learning Desk Lamp Based on STM32F103

1. Introduction With the development of technology, smart home devices are receiving increasing attention. This article introduces a smart learning desk lamp based on the STM32F103 microcontroller, which can automatically adjust brightness according to ambient light intensity and transmit environmental data to a mobile phone via Bluetooth for remote monitoring and control.

2. System Design
2.1 Hardware Composition
• Main Controller: STM32F103C8T6, responsible for processing sensor data and controlling the LED light.
• Light Sensor: Used to detect ambient light intensity.
• Bluetooth Module: HC-05 Bluetooth module, used for communication with the mobile APP.
• LED Light: High-brightness LED, supports PWM dimming.
• OLED Display: Used to display the current light intensity and lamp status.
• Power Module: Provides a stable 5V power supply.

2.2 Software Design
• Embedded Software: Developed using the Keil MDK development environment, programming in C language.
• Mobile APP: Developed using Android Studio, implementing data reception and control interface.

3. Function Implementation
3.1 Light Intensity Detection and Automatic Adjustment The light sensor continuously detects the ambient light intensity, and the data is read through the ADC module. Based on the detected light intensity, the brightness of the LED light is adjusted via PWM to achieve automatic dimming functionality.

// Light intensity detection and automatic adjustment function<br/>void autoLightAdjust() {<br/>    uint16_t lightValue = ADC_Read(ADC_Channel_0); // Read light sensor value<br/>    float lightIntensity = (float)lightValue / 4095.0 * 100.0; // Convert to percentage<br/>    if (lightIntensity < 20) {<br/>        PWM_SetDutyCycle(100); // Dark light, full brightness<br/>    } else if (lightIntensity < 50) {<br/>        PWM_SetDutyCycle(50); // Medium brightness<br/>    } else {<br/>        PWM_SetDutyCycle(0); // Sufficient light, turn off<br/>    }<br/>    OLED_DisplayLightIntensity(lightIntensity); // Display light intensity<br/>}

3.2 Bluetooth Data Transmission The HC-05 Bluetooth module is configured as the master mode, establishing a connection with the mobile APP. Communication with STM32 is achieved through UART serial port, enabling the transmission of environmental data and reception of control commands.

// Bluetooth data sending function<br/>void sendBluetoothData(float lightIntensity) {<br/>    char data[20];<br/>    sprintf(data,"Light:%.2f%%",lightIntensity);<br/>    UART_SendString(data);<br/>}<br/>// Bluetooth command handling function<br/>void handleBluetoothCommand(char *command) {<br/>    if (strcmp(command, "ON") == 0) {<br/>        PWM_SetDutyCycle(100); // Turn on the desk lamp<br/>    } else if (strcmp(command, "OFF") == 0) {<br/>        PWM_SetDutyCycle(0); // Turn off the desk lamp<br/>    }<br/>}

3.3 Mobile APP Design The mobile APP interface includes real-time light intensity display, lamp status control buttons, and data recording functionality. The desk lamp is connected via Bluetooth for remote monitoring and control.

Design of a Bluetooth APP Smart Learning Desk Lamp Based on STM32F103

4. System Testing
4.1 Light Intensity Detection Accuracy Testing By changing the ambient light intensity, the accuracy of the light sensor detection and the automatic dimming effect are tested.
4.2 Bluetooth Communication Stability Testing The stability of the Bluetooth module’s communication is tested under different distances and interference environments to ensure the reliability of data transmission.
4.3 Mobile APP Function Testing The interface display, control button functionality, and data recording features of the mobile APP are tested to ensure user convenience.

5. Conclusion The Bluetooth APP smart learning desk lamp designed based on the STM32F103 achieves adaptive light intensity adjustment and remote monitoring functionality, enhancing the comfort and convenience of the learning environment. Through continuous optimization and improvement, this lamp can further incorporate more intelligent features, such as timed switching and color temperature adjustment, to meet the needs of different users.

Leave a Comment