Let us introduce the Breath-o-Matic alcohol sensor.
The Breath-o-Matic is an electronic, non-invasive method of measuring a human’s blood alcohol content (BAC). Its elegant, yet discombobulated design embodies a cheerful mix of mechanical and semiconductural components. Simply blowing into the mouthpiece causes the Breath-o-Matic to automatically begin taking a sample of your own foul morning breath. If you’ve partied sufficiently hardy, then you may also have a chance of making the high score list. You’ll then have the pleasure of seeing your name up on the wall of shame, along with up to nine other drunken slobs. Of course, if you don’t make the high score list on your first try, don’t despair! At college, the night is always young!
Please note that the designers and manufacturers of the Breath-o-Matic do not advocate excessive alcohol ingestion, and the Breath-o-Matic should not be viewed as an excuse, nor as a motivation for binge drinking. Additionally, the designers and manufacturers of the Breath-o-Matic make no claims about the Breath-o-Matic’s ability to detect “legal BAC limits” for the purposes of driving, operating heavy machinery, or attempting to engage in stimulating conversation with members of the opposite sex.
High Level Design
(Or: Inspiration besides the obvious)
Our inspiration for this project came from a very simple illustration of how a Breathalyzer works in the book, The Way Things Work, by David Macaulay. We’d also often found ourselves in situations where we would have liked to know our current BAC, but we had no methods of determining it, beyond crude estimation using the “attempt to touch your nose with your finger with your eyes closed while standing on one leg” method, which often resulted in injuries. Thus was born the Breath-o-Matic.
(Or: What to look for when your vision gets blurry and your brain stops functioning, and you’re not entirely sure whether you just blew into the Breath-o-Matic’s mouthpiece or the dog’s nose)
When the Breath-o-Matic is first turned on, the Main Menu appears on the screen with three choices: press the Green Button to access the High Score List, press the Blue Button the force sample acquisition, or start blowin’!
Pressing the Green Button brings the user to the Breath-o-Matic’s high score list, which cycles through all of the current high scores. If there are no high scores yet, a message to that effect is displayed. At this point, the Blue Button will delete high scores, and the Green Button brings the user back to the Main Menu.
If the user elects at the Main Menu to huff and/or puff into the mouthpiece, the pressure sensor will detect a pressure differential and the Breath-o-Matic will begin taking samples. Pressing the Blue Button will accomplish the same thing. Approximately every half-second, a sample is taken, an LED flashes and the speaker beeps. These actions provide the user with breathtaking (har!) visual and audible feedback.
After about five seconds (10 samples), the user stops blowing, and the MCU waits six seconds, or until the sample has stabilized, whichever comes first. If the sample has not stabilized after six seconds, the speaker makes an angry noise, and the user is ejected back to the main menu to try again, or, if they are feeling belligerent, chuck the device across the room. If the sample has stabilized, the speaker plays a happy tune and the user is presented with their reading, which, for good little girls and boys, may well be zero. We use six LEDs to indicate six different levels of intoxication. These levels include “Sober” (BAC<0.04), “Happy” (0.04≤BAC<0.06), “Tipsy” (0.06≤BAC<0.09), “Confused” (0.09≤BAC<0.12) “Incomprehensible” (0.12≤BAC<0.15) and “Boris Yeltsin” (BAC ≥0.15).
If the user has achieved a high score, by either having a higher BAC than any of the ten current high scores, or by there being fewer than ten high scores on record, then they are notified of their disgraceful achievement and prompted to enter their name via a standard computer keyboard (not included). After name entry, the user is shuffled over to the high score list, where they may see how they stand compared to the ten other lowliest degenerates to have used the Breath-o-Matic. High scorers may wish to celebrate their success with a glass of water, a long nap, and a brain shattering hangover (also not included).
The TGS 2620 alcohol sensor functions as a variable resistor, whose resistance has a logarithmic response to ethanol, as shown in the following plot, lifted with no shame from the TGS 2620 datasheet.
Using the Golden Rule of log-log equation determination (i.e., estimating values based on the fact that lines look “pretty close together”), we extracted the following equations for determining the PPM of ethanol in air from the sensor’s resistance:
Region 1 (2 ≤ Rs/R0 < 4): PPM = 244.8(R/Rs)1.304
Region 2 (Rs/R0 < 2): PPM = 248(R/Rs)1.323
R0 is a constant that depends on the individual sensor, and Rs is the sensor’s resistance in ohms. We calculated R0 of our sensor to be 6584 ohms. Values of Rs/R0 above 4 correspond to BACs of less than 0.015, and therefore are reported as a BAC of 0.
Parts per million is defined as grams of solute per grams of solvent. BAC, however, is defined as grams of ethanol per 100mL of blood. Because the intention of our project was to be noninvasive, we ruled out our first design, which would use a mechanized needle to puncture the user’s vein, suck out the user’s blood using a 12V pump, and determine the BAC from the blood sample. Instead, we sample the user’s breath, which is less invasive, but slightly more harmful to bystanders and the environment in a halitosital sense. Alveoli (deep lung) air has one twenty-six hundredth of the ethanol (by mass) that blood does. Thus, we can convert to BAC from the sensor’s output of parts per million as follows:
PPM ETOH = (g ETOH / 106g Blood)
BAC = (1g ETOH / 106g blood)(129g air / 1L air)(210)(10-6) = (g ETOH / 210L air) = (g ETOH / 100mL blood)
(Or: States of Confusion)
The bulk of our software design is centered around several state machines. Chief among these is, appropriately, the Main State Machine. The main state machine decides, using the primitive ones and zeros that pass for its consciousness, what part of the system to run. Choices include the Main Menu, Taking Sample, Entering High Score, and the High Scores List. Except for the main menu, these states each have their own state machines, and they are handled by the Main State Machine in the following goony manner:
// et cetera et cetera …
// … et cetera et cetera
Main State Machine Diagram
If the user starts blowing into the mouthpiece at the Main Menu, then the Taking Sample state machine comes into effect. The Taking Sample state machine does a variety of things, including measuring the alcohol content of the user’s breath at 512 millisecond intervals for 5.1 seconds (at which point the user has probably been out of breath for at least one second), determining the validity of the sample, and playing cheesy tunes and lighting LEDs. Unfortunately, we must require such a lengthy breath sample, because the TGS 2620’s response is very slow. As such it’s occasionally necessary to take more than one sample to get a good reading. By that time though, the ADD-plagued intoxee has probably wandered off to stare at something else, so we figure it’s not too big a deal.
The Taking Sample state machine also determines the stability of the sample. If the sample fails to stabilize after six seconds, it is declared to be bad, and the user’s readings are rejected. Bad readings are possible if the user has a high BAC and the sensor takes too long to reach its maximum value, or if the user does not blow consistently into the mouthpiece (such as if they asphyxiate in the middle of the sample taking process). Note that, even if the user is not intoxicated, the amount of breathing effort required to get a good sample with the Breath-o-Matic can sufficiently deprive the user’s brain of oxygen such that the user feels intoxicated anyway! Party on!
Taking Sample State Machine Diagram
If the user’s average BAC is sufficiently high to make the high score list (or else there are fewer than 10 high scores on record), the processor heaves itself into the Enter High Score state machine. This state machine takes keyboard input with the aid of the Mega32’s USART. We didn’t really feel like doing weird mathematics and register assignments and nonsense like that to synchronize with the keyboard’s internal clock, so we just jammed the keyboard’s clock wire onto the Mega32’s XCK pin. In this way, the USART can synchronize itself with the keyboard clock, and we’re left in blissful ignorance of such trivialities as the clock’s period (which happens to be around 80 microseconds). We did however have to decode the keyboard’s character codes, which, fiendishly, bear no resemblance to ASCII. We did this with the help of Adam Chapweske’s splendertastic web site, “PS/2 Mouse/Keyboard Protocol” (see the appendix for details).
The High Score List state machine isn’t really a state machine, but we call it one for consistency’s sake. It cycles through the current high scores, and its “state” is really just the high score number that it’s currently showing. That is, if high score #6 is currently showing on the LCD, then High Score List’s state number will be 6. If you were hoping for some sort of cryptic elegance, then I am afraid that this state machine will only disappoint.
Enter High Score State Machine Diagram
All of these states blend together in the final produce to form a delicious, frothy, nourishing product, blended with only the finest Columbian coffee beans, spiced to perfection, and topped with a generous helping of whipped cream. $4.78 plus tax. Thank you, and have a nice day.
(Or: What went into the Breath-o-Matic, besides your tuna breath)
The heart of our design is the TGS 2620 Solvent Vapor detector from Figaro Electronics, Inc. The TGS 2620 is capable of detecting ethanol gas, and thus makes an ideal sensor for breath-alcohol detection. The TGS 2620 also responds to several other gases, including methane and carbon monoxide, but we’re banking on the fact that these chemicals are not often found in living humans’ breath. The brain of the Breath-o-Matic is an Atmel Mega32 microprocessor, which has more than enough processing power, and barely enough ports to handle all of the junk that we crammed into the project. Sadly, despite the presence of a heart and brain, our limited budget meant that we were unable to afford a soul. As a result, the Breath-o-Matic is intrinsically evil. Luckily for consumers, it’s also inanimate!
We use a Motorola MPX 2052D differential pressure sensor to detect when the user is breathing into the Breath-o-Matic. This sensor was working very well until it broke (probably due to an overload of saliva), and now it’s fairly unpredictable. It tends to change its output voltage when the pressure across its face changes, but it doesn’t always. It also occasionally changes its voltage for no reason, resulting in samples being taken when nobody is even touching the device. Had we the time and money to replace the pressure sensor before demo time, we would have. In it current state, the sensor usually does what we want it to.
Our pressure sensor’s output is on the order of ones of millivolts, so we needed to amplify its signal. Unfortunately, hoity toity Morotola decided that, since the pressure sensor is differential, users must want two outputs as well, one for each side of the sensor. Of course, we users do not want this configuration. Two outputs that differ by only a couple of millivolts are very difficult to work with for the typical unassuming ECE 476 student. After spending many futile hours trying to get an amplifying voltage subtractor circuit to work, we finally got a super secret INA121 differential amplifier from Professor Land. This amplifier has a differential input and variable gain, and it works beautifully. However, by the time we got it, the pressure sensor didn’t work any more. Oh well!
Both the pressure and alcohol sensors are mounted inside a series of sophisticated pressure chambers (party balloons), with reinforced interconnects (drinking straws), and sealed with advanced sealants (twisty ties). By “mounted,” of course, we mean “dangling inside the balloons with their leads poking out through the rubber.” The pressure sensor has one of its faces (the pressure side) inside the pressure chamber, and one side (the vacuum side) exposed to the air. This design offers a compromise between functionality, and a mechanical setup so simple, even an ECE can understand it. Note that, initially (i.e., for the first four weeks), we didn’t understand it, and as such, spit a lot into both sensors. Eventually, we fixed this problem by using a filter (old gym shirt) when blowing into the Breath-o-Matic.
We also use a standard 104-key PS/2 computer keyboard for high score entry.
|TGS2620||Alcohol Sensor.||2620.pdf||Figaro Sensor||0.00|
|MPX2052||Differential pressure sensor||MPX2052D.pdf||MPJA||4.95|
|6Pin Mini DIN||Keyboard adaptor||Digikey||0.93|
||9V battery connector||Lab||0.00|
For more detail: The Breath-o-Matic