1. Introduction Noise, as an environmental issue that cannot be ignored in modern society, makes monitoring and control particularly important. With the development of technology, designing a noise detector using microcontroller technology has become an efficient and economical solution. This article will introduce a noise detector design based on the 51 microcontroller, which can not only monitor environmental noise in real-time but also provide scientific basis for environmental noise management through big data collection and analysis.
2. Hardware Design
1. Core Controller This design uses the 51 microcontroller as the core controller. The 51 microcontroller, known for its low power consumption, high performance, and rich peripheral interfaces, has become the preferred choice for embedded system design. The chip selected in this design is compatible with all 51 series microcontrollers, including the AT series and STC series.
2. Noise Sensor The noise sensor uses a high-sensitivity microphone that can capture sound signals in the environment. The analog signal output from the sensor is amplified by an LM358 amplifier circuit and then sent to the ADC0832 for analog-to-digital conversion.
3. Display Module The display module uses an LCD1602 liquid crystal display to show the noise decibel value in real-time. The LCD1602 features low power consumption and high clarity, making it suitable for embedded system applications.
4. Alarm Module The alarm module consists of a buzzer and an LED indicator. When the noise decibel value exceeds the preset threshold, the buzzer sounds, and the red LED indicator flashes, alerting the user to noise pollution.
5. Key Module The key module includes a set key, an increase key, and a decrease key, used to set the noise alarm threshold. Users can adjust the threshold through the keys for personalized settings.
6. Power Module The power module uses a 5V DC power supply to ensure stable operation of the system. The power module is also designed with a power indicator light for easy observation of the power status.
3. Software Design
1. Main Program Flow The main program first initializes each module, including the LCD1602, ADC0832, timer, etc. It then enters a loop, continuously reading data from the noise sensor, performing analog-to-digital conversion and data processing. Based on the processing results, it updates the display content and determines whether to trigger the alarm. At the same time, the main program also handles key events to implement the threshold setting function.
2. ADC0832 Driver Program The ADC0832 driver program is responsible for converting the analog signal into a digital signal. The driver program uses the successive approximation method to ensure conversion accuracy. The converted data is filtered to eliminate interference and improve measurement accuracy.
3. LCD1602 Driver Program The LCD1602 driver program is responsible for displaying the noise decibel value and alarm threshold. The driver program uses character display mode for fast refresh. Additionally, the driver program supports Chinese character display for user convenience.
4. Alarm Handling Program The alarm handling program is responsible for determining whether the noise decibel value exceeds the threshold. When it exceeds the threshold, it triggers the buzzer and LED indicator alarm. The alarm handling program also supports alarm delay functionality to avoid false alarms.
4. Big Data Collection and Analysis
1. Data Collection This design collects noise data in real-time through the 51 microcontroller and transmits it to the host computer via serial port. The host computer uses a Python-written data collection program to achieve real-time data reception and storage. Data storage uses SQLite database to ensure data security and reliability.
2. Data Analysis Data analysis uses Python’s Pandas library and Matplotlib library. The Pandas library is used for data cleaning, organization, and analysis, while the Matplotlib library is used for data visualization. Through statistical analysis of noise data, the changing patterns of environmental noise can be derived, providing a scientific basis for noise management.
The following is the main source code:
#include <reg51.h><br/>#include <intrins.h><br/>#include "LCD1602.h"<br/>#include "ADC0832.h"<br/>#define K_ZERO 130 // Zero drift value<br/>sbit beep = P2^3; // Buzzer<br/>sbit led0 = P2^4; // Green light<br/>sbit led1 = P2^5; // Red light<br/>sbit set = P3^0; // Set key<br/>sbit add = P3^1; // Increase key<br/>sbit sub = P3^2; // Decrease key<br/>int sum = 0;<br/>int temp = 0;<br/>int m = 0;<br/>int WARNING = 70; // Default alarm threshold<br/>bit flag = 0;<br/>void main() {<br/> Init1602(); // Initialize LCD1602<br/> init(); // Initialize timer<br/> while(1) {<br/> for(m = 0; m < 50; m++) {<br/> sum = adc0832(0) + sum;<br/> }<br/> temp = sum / 50;<br/> if(temp > K_ZERO) {<br/> temp = (temp - K_ZERO) / 2.0;<br/> }<br/> else {<br/> temp = 0;<br/> }<br/> sum = 0;<br/> if(set == 0) {<br/> Display_1602(temp, WARNING);<br/> if(temp < WARNING) {<br/> flag = 0;<br/> }<br/> else if(temp > WARNING) {<br/> flag = 1;<br/> }<br/> }<br/> Key(); // Handle key events<br/> // Alarm handling<br/> if(flag == 1) {<br/> beep = ~beep;<br/> led0 = 1;<br/> led1 = 0;<br/> }<br/> else {<br/> beep = 1;<br/> led0 = 0;<br/> led1 = 1;<br/> }<br/> }<br/>}