DESIGN AND IMPLEMENTATION OF ALCOHOL DETECTOR USING 8051 MICROCONTROLLER V Ganesh(13L217) M Gokularam(13L218) P.S.Guru Balajee(13L219) Dissertation submitted in partial fulfilment of the requirements for the degree of
BACHELOR OF ENGINEERING ELECTRONICS AND COMMUNICATION ENGINEERING Of Anna University
September 2015
12L511 - Microprocessor and Microcontroller Laboratory DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING
PSG COLLEGE OF TECHNOLOGY (Autonomous Institution) COIMBATORE – 641 004
1
PSG COLLEGE OF TECHNOLOGY (Autonomous Institution)
COIMBATORE – 641 004
DESIGN AND IMPLEMENTATION OF ALCOHOL DETECTOR USING 8051 MICROCONTROLLER Bona fide record of work done by
V Ganesh (13L217) M Gokularam(13L218) P.S.Guru Balajee(13L219) Dissertation submitted in partial fulfilment of the requirements for the degree of
BACHELOR OF ENGINEERING ELECTRONIC AND COMMUNICATION ENGINEERING Of Anna University
September 2015
……………………………….. Faculty guide
……………………………… Dr. S. Subha Rani Head of the Department 2
ACKNOWLEDGEMENT
I would like to extend my sincere thanks to Dr. R. RUDHRAMOORTHY, Principal, PSG College of Technology, for his kind patronage.
I am indebted to Dr. S. SUBHA RANI, Professor and Head of the Department of Electronics and Communication Engineering, for her continued support and motivation.
I would like to express my gratitude to my technical report guide Dr.D. Sivaraj and Mr.K.Rajasekar, Department of Electronics and Communication Engineering, for their constant motivation, direction and guidance throughout the entire course of our technical report.
I am grateful to the support by my class advisor Mrs. P. Prabavathi, Professor, Department of Electronics and Communication Engineering.
I thank all the staff members of the Department of Electronics and Communication Engineering for their support.
Last but not the least I thank the Almighty and my family members who have been a guiding light in all our endeavours.
3
Table of Contents Objective and need for the Project......................................................................6 Objective of Project...................................................................................... 6 Project overview............................................................................................. 7 Block Diagram............................................................................................. 7 Circuit Schematic and Explanation..................................................................8 Flowchart and C program.................................................................................9 Keil Program[C code] for alcohol detector......................................................11 Simulation and Hardware implementation.........................................................16 Simulation Results...................................................................................... 16 Hardware Implementation...........................................................................17 Conclusion................................................................................................... 18 Future Scope................................................................................................ 18 Reference..................................................................................................... 18
LIST OF FIGURES
Figure 1.Alcohol Detector Block Diagram.......................................................................7 Figure 2.Schematic of the alcohol detector done in Proteus ISIS simulator............................8 Figure 3.Main function flowchart.................................................................................9 Figure 4. Flowchart for signal conditioning.....................................................................9 Figure 5.Flowchart for LCD...................................................................................... 10 Figure 6. Simulation showing drunk output..................................................................16 Figure 7. Simulation showing Normal Output...............................................................16
4
ABSTRACT This project report deals with the design and testing of alcohol detector with the 8051 series of ATMEL’s microcontrollers. This project uses the 8051 variant AT89S52 (8052). The program for configuring the microcontroller was written in Keil microvision 3 IDE, designed for ATMEL 8051 series microcontrollers.
5
CHAPTER I Objective and need for the Project Many accidents happen in this fast moving day to day world. And one of the main reasons for these accidents are drunken driving. Due to this very reason, even innocent people are affected too. So a constant check is needed in this issue by the government to strictly avoid drinking during driving. And for this we need a device to detect the presence of alcohol in human without and interference of environment. So this calls for a perfect engineered design to maintain accuracy and detection. The only solution to such problem is the usage of an alcohol detector. The alcohol detector is the widely used device in the present day world by the police and the government to inspect a person’s status. Hence alcohol detectors have evolved to a greater extent in this present day world that it has become an integral part of the traffic world. Objective of Project The objective of the project is to design a fool proof alcohol detector to detect the presence of alcohol in human breath. It also needs to provide the numerical value of the alcohol content to know the extent of alcohol consumption. For this digital devices such as microcontrollers are used to achieve high accuracy and speed for instantaneous detection.
CHAPTER II 6
Project overview Block Diagram
Figure 1.Alcohol Detector Block Diagram
The block diagram shown explains the hardware setup of alcohol detector. First to detect the alcohol, alcohol sensor is used. But the issue is the sensor provides analog data which is incompatible to microprocessors. So there comes a need for analog to digital conversion. This job is done by the ADC 0804 present on board in the development kit. Then the converted data are sent to the controller to process and send the threshold and actual value. The result is displayed in LCD display for easy interpretation. Thus this project involves complex interfacing of many devices.
Circuit Schematic and Explanation 7
Figure 2.Schematic of the alcohol detector done in Proteus ISIS simulator
The figure above shows the circuit schematic of the alcohol detector in Proteus Simulation software. Here we can see the regular connections such as the crystal oscillator connected to pin 18, 19. Here as mentioned above, instead of using the sensor, for the purpose of demonstration, we have used a potentiometer. And it is given to a ADC. The ADC is also supplied with the required clock frequency with the RC network. Then the converted data is taken and given to the controller via port 2. Now the processes are done in the microcontroller and the data to be displayed are given to the LCD display via port 1. Then the additional data to be given to the LCD display such as write, enable, etc. are given via some of the pins of port 3.
CHAPTER III
8
Flowchart and C program
Figure 3.Main function flowchart
The above flowchart shows the main procedure to get the final result. That is, we first blow on the sensor, then the amount of alcohol is calculated and the result is given according to the threshold value.
Figure 4. Flowchart for signal conditioning
This flowchart depicted above shows the signal conditioning and display unit in an outline. In signal conditioning, the alcohol vapour concentration is given to the sensor and it produces a resistance change. This resistance change 9
in turn produces a voltage change corresponding to it, since it is a passive sensor. Now the voltage is converted by ADC and given to the microcontroller.
Figure 5.Flowchart for LCD
This flow chart describes the working of the LCD. Here when powered ON, the LCD is initialised. That is the function sets are sent in one by one and each digits are displayed one by one according to the clock cycle. After displaying the digits, it clears the whole display and waits for the next set of data to display. Due to high clock frequency, we observe the digits as stable ones.
Keil Program[C code] for alcohol detector The following program programs the AT89S51 microcontroller to configure it as an alcohol detector. 10
#include unsigned char adc,i; unsigned char drunk[]={0x44,0x52,0x55,0x4e,0x4b,0x20,0x20};//both the arrays store the ascii values unsigned char normal[]={0x4e,0x4f,0x52,0x4d,0x41,0x4c,0x20,0x20};//for the words 'drunk' and 'normal' unsigned char h,t,o; sbit rs=P3^2; sbit rw=P3^3; sbit en=P3^4; sbit rd=P3^7; sbit wr=P3^6; sbit intr=P3^5; void delay(unsigned int x) { while(x--); }
void main() { //Initialise lcd rs=0; rw=0; en=1; delay(1500); //clear display and move to home //------------------------------
P1=0x01; en=0; 11
delay(1500); en=1;
P1=0x03; en=0; delay(1500); en=1; //-------------------------------
//set entry mode //------------------------------P1=0x06; en=0; delay(1500); en=1; //-------------------------------
//set lcd functioning(16*2, uses two lines, 8 bit data mode) //------------------------------P1=0x38; en=0; delay(1500); en=1; //-------------------------------
//turn on and configure display //------------------------------P1=0x0e; en=0; delay(1500); 12
en=1; //------------------------------rs=0; P1=0x80; //set cursor to first line first position en=0; delay(1500); en=1; //------------------------------
//------------------------------
while(1) { rd=1; wr=1; while(intr); wr=0; rd=0; adc=P2;
if(adc<127) { rs=0; P1=0x85;//set cursor to 6th position on first line en=0; delay(1500); en=1; delay(1500); for(i=0;i<7;i++) 13
{ rs=1; P1=normal[i]; en=0; delay(1500); en=1; } }
if(adc>127) { rs=0; P1=0x85; en=0; delay(1500); en=1; delay(1500); for(i=0;i<7;i++) { rs=1; P1=drunk[i]; en=0; delay(1500); en=1; } } h=adc/100; individual
//split the adc decimal value into
t=(adc%100)/10; values)
// digits(hundreds,tens and ones place
o=adc%10;
//(255 -> h=2,t=5,o=5) 14
rs=1;//ascii value of zero is 0x30, add h to 0x30 to get P1=0x30+h;//the corresponding ascii value of h en=0; delay(1500); en=1;
rs=1; P1=0x30+t; en=0; delay(1500); en=1; rs=1; P1=0x30+o; en=0; delay(1500); en=1; } }
CHAPTER IV Simulation and Hardware implementation Simulation Results
15
Figure 6. Simulation showing drunk output
Figure 7. Simulation showing Normal Output
The figures shown above is the simulation of the alcohol detector circuit in Proteus Simulation software. We can clearly observe the working of the device in both the test conditions. The first figure displays the output when the condition is DRUNK and the second image shows the output when the condition is NORMAL. The following content shows the hardware implementation.
16
Hardware Implementation
This picture shows the hardware implementation of the alcohol detector. The 8051 microcontroller is programmed with all interfacing codes. For the sake of demonstration, here instead of alcohol sensor, a potentiometer is used in the place of sensor. The ADC 0804 nearby is used to convert the output of the potentiometer to the corresponding digital output. The converted output is then given as input to P1. The input is taken and checked for the threshold and the final result is obtained. Then the threshold value is converted to the format of LCD display. The converted code is then given as input to the display. Now the potentiometer is turned with a screw driver and the input is varied. Now we can see the change in display value of the LCD and can see the change of result status from ‘DRUNK’ to ‘NORMAL’ and vice versa.
Conclusion From this report it can be seen that implementation and realisation of alcohol detector is a challenging, yet a vital one. It gives us a wide idea about the field of coding in embedded systems. It also helps us to realise the architecture of 8051. On realisation, it justifies that simulation and the working is the same. So the design of alcohol detector at its simplest is conveyed in all possible ways. Similar works can also be done with such technical knowledge.
17
Future Scope Alcohol detector designed in this project is the simplest one compares to the present day equipment. The future scope for this alcohol detector can be extended to various degrees. They are Camera A camera can be interfaced with this device to immediately capture the face of the person who is drunk. It gives us an advantage to get more details about the accust. GPS GPS can be interfaced with this device to trace the exact location of the crime. It gives us more details and also easy for us to track the device if lost or in theft. Printer A thermal printer interfaced with this device can be of immense use to immediately print the fine receipt like bus ticket issuer. Card Swiper An attached card swiper can be used to pay the fine on the spot for time saving. It also gives extra accounting purpose.
Reference 1. The 8051 microcontroller – Architecture, Programming and applications – Kenneth J. Ayala 2. The 8051 microcontroller and embedded systems – Muhammad Ali Mazidi and Janice Gillespie Mazidi 3. Architecture and Programming of 8051 microcontrollers – Mikroelektronika. 4. ATMEL’s AT89S52 hardware description datasheets.
18