Make an alcohol tester based on 8051 microcontroller

Publisher:东土大唐88Latest update time:2024-01-03 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

We often see traffic police using breathalyzers to check whether drivers are under the influence of alcohol when checking for drunk driving. In fact, the alcohol tester is actually very easy to make. Here is how to make a homemade alcohol tester with a 3-digit display output. Of course, after all, it is used as a simple case, so the accuracy is slightly worse.


In this article, a breath analyzer circuit using 8051 microcontroller is used which outputs the blood alcohol content (BAC) from the breath. The "percentage of alcohol content" is displayed as a percentage on the 3-digit seven-segment display. The microcontroller used is AT89S51 of 8051 series and alcohol sensor MQ135 gas sensor.


1. MQ135 gas sensor circuit

MQ135 is a stable and sensitive gas sensor that can detect ammonia, carbon dioxide, alcohol, smoke, nitrogen dioxide, etc. The sensor consists of a tin dioxide sensitive layer inside an aluminum oxide microtube, a measuring electrode and a heating element inside a tubular aluminum shell. The front end of the sensor is covered with a stainless steel mesh, and the connection terminals are fixed on the back.


The ethanol present in the breath is oxidized to acetic acid as it passes through the heating element. This ethanol lands on the tin dioxide sensing layer, so its resistance decreases. Use an external load resistor to convert this resistance change into a suitable voltage change. MQ135

A typical connection arrangement for an alcohol sensor is as follows:

mq135-connection-diagram.png

MQ135 has different resistance values ​​at different temperatures and different gas concentrations. The manufacturer recommends 100 ppm ammonia or 50

Calibrate the sensor in ppm alcohol. The recommended value of the load resistor is between 10K and 47K.

2. Schematic diagram of alcohol tester

alcohol-breathalyzer-using-80511.jpg

List of required components:

Alcohol sensor (MQ135) – 1 pc.

IC (ADC 0804) – 1 pc.

Microcontroller (AT89S51) – 1 pc.

7-segment display – 3 pcs.

Transistor (2N2222) – 3 pcs.

Switch – 1 pc.

Capacitor (150pF) – 1 pc.

Capacitor (22uF/10V) – 1 pc.

Capacitors (10uF/10V) – 3 pcs.

Resistors: 100 – 11 nos, 10k – 3nos, 22k – 1 nos, 8.2k – 1 nos, 330 ohm – 1

nos.

3. Working principle of alcohol detector circuit

The voltage output of the alcohol detector unit is converted to digital format using ADC0804 (IC1). The V ref/2 pin of the ADC is used by R14 and R15

The resulting voltage divider network remains at 1.28V. V ref/2 =1.28V means that the step size of the ADC is 10mV. Every time the analog input increases by 10mV, the output of the ADC will increase by one bit. See

Datasheet for the ADC0804 to get a better grasp. The digital outputs of the ADC (D0 to D7) are connected to port 1 of the microcontroller. The control signals CS, RD, WR, and INTR are respectively sent from the microcontroller

P3.7, P3.6, P3.5, P3.4 pins are obtained. R9 and C1 are related to the clock circuit of ADC0804.

Capacitor C3 is connected between V in+ and V in- of the noise filter (if present) in the ADC0804 sensor output. If C3 is not used, the ADC

The digital output will be unstable. The filter capacitor certainly causes some hysteresis in the ADC response, but it is not very important in this entry-level application. Microcontroller to ADC

The digital output performs the required operations in order to convert it to "percent alcohol content" and display it on a three-digit, seven-segment display. Port 0 of the microcontroller

Connected to multiplexed three-digit seven-segment display. The three-digit driving signals are obtained from the P3.0, P3.1, and P3.2 pins of the microcontroller.

4. 8051 microcontroller alcohol tester program


ORG 00H

MOV P1,#11111111B

MOV P0,#00000000B

MOV P3,#00000000B

MOV DPTR,#LUT

MAIN: MOV R4,#250D

      CLR P3.7

      SETB P3.6

      CLR P3.5

      SETB P3.5

WAIT: JB P3.4,WAIT

      CLR P3.7

      CLR P3.6

      MOV A,P1

      MOV R5,A

      SUBB A,#86

      JC NEXT

      SETB P3.3

      CLR PSW.7

NEXT: MOV A,R5

      SUBB A,#115D

      JNC LABEL

      MOV A,#00000000B

      CLR PSW.7

LABEL: MOV B,#5D

       MUL AB

       MOV B,#8D

       DIV AB

       MOV B,#10D

       DIV AB

       MOV R6,A

       MOV R7,B

DLOOP:SETB P3.0

      MOV P0,#01000000B

      ACALL DELAY

      CLR P3.0

      SETB P3.1

      MOV A,R6

      ACALL DISPLAY

      MOV P0,A

      ACALL DELAY

      CLR P3.1

      SETB P3.2

      MOV A,R7

      ACALL DISPLAY

      MOV P0,A

      ACALL DELAY

      CLR P3.2

      DJNZ R4,DLOOP

      SJMP MAIN

DELAY: MOV R3,#255D

LABEL1: DJNZ R3,LABEL1

        RET

DISPLAY: MOVC A,@A+DPTR

         CPL A

         RET

LUT: DB 3FH

     DB 06H

     DB 5BH

     DB4FH

     DB66H

     DB 6DH

     DB 7DH

     DB07H

     DB7FH

     DB 6FH


Reference address:Make an alcohol tester based on 8051 microcontroller

Previous article:Design of data acquisition system with C8051F340 microcontroller as the core
Next article:How to build an Android phone controlled robot using 8051 microcontroller and Bluetooth module

Recommended ReadingLatest update time:2024-11-15 07:52

8051 MCU Data Description
One of the keys to learning C51 is to deeply understand and apply the extensions of C51 to standard ANSI C, because most of the extensions are directly targeted at the 8051 series CPU hardware. The specific instructions are as follows (8031 is the default CPU). 1. Keil C51 extended keywords C51 V4.0 version has
[Microcontroller]
How to access bytes in int in 8051 microcontroller
In the use of single-chip microcomputer, unsigned int occupies 2 bytes, unsigned char occupies 1 byte. Single-chip microcomputer implements byte addressing. 16-byte bit addressing is really not easy to use. It is not useful because it cannot create arrays. In the actual development process, DPTR, as well a
[Microcontroller]
How to access bytes in int in 8051 microcontroller
High-speed interface between C8051 and SRAM
The C8051 series microcontrollers do not have data buses (RD, WR, ALE) like the standard 51 microcontrollers, and can only use the general I/O port analog bus method to access external memory. Therefore, C8051 requires dozens of instructions to access external memory once. Even so, since most of the instructions of C80
[Microcontroller]
High-speed interface between C8051 and SRAM
How to achieve precise delay of C8051 microcontroller
Code written in C: delay=0x64; while(--delay); The compiled assembly source code is as follows: ;SOURCELINE#62 00107F64MOVR7,#064H;2B,2CLK 0012? C0006: ;SOURCELINE#63 0012DFFEDJNZR7,? C0006;2B,2/3CLK If we use a 24MHZ crystal oscillator and each clock cycle is 41.6ns, then the delay accuracy of the above delay sta
[Microcontroller]
Design and implementation of a multifunctional frequency meter based on FPGA and 8051 single-chip microcomputer IP core
  Frequency is an important physical quantity in electrical signals. In electronic and communication systems, the frequency stability of the signal determines the performance of the entire system. Accurately measuring the frequency of the signal is an important part of system design.   Single-chip microcomputers are
[Microcontroller]
Design and implementation of a multifunctional frequency meter based on FPGA and 8051 single-chip microcomputer IP core
IO configuration method and principle of c8051f
C8051F---I/0 port Q: What is the difference between the P4-P7 port and the P0-P3 port of the C8051F020/022? A: The P0-P3 port is a general-purpose port when reset, and can be set to the second function according to the priority through the Crossbar (data crossbar) register. The P4-P7 port is a general-purpose port, an
[Microcontroller]
Usage of R8051XC2 Timer 2
T2CON----Timer 2 Control Register t2con.7---t2ps: clock selection                      0: Timer 2 is clocked at 1/12 of the oscillator frequency                      1: Timer 2 is clocked at 1/24 of the oscillator frequency t2con.6---3fr: Active selection of external interrupt int3 (also used to compare and ob
[Microcontroller]
8051 MCU (STC89C52) timer achieves 10ms accurate timing
8051 has two 16-bit counters integrated inside, which can be used as timers as needed. At this time, the counting frequency of the timer is system CLK/12. If the crystal frequency of the CPU is 12MHz, then the frequency of the timer signal source is fixed to 12MHz/12 = 1MHz. If the timing period of the timer is set to
[Microcontroller]
8051 MCU (STC89C52) timer achieves 10ms accurate timing
Latest Microcontroller Articles
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号