Back
 OALibJ  Vol.8 No.8 , August 2021
STM32-Based Intelligent Desk Lamp Design and Implementation
Abstract: Table lamps have long been one of the necessities of people’s life and work, as they appear and are used very frequently in household lighting equipment. Table lamps provide the right amount of light for people to work and study in their daily lives. Compared with the general traditional desk lamp, intelligent desk lamps provide a more comfortable lighting environment for people to read, work and study. The paper firstly analyzes the system scheme of the intelligent desk lamp and completes the hardware selection, using STM32F103C8T6 as the main control, HR-SR501 module as the pyroelectric module of the intelligent desk lamp. HC-SR04 ultrasonic distance measures sensor for distance measurement. Bluetooth module HC-05 is the wireless control module of the lamp. Then the interface circuit design of each functional module is completed by drawing schematic diagram through Altium Designer. The program design of each function by drawing program flowchart is completed. The program is written through keil5. Finally, the automatic adjustment of lighting intensity, posture reminder, human infrared sensing and wireless control of the intelligent lamp are realized through a combination of hardware and software. Desk lamp has the advantages of simple operation, energy saving, sitting posture reminder, automatic dimming and wireless control, etc. Compared with the general traditional desk lamp, it solves the problems of traditional desk lamp control not simple enough, high energy consumption and being easy to cause visual fatigue or myopia; therefore, it has high application value and market value.

1. Introduction

Along with the continuous development of technology and people’s rising standard of living and quality of life, people have begun to put forward more and more demands for home appliances, and the demand has gradually changed from the initial single function to the intelligent and simple operation design of home appliances. Compared with traditional home appliances, smart appliances can not only be set and controlled according to the user’s needs, but can also perform personalized operations according to the user’s home environment and habits [1].

Lighting affects the efficiency of work and study, and when people are in poor lighting conditions, they will be less efficient in work and study due to visual fatigue and other problems [2]. While desk lamps are created for similar activities such as reading and writing, it is a movable lamp that provides localized lighting [3]. In modern society, myopia caused by poor sitting posture such as hunchback is very common among adolescents, which causes a lot of inconvenience in daily life. As a household lighting device, the desk lamp is used very frequently and is essential in people’s daily study and work. Traditional desk lamps only have simple lighting functions and require manual control of the lamp, which is a single function [4] [5]. Those intelligent desk lamps with sitting sensing function can provide more scientific and intelligent lighting conditions [6]. Smart desk lamps with pyroelectric detection can detect biological activity around them, and when there is no activity around, the lamp will turn off the lighting after a time delay [7]. As a smart desk lamp, although most of them have integrated multiple functions that allow the lamp to be used in different situations, the core function of the lamp is still the ability to provide a comfortable lighting environment for the user [8].

As the first electric lamp, the incandescent lamp is heated by energizing the filament, and when it becomes incandescent, the visible light is emitted by the thermal radiation generated by the filament. Because the light emitted is very close to the spectrum of the sun, it can faithfully restore the original color of the displayed object [9]. Fluorescent lamps, also known as fluorescent lamps, rely on phosphors on the inside of the lamp to adjust the color of light, and changing the type of phosphor can change the color of light emitted [10]. And in the process of bonding, light will be generated, the light-emitting phenomenon is caused by the release of photons [11]. Nowadays, the mainstream light sources are using LED lights for lighting.

The task of this project is to use the STM32 microcontroller as the control core, combined with the sensor module, design a lamp to achieve automatic lighting, intelligent dimming, remind to change the sitting posture, night light and other functions, through the wireless sensor transmission data and cell phone APP for real-time control of the lamp, with the collection of environmental parameters around the function of intelligent desk lamp, to achieve energy saving and convenience purposes.

2. Overall Design of Smart Desk Lamp

2.1. The Working Principle and System Structure Diagram of Intelligent Desk Lamp

The intelligent desk lamp designed in this project is based on STM32F103C8T6 microprocessor as the core control unit, with several sensor modules to achieve various functions. The main modules of the control system of this design are: light intensity detection module, distance measurement module, pyroelectric module, alarm module, power supply module, button module, wireless communication module and lighting module. The photoresistor sensor detects the light intensity of the environment and converts the detected light intensity into a specific numerical value, the HC-SR501 pyroelectric sensor detects the activity of people, the HC-SR04 ultrasonic distance sensor detects the distance between the user and the lamp, the buzzer reminds the user, the keypad adjusts the lighting intensity of the lamp, and the HC05 Bluetooth serial module to establish a connection between the lamp and the cell phone for wireless communication. After the wireless connection is established through the Bluetooth module, the lighting intensity of the lamp can be adjusted and the current mode of the lamp can be changed wirelessly through the cell phone APP. The lighting part uses a triode to drive 12 LEDs to achieve lighting, and adjusts the lighting intensity through PWM. For the power supply, 5.0 USB power supply is used, and the 5.0 volt voltage is stepped down to 3.30 volts through the step-down module, of which 3.30 volts is provided to the microcontroller, Bluetooth module and light detection module, and 5 volts is supplied to the HC-SR501 pyroelectric module and HC-SR04 ultrasonic module, as shown in Figure 1.

2.2. Functional Design of Smart Desk Lamp

This design of smart table lamp receives and processes various information by microcontroller, and adjusts the lighting brightness of the lighting LED lamp according to the information. The smart desk lamp has three working modes,

Figure 1. System structure diagram.

namely manual operation mode, intelligent adjustment lighting mode and night light mode. After the lamp is powered on, the lamp is in manual operation mode by default or reset, and the user can switch the operation mode of the lamp through the mode switch button. In manual operation mode, users can press the lighting switch button to adjust the lighting intensity of the lamp, or use Bluetooth to connect the phone to the lamp and adjust the lighting intensity of the lamp and switch the lamp mode through the mobile app. In the intelligent adjustment of lighting mode, the lamp will detect whether there is human activity around, and if there is activity, it will detect the brightness of the surrounding environment and automatically adjust the lamp lighting according to the environmental brightness. After switching to night light mode, when the external light is low, the desk lamp will turn on the pyroelectric sensor and ultrasonic distance measurement mode, and when the human body is detected to be close to the desk lamp, the desk lamp will turn on a light with lower brightness to facilitate users’ activities at night. In addition to the three modes, the lamp also has a distance measurement function, which can be controlled by a button to turn it on or off. When the distance measurement function is turned on, the lamp can detect the distance between the user and the lamp in real time to determine whether the user’s sitting posture is reasonable, and if it is not, the lamp will trigger a buzzer alarm to remind the user to adjust the sitting posture.

3. Hardware Design of Smart Desk Lamp

3.1. Hardware Selection and Justification

3.1.1. Selection and Demonstration of the Main Control Chip

As the 8051 microcontroller has less timer function and no ADC function, an external analog-to-digital converter chip is needed to convert the analog value measured by the photoresistor sensor to a specific digital. 8051 microcontroller has a low clock frequency of less than 12 MHz and poor performance. The microcontroller selected for this design is the STM32F103C8T6, which has a higher clock frequency (up to 72 MHz) and strong performance.

3.1.2. Selection and Justification of Pyroelectric Sensors

The principle of HR-SR501 module is the same as that of HR-SR602 module, but the sensing range of HR-SR501 module is larger (up to 7 meters). Compared with the HR-SR602 module, the HR-SR501 module is more convenient to adjust the delay time by simply turning the corresponding knob, as shown in Figure 2.

The pins of the HC-SR501 pyroelectric human sensor module are shown in Figure 3. As seen in Figure 3, the sensor’s pins include a power supply pin, a time delay pin, a sensitivity adjustment pin, and a trigger method pin.

3.1.3. Selection and Justification of the Distance Measurement Module

Infrared distance measurement module GP2Y0A21YK0F, which uses triangulation, and its output voltage value can be converted to get the distance. The sensor can be used for distance measurement, obstacle avoidance, etc. The measurement range is between 10.0 cm and 80.0 cm. Compared with the HC-SR04 module, its distance measurement range is small, but its accuracy is high. Therefore, the HC-SR04 ultrasonic distance measurement sensor of Option 1 is selected, as shown in Figure 4.

3.1.4. Selection and Justification of Light Detection Module

The photoresistors are very sensitive to light, the stronger its light the lower the resistance. Due to the characteristic of its resistance value changing with the light intensity, the photoresistor has gained wide application. The change in the resistance value of the photoresistor changes the voltage of the photoresistor, and the change in its voltage and can respond to the light intensity of the environment. However, since its voltage change is an analog quantity, it needs to be converted to a digital quantity by AD before it can be used, as shown in Figure 5.

Figure 2. HC-SR501 pyroelectric human sensor module.

Figure 3. The pins of the HC-SR501 pyroelectric human sensor module.

Figure 4. HC-SR04 ultrasonic distance measuring sensor.

Figure 5. Photoresistor sensor.

Figure 6. HC-05 bluetooth module.

3.1.5. Selection and Justification of Wireless Communication Modules

HC-05 Bluetooth module compared with ESP8266wifi module, the price of both is basically the same, but the development and programming of HC-05 Bluetooth module is much easier than ESP8266wifi module, because ESP8266wifi module itself is a microcontroller, you need to develop and program it separately. Therefore, this design selects the Bluetooth module HC-05 as the wireless control module of the desk lamp, as shown in Figure 6.

3.2. Hardware Circuit Schematic

The pins of STM32F103C8T6 that need to be used in this design of smart desk lamp are: the output port of pyroelectric module is connected to PA8 port of microcontroller, the control input of ultrasonic distance measurement module is connected to PA4 port of microcontroller, and the output of ultrasonic module is connected to PB6 pin. The analog output of the photoresistor sensor is connected to the PA0 port of the microcontroller. The transmit and receive pins of the Bluetooth module accumulate to pins PB10 and PB11 of the microcontroller, respectively, and use the USART3 function of STM32 to communicate with the microcontroller. The keypad module uses the microcontroller’s PB12 port to receive external voltage. The LED lighting module uses the microcontroller’s PA6 port to output PWM square wave, thus regulating the lighting. The Intelligent desk lamp microcontroller I/O port and resource allocation table is shown in Table 1.

This design uses STM32F103C8T6 minimum system board as the main control core, with manual control, intelligent control and wireless control functions. In manual control, the lighting control of the lamp can be completed by using only one button; in smart control mode, the lamp can adjust the lighting brightness according to the brightness of the surrounding environment and the state of the user; in wireless control, the lighting of the lamp can be controlled by Bluetooth using a cell phone. The overall design block diagram is shown in Figure 7.

Table 1. Intelligent desk lamp microcontroller I/O port and resource allocation table.

Figure 7. Overall design block diagram.

4. Software Design of Smart Desk Lamp

There are three control modes available in this design: one is to use the buttons on the lamp, which is also the default mode; one is the intelligent dimming mode, in which the lamp will automatically adjust the lighting in combination with the surrounding light intensity and the activities of people around the lamp without human intervention; and one is the night light mode, which can provide lighting for users when they are active at night.

After choosing the manual mode, the lighting can only be adjusted by the buttons on the lamp, or wirelessly adjust the lamp lighting through the cell phone APP, and the cell phone wireless control and button control can be used at the same time, without conflict. After selecting the control mode of intelligent lighting adjustment, the lamp will automatically adjust the lamp lighting according to the current specific environmental brightness when people are detected and the current light is low; if the posture reminder function is turned on at the same time, the lamp will issue a reminder when it detects the user's poor posture to remind the user to correct the posture; after switching to night light mode, the lamp can be used as a bedside lamp and other night lighting tools, and when the user is up and moving in the dark, the lamp will turn on. When users get up and move around in the dark, the lamp will turn on the lower lighting to provide light to users and not to affect other users’ sleep because of too bright light. The flow chart of the main program is shown in Figure 8.

Figure 8. Main program flow chart.

5. Product Commissioning

5.1. Commissioning of Pyroelectric Sensors

When the pyroelectric module is powered on, an LED is connected to its output pin, and the LED will light up when the pyroelectric module is working normally. As shown in Figure 9, the LED lights up after triggering the pyroelectric module.

5.2. Commissioning of Ultrasonic Sensors

For the detection of ultrasonic module, according to its working principle, it is difficult to judge whether it can work normally by hardware circuit only, so it is necessary to burn the test program to the microcontroller and connect the pins of ultrasonic module to the corresponding pins of the microcontroller correctly. Then by constantly adjusting the distance between the object under test and the ultrasonic module, use the serial port to send the data to the computer side to see whether the output distance corresponds to the actual distance, so as to determine whether the ultrasonic module works properly. The ultrasonic module ranging data sheet is shown in Table 2. A total of six sets of experiments were conducted, and the test distances selected for the experiments were 10, 20, 40, 45, 60 and 100 cm. The measured values are shown in Table 2. The ultrasonic module can measure the distance within 80 cm, and the error is within 3 cm; when the measurement range exceeds 80 cm, the error is larger than 3 cm.

Figure 9. Table lamp lights up after triggering pyroelectricity.

Table 2. Ultrasonic module ranging data sheet.

6. Conclusions

The main functions of the STM32-based intelligent desk lamp design required by this topic are as follows.

1) Manual control (keypad): In manual control mode, the lighting intensity of the desk lamp can be adjusted by the number of keystrokes, so as to select the appropriate lighting intensity.

2) Manual control (cell phone wireless control): In the manual control mode, the lighting of the lamp can be controlled wirelessly by cell phone. And in the manual control mode, the cell phone control and button control do not conflict, and can be seamlessly switched.

3) Intelligent dimming mode: In this mode, the intelligent desk lamp can automatically adjust the lighting intensity of the lamp according to the ambient light intensity and whether there are people around. After detecting someone around, it will adjust the lamp lighting appropriately according to the current ambient light intensity.

4) Posture reminder mode: In this mode, the smart desk lamp can detect the distance from the user to the lamp through the ultrasonic distance measurement module. When the distance between the user and the lamp is detected to be too small and lasts for more than 3 seconds, the alarm system will issue a reminder to urge the user to stay away from the lamp, and the buzzer will end the alarm after the user stays away from the lamp.

5) Night light mode: In this mode, the smart desk lamp can be used as a night light. When the ambient brightness is low, when the desk lamp detects someone’s activity nearby, it will turn on the lower brightness lighting to facilitate the user’s action in the dark, but the desk lamp lighting turns off after the user immediately.

Acknowledgements

This research was supported by the Doctoral Research Initiation Fund of Guilin University of Technology (GUTQDJJ2018068) and 2020 Guangxi University Middle-aged and Young Teachers’ Basic Research Ability Improvement Project (2020KY06024).

Cite this paper: Lian, Y.Y., Wu, D. and Ji, Z.L. (2021) STM32-Based Intelligent Desk Lamp Design and Implementation. Open Access Library Journal, 8, 1-11. doi: 10.4236/oalib.1107754.
References

[1]   Wang, L. and Zheng, L. (2019) Design and Implementation of Wireless Control System for Home Table Lamp. Practical rural Technology, No. 6, 126.

[2]   Liu, J.Y., Xu, L.K. and Wang, J.H. (2020) Comprehensive Evaluation of Desk Lamp Lighting Based on Light Environment. Industrial Design, No. 4, 91-92.

[3]   Hu, S. and Lu, D. (2020) Design of a Rapid Testing System for Table Lamp Photometric Performance. Electromechanical Information, No. 11, 124-125.

[4]   Feng, M. (2017) Design of Intelligent Table Lamp System Based on 51 Microcontroller. Electrical and Mechanical Engineering Technology, No. S2.

[5]   Xiong, Z. and Wang, R. (2016) Intelligent Learning Desk Lamp Design Based on STM32. Electronic World, No. 8, 160-161.

[6]   Luo, Y. (2020) An Intelligent Desk Lamp Design with Sitting Sensing Function. Information Recording Materials, 21, 131-132.

[7]   Qin, Z. (2020) Analysis of the Application of Microcontroller in the Field of Intelligent Home Appliances. China Equipment Engineering, No. 3, 31-33.

[8]   Song, J., Li, J. and He, X. (2019) New Thinking on the Development of Intelligent Reading and Writing Desk Lamp. Light Sources and Lighting, No. 3, 44-48.

[9]   Li, Z. (2016) Colin Fernandez. Incandescent Light Bulbs Are Expected to Be “Put Back in Service” with New Technology. China Lighting Appliance, No. 4, 42-43.

[10]   Zheng, X. (2019) How to Buy Table Lamps. Rural Pepsi, No. 16, 54-55.

[11]   Xia, W. (2018) The Characteristics, Applications and Prospects of LED Lights. Science and Technology Wind, No. 2, 115.

 
 
Top