Design of alcohol concentration detector based on STM32 microcontroller

Publisher:MysticalDreamerLatest update time:2014-01-21 Source: 电子设计工程 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Introduction
    Drunk driving is an important cause of traffic accidents, which brings great harm to people's lives and life safety. In order to prevent motor vehicle drivers from driving after drinking, the on-site real-time inspection of the alcohol content in human breath has received increasing attention. Aiming at the problem of long recovery time of existing alcohol sensors, this system successfully realizes rapid alcohol concentration detection by calculating the slope, shortens the detection interval time, and greatly improves the efficiency of alcohol detection.

1 Overall structure of alcohol concentration detector
   
The alcohol concentration detector consists of a single-chip microcomputer, an alcohol sensor, a signal conditioning circuit, a voice alarm module, a TFTLCD display module, a communication module, a power amplifier module, etc. The structural block diagram is shown in Figure 1. Since the voice alarm module and the TFTLCD display module have high requirements for the processing speed and processing data volume of the single-chip microcomputer, and the alcohol detection reaction speed is fast and the real-time performance is high, the STM32 series single-chip microcomputer of ST Company is used as the main control end. ME3-C2H5OH electrochemical gas sensor has the advantages of low power consumption, high precision, high sensitivity, wide linear range, strong anti-interference ability, excellent repeatability and high stability.

a.JPG



2 Hardware Design
2.1 Design of MCU and its peripheral interface
   
The MCU adopts low-power and high-speed industrial-grade chip STM32F103VET6. The STM32 series is based on the ARM Cortex-M3 core designed for embedded applications requiring high performance, low cost and low power consumption. The STM32F103 is an "enhanced" series with a clock frequency of 72MHz, 512KB ROM, 64KB RAM, 80 common I/O ports, 8 timers/counters, 3 SPI, 2 I2C buses, 3 UARTs, 1 USB, 1 CAN bus and other communication ports. It has 2 I2S audio ports, 1μs dual 12-bit ADC, 4 Mbps UART, 18Mbps SPI, 18 MHz I/O flip speed, and internally integrates excellent safety clock mode, low-power mode with wake-up function, internal RC oscillator, embedded reset circuit, etc., which fully meet the design requirements of this alcohol concentration detector.
    The power supply circuit uses LM2596 as the primary voltage conversion chip to provide 5 V voltage to power the peripheral modules, and uses AMS-3.3 as the final voltage conversion chip to provide 3.3 V voltage to power the STM32. The output current of this chip can reach 1 A, the input voltage regulation rate is less than 0.2%, the load regulation rate is less than 0.4%, and the output voltage is stable.
    The watchdog circuit uses the system μP monitoring chip IMP706 produced by IMP Company of the United States. IMP706 can generate a reset signal during power-on, power-off or manual operation. The device contains a 1.6 s watchdog timer and a 4.4 V power supply voltage monitor. In addition, IMP706 also has a 1.25 V threshold power failure alarm circuit, which can be used to detect battery voltage and non-5 V power supply.
2.2 Alcohol sensor
   
The ME3-C2H5OH alcohol sensor works according to the electrochemical principle. It uses the electrochemical oxidation process of the gas to be tested on the working electrode potential in the electrolytic cell. The current generated by the electrochemical reaction of the gas to be tested is proportional to its concentration and follows Faraday's law. The concentration of the gas to be tested can be determined by detecting the magnitude of the current. The detection and processing circuit of the ME3-C2H5OH sensor is shown in Figure 2. The sampling voltage is obtained by the sampling resistor R1 in response to the alcohol concentration in the exhaled gas of the subject, and the sampling voltage is amplified through the op amp negative feedback amplifier circuit. The RT in the circuit is a thermal resistor, which is used to offset the temperature drift and ensure a constant amplification factor. The amplified voltage signal is sent to the ADC of the STM32, and the data after A/D conversion is analyzed and processed. Finally, the alcohol concentration is calculated to determine whether the subject is drinking. The judgment result is voice prompted by the voice chip, and then the concentration value is displayed on the LCD.

b.JPG


    Figure 3 shows the sensitivity, response recovery and output signal characteristics of the alcohol sensor, and Figure 4 shows the concentration linear characteristic curve. It can be seen from Figures 3 and 4 that the ME3-C2H5OH type electrochemical element has high sensitivity, fast response speed, small zero drift, and this element is linear. Therefore, the use of this type of electrochemical element to detect alcohol concentration values ​​has high accuracy and fast response.

c.JPG


2.3 Voice Alarm Module
   
The XF-S4040-CN Chinese speech synthesis chip is a brand-new Chinese speech synthesis chip designed based on the InterSound4.6 Chinese speech synthesis system and launched by Anhui University of Science and Technology iFlytek Information Technology Co., Ltd. The chip can receive commands and text to be synthesized through the asynchronous serial port (UART) and I2C bus interface, and directly synthesize it into speech output. It is mainly aimed at mid-to-high-end application fields, providing a set of speech synthesis solutions with excellent speech synthesis effects and extremely small size. The circuit of the speech synthesis module is shown in Figure 5.

f.JPG


    The XF-S4040-CN Chinese speech synthesis chip is designed for embedded applications and has the ability to synthesize any Chinese text and English letters. The main features of this chip are high naturalness of synthesized speech, simple and convenient control interface, and powerful adjustable functions. The operation command format is as follows. [page]

d.JPG


    The operation routine based on the serial port is as follows:
    e.JPG
    g.JPG
2.4 The power amplifier module
   
TDA7266 is a dual-channel audio stereo amplifier, packaged in the form of MULTI-WATT, specially designed for high-quality audio amplifier circuits of music equipment and color TVs. The voice signals of the left and right channels output by the voice alarm module enter the TDA7266 amplifier through the potentiometer to amplify the voice signals. The potentiometer is used to adjust the volume. After amplification, two audio signals are output, and these two channels are connected to two speakers respectively.

h.JPG


    The TDA7266 amplifier circuit is simple and has good sound effects, so it is widely used in high-quality audio amplification. The amplifier module circuit is shown in Figure 6.
2.5 Communication module
   
When the communication distance is required to be from tens of meters to thousands of meters, the RS-485 serial bus is widely used. RS-485 uses a combination of balanced transmission and differential reception, so it has the ability to suppress common-mode interference. In addition, the bus transceiver has high sensitivity and can detect voltages as low as 200 mV, so the transmission signal can be recovered thousands of meters away. The RS-485 interface bus allows up to 128 transceivers to be connected, that is, it has multi-station capabilities, so that users can easily establish a device network using a simple RS-485 interface. In this design, it is precisely considering that the data of the alcohol concentration detector may be transmitted back to the computer host terminal, requiring a relatively long transmission distance and low signal distortion, so RS-485 communication is selected.
2.6 TFTLCD display module
   
When the alcohol concentration detector is in use, it is necessary to display the alcohol concentration value and alarm information. At the same time, it is also necessary to enter the preset value of the alcohol concentration alarm point to set the range of the alcohol concentration alarm. Therefore, this design uses TFTLCD to display the alcohol concentration value. TFTLCD has a touch function and can be used to input the preset value of alcohol concentration.
    TFTLCD uses a 260,000-color TFTLCD screen with a resolution of 320×240, which can realize a friendly human-machine interface display. TFTLCD uses ILI9320 produced by Ilitek, which can communicate with the microcontroller through multiple parallel communication methods. The TFTLCD screen has a resistive touch screen, which is controlled by pressure sensing. The ADS7846 produced by TI is used as the touch screen control chip. ADS7846 integrates a 12-bit successive approximation A/D converter with a conversion frequency of 125 kHz. When in use, ADS7846 obtains the X and Y
coordinates of the contact position through two A/D conversions, communicates with STM32 through the SPI bus, and completes the input of control information.

3 Software Design
3.1 Overall Software Design
   
After the system is initialized, the value of the alcohol concentration sensor is first collected, and do...while() is used to wait for the sensor to initialize until the optimal state, otherwise it will wait. After the sensor is initialized, it enters the cycle detection mode. When someone blows, it can be detected according to the range of slope changes, and then it can be judged whether the person is drinking. When alcohol gas is detected, the conductivity of the sensor will increase with the increase of gas concentration, resulting in an increase in the voltage of the voltage divider resistor connected to the sensor. The 7th channel of the A/D interface of the microcontroller will collect this voltage. When the voltage value increases to a certain extent, that is, when the alcohol concentration reaches the set value, the flag position will be set to the drinking state; if the voltage decreases, that is, the alcohol concentration is zero, the flag position is in the normal state. According to the above two different states, the buzzer, voice module and LED indicator light will give different alarms. The microcontroller continuously performs timed A/D conversion, and performs filtering and comparison in the conversion end interrupt. The difference between the two A/D measurement values ​​is the rate of change of the voltage, that is, the required slope value. This value is compared with the slope range value set before, so as to judge whether the person being tested is drinking. The LCD will always filter and average the collected values ​​for dynamic display.
3.2 Slope Algorithm Design
   
The design of the slope algorithm mainly uses the timing A/D conversion resources of the microcontroller. According to the previous description, it is necessary to calculate the slope of the voltage change, that is, the range of voltage change within a certain period of time. The timing A/D conversion function can easily achieve this requirement.

i.JPG


    Figure 7 is the A/D conversion interrupt program flow chart. In the main program, corresponding operations can be performed according to the flag bit set by this interrupt, such as voice playback control, buzzer alarm, LED flashing, etc.

Conclusion
   
This article introduces in detail the design method of alcohol concentration detector based on STM32. The detector has the advantages of high precision, high sensitivity, friendly human-computer interaction, intelligent voice alarm, and easy to carry. It can be used in various occasions where human alcohol content needs to be detected, especially for the detection of drunk driving, and has broad application prospects.

Reference address:Design of alcohol concentration detector based on STM32 microcontroller

Previous article:Design of DDS Signal Source in Quartz Crystal Test System
Next article:Energy spectrum nuclear well logging instrument based on embedded system

Recommended ReadingLatest update time:2024-11-17 00:51

Analysis of the reasons why stm32 external interrupt cannot enter
I have been tinkering with stm32 in recent days and encountered a very frustrating problem. The external interrupt could not be entered. When I finally found a solution, I felt... Well, here are a few reasons to help you avoid detours. 1. Remember to turn on the multiplexed clock: RCC_APB2PeriphClockCmd(RCC_APB2Periph
[Microcontroller]
Analysis of the reasons why stm32 external interrupt cannot enter
stm32 uses J-LINK to download
1. Hardware Connection 2. Software Settings MDK5 1. Modify debug to J-LINK/J-TRACE Cortex Click setting, open Flash Download, and modify Programming according to memory 2. Return to the previous level and modify Utilities I used the default configuration here
[Microcontroller]
STM32 MCU timer debugging square wave output
Today I tried to make the STM32 timer output a 50% duty cycle signal. I wrote a square wave initialization function according to the routine. The routine used the STM32's own library function. Because it was troublesome, I wrote a simple one myself, using timer 1 for output. As a result, there was no response at the be
[Microcontroller]
STM32 study notes: standby wake-up
Open the Chinese reference manual of STM32, which contains detailed annotations on the low power mode of STM32.        1. Sleep mode (Cortex™-M3 core stops, all peripherals including the peripherals of the Cortex-M3 core, such as NVIC, system clock (SysTick), etc. are still running)        2. Stop mode (all clocks are
[Microcontroller]
STM32 study notes: standby wake-up
【STM32】The basic principles and registers of ADC
STM32F1xx official information: "STM32 Chinese Reference Manual V10" - Chapter 11 Analog/Digital Conversion (ADC) Basic Introduction to ADC Basic Definition of ADC The abbreviation of Analog-to-Digital Converter. It refers to an analog/digital converter or an analog/digital converter. It refers to a device that co
[Microcontroller]
【STM32】The basic principles and registers of ADC
STM32 interrupt nesting controller
Priority concept in STM32 (Cortex-M3) There are two priority concepts in STM32 (Cortex-M3): preemptive priority and response priority. The response priority is also called "sub-priority" or "sub-priority". Each interrupt source needs to be assigned these two priorities. 1. What is pre-emption priority? Interrupt
[Microcontroller]
STM32 boot code selection and number of bytes per block
● Small capacity products are STM32F101xx, STM32F102xx and STM32F103xx microcontrollers with flash memory capacities between 16K and 32K bytes . Corresponding suffix ld ● Medium capacity products are STM32F101xx, STM32F102xx and STM32F103xx microcontrollers with flash memory capacities between 64K and 128K bytes . Cor
[Microcontroller]
Can STM32 run Linux?
There are two types of operating systems: those with MMU and those without MMU The ones that use MMU are Windows, MacOS, Linux, Android, and the ones that don't use MMU are FreeRTOS, VxWorks, and ucOS... There are two types of CPUs, with and without MMU. The ones with MMU are Cortex-A series, ARM9, and ARM11 se
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号