How to Design a Multi-functional Smart Desk Lamp by AT89S51
1.1 Background of the Project
With the rapid development of our times, students are increasingly burdened with learning pressures, leading to a yearly rise in the incidence of myopia among schoolchildren. One of the primary reasons for this is improper sitting posture during study sessions. To address this issue, we have designed a fully automatic multifunctional intelligent desk lamp to help students alleviate this problem.
1.2 Module Descriptions
Human Body Sensor: Accurately detects whether there is anyone around the desk lamp.
Photoelectric Sensor: Determines whether the surrounding environment necessitates turning on the desk lamp.
Voice Module: Reminds users to maintain proper sitting posture and take regular breaks.
LCD Display Module: Displays the user's study time and confirms whether the sitting posture is correct.
Ultrasonic Distance Measurement Sensor: Precisely measures the distance between the user and the desk lamp, facilitating the automatic switching of the lamp and correcting the user's sitting posture.
2.1 Main Processor Chip
The main processor uses the AT89S51.
2.2 Auxiliary Chips
2.2.1 Human Body Sensor Chip
The human body sensor switch mainly consists of a passive infrared (PIR) sensor. As the human body maintains a constant temperature, it emits infrared radiation at a specific wavelength. When the infrared sensor’s lens detects this radiation, it focuses it onto the pyroelectric element through a Fresnel lens. The resulting change in charge balance on the pyroelectric element triggers an external release of charge. The connected circuitry of the infrared sensor detects this charge variation, recognizing the presence of a human and turning the switch to the "on" state. If no human presence is detected for a set period, the switch remains "on" until the preset delay lapses, after which the switch changes to "off."
2.2.2 Ultrasonic Distance Measurement Sensor
The HC-SR04 ultrasonic distance measurement sensor operates on the principle of ultrasound echo-ranging. Utilizing precise time difference measurement techniques, it determines the distance between the sensor and the target object. This sensor features a small angle and blind zone, offering accurate measurements without contact. It is waterproof, corrosion-resistant, and cost-effective, making it suitable for level detection in various applications. Its unique design ensures stable output even in challenging conditions such as foamy or highly agitated liquid surfaces. It finds utility in industries for liquid level, material level detection, and industrial process control.
3. Circuit Connection Diagram
3.1 Pin Control Diagram
4.1 Key System Technologies
4.1.1 Ultrasonic Distance Measurement Technology
The ultrasonic transmitter emits ultrasonic waves in a specific direction and starts timing simultaneously at the moment of emission. These waves travel through the air, and upon encountering an obstacle, they are reflected back. The ultrasonic receiver stops timing as soon as it receives the reflected waves. The speed of ultrasonic waves in air is 340m/s, and using the recorded time ( t ), the distance ( s ) from the emission point to the obstacle can be calculated as ( s = 340t/2 ). This method is known as the time-difference distance measurement. Ultrasonic waves are preferred over infrared for distance measurement due to their higher accuracy and broader measurement range.
4.1.2 PWM Dimming Technology
PWM stands for Pulse Width Modulation. It has two fundamental parameters: frequency and duty cycle. Frequency refers to the number of high-low level changes per second, while the duty cycle indicates the proportion of high-level duration to the entire pulse period. For simulating PWM using a timer, the basic method involves cyclically setting the output value of an IO port to high and low levels. The timer functions as a clock, requiring two time durations: high-level sustain time and low-level sustain time. By adjusting the ratio of these two times, basic PWM dimming can be achieved.
4.2 Functional Features
This design centers on the AT89S51 microcontroller, supplemented with various sensors to create a multifunctional smart desk lamp. The lamp boasts the following features:
It is powered via a USB port, making it a rechargeable desk lamp. It can be charged using a computer, power bank, or a dedicated power adapter. Additionally, the lamp can charge a mobile phone when its battery is low.
It offers two control modes: manual and automatic. In manual mode, the brightness of the lamp is adjusted via buttons. In automatic mode, the brightness varies based on the distance between the user and the lamp, with the current distance displayed on an LCD screen.
In automatic mode, if the user gets too close to the lamp, reaching a preset threshold, the lamp will automatically issue a voice reminder to maintain proper posture, accompanied by a corresponding prompt on the LCD screen. If the user moves too far away and the human presence sensor detects no one, the lamp will automatically turn off.
Upon activation, the system begins timing, displaying the elapsed time on the LCD1602 screen. Users can set study or work durations via buttons. The lamp provides timely voice reminders for breaks, also shown on the LCD screen. If the user leaves during this period, the timer pauses, resuming when they return. Alternatively, users can reset the timer to zero and start anew.
5.System Display Diagram