Difficulty Level = 3 [What’s this?]
The MQ-3 is an alcohol gas sensor that is available for about $5 from Sparkfun, Seeed Studio, and others. It’s easy to use and has sparked the imagination of anyone who has dreamed of building their own breathalyzer device for measuring the amount of alcohol in the human body. I got an MQ-3 sensor a couple of months ago and have spent a lot of time trying to figure out how to do this. After lots of “data gathering”, I found that this task is not as easy as it sounds.
The Circuit
The MQ-3 has a 6 contacts which is confusing, but not as confusing as the MQ-3 datasheet. I also got the Sparkfun breakout PCB for the MQ-3 so it makes the pinout easier to understand. Basically, there is a heater which you power by connecting to VCC and GND. The heater draws about 150mA of current, so I would not power the heater directly from an Arduino board (and certainly not from an output pin). The Arduino voltage regulator can handle 800mA, but you need to consider the power dissipation capability of that voltage regulator, too. I think it’s best to power the heater from an external source, like a regulated 5V power supply or a 7805 voltage regulator.
The other part of the circuit is essentially a variable resistor inside the sensor. The resistance across an A pin and a B pin varies depending on how much alcohol is in the air in the sensor. The more alcohol, the lower the resistance. We measure alcohol in the breath by measuring this resistance. Instead of measuring the resistance directly, we measure the voltage level at the point between the sensor and a load resistor. The sensor and load resistor form a voltage divider, and the lower the sensor resistance, the higher the voltage reading will be. An Arduino analog input pin is a good way to measure the voltage and gives us a reading between 0 and 1023. Higher values mean more alcohol.
One more caveat that every MQ-3 owner needs to know: the sensor has a 24-48 hour “break in” period. That is, the sensor needs to be turned on for 24-48 hours before the readings become stable.
Here’s a circuit that shows how I connected the MQ-3. I used a 10K ohm load resistor in series with the sensor resistor. The MQ-3 datasheet says to use a 200K ohm resistor, but anyone who’s used this sensor knows that this constrains the measured voltage to a tight, high range. I recommend a 10K ohm resistor. Make sure you connect all the grounds together.
It’s easy to read the analog value from the analog input pin with a very simple Arduino program. I chose to run the Standard Firmata firmware on the Arduino and run a Processing program on my computer to display the values. More on that later.And Now, Some Math
The good news is that if you know how much alcohol is in your breath, there is a straightforward formula used to calculate your blood alcohol content (BAC). Alcohol content in a volume of breath or blood is expressed as mg/L (milligrams per liter). A 1% blood alcohol content is 10g/L or 10,000mg/L. Since this level would almost certainly be fatal, let’s scale this down from “dead” to “drunk”. A 0.1% BAC is 1000mg/L.
How does this relate to the breath? It turns out that there is a standard conversion from breath alcohol content to BAC that is employed by commercial breathalyzers. Breath and blood alcohol content differ by a factor of 2100; that is, for every mg of alcohol in the breath, there are 2100mg of alcohol in the blood. So, a person with BAC of 0.1% has 1000mg/L of alcohol in their blood and 1000/2100 = 0.4762mg alcohol in their breath. So, our final formula for calculating BAC from the alcohol measured in the breath is:
% BAC = breath mg/L * 0.21
Sensor Calibration Challenges
So, I simply need to use the sensor to determine how many mg/L of alcohol there is in my breath, right? The bad news is that it is very difficult to know how much alcohol is in your breath in terms of mg/L! The poorly written MQ-3 datasheet says to calibrate the sensor by exposing it to a known alcohol gas of 0.4mg/L. From there, you can determine gas alcohol content in terms of mg/L.
But how do I create an air environment with 0.4mg/L alcohol? I could evaporate 0.4mg of ethanol (that’s the type of alcohol we’re talking about here) in a liter of air, but how do I measure out exactly 0.4mg of pure ethanol? I don’t have a source of pure ethanol. I could buy 151 proof Everclear grain alcohol but then would need to account for the different density when measuring this tiny quantity. And there’s the additional complexity in that evaporating aqueous ethanol will alter the humidity, and the sensor readings are sensitive to humidity! This is getting complicated. If were really motivated, I would drive to Wisconsin where I could buy 190 proof (95%) Everclear. Last time I drove to Wisconsin was to buy illegal fireworks, and it seems that my only reason for visiting Wisconsin is to purchase contraband and smuggle it back into Minnesota. But I digress…the bottom line is that calibration according to the MQ-3 datasheet is hard.
Another calibration approach would be to use my breath as a “known” concentration of ethanol after drinking a known quantity of alcoholic beverages. I could drink the right amount of alcohol to give a 0.4mg/L concentraion in my breath and measure the resistance to get my calibration baseline. But this presents problems, too! The sensor calibration depends on 0.4mg/L concentration in “clean air”. What is “clean air”? I think it means air that is devoid of other contaminating gases that affect the sensor, and assumes 21% oxygen concentration and 65% humidity at room temperature. Those conditions are not going to be true in my breath!
My head is spinning, and I haven’t even started drinking yet. In short, I don’t know how to create the right conditions for accurate calibration without a laboratory. Any ideas welcome.
Forget Calibration — Use Correlation
Ultimately, I decided to simply correlate sensor readings with “computed” BAC based on body weight, amount of alcohol consumed, and elapsed time. There are plenty of online charts and calculators that tell you your approximate BAC based on these inputs. Unfortunately, they don’t give the same values for the same input! I used the first link below from Viginia Tech because it was the source of the values cited in the Wikipedia BAC page and everything in Wikipedia is correct, right?
http://www.alcohol.vt.edu/Students/alcoholEffects/estimatingBAC/index.htm
http://www.bloodalcoholcalculator.org/
http://www.healthstatus.com/cgi-bin/calc/calculator.cgi
http://www.intox.com/wheel/drinkwheel.asp
http://www.1800duilaws.com/dui-resources/BAC-calculator.asp
http://health.discovery.com/tools/calculators/alcohol/alcohol.html
My experimental approach is simply to drink alcohol, compute my BAC according to a chart, and correlate that value to the voltage reading from the Arduino analong input pin. If the sensor is accurate, and if I gather enough data points, I should be able to correlate measured voltage to BAC. This will involve a lot of drinking, night after night. I’m doing this for science. Science!
Sensor Hardware
In order to ensure that I exposed the sensor to a uniform breath sample, I decided to enclose the sensor in a glass chamber. I used a simple glass jar with a plastic lid (it used to hold spices).
I drilled some holes in the lid and used some vinyl tubing as a tube to blow into. One small hole is for the sensor wires, and the other small hole is for breath to escape as I blow more breath into the jar.In the blow tube, I added a tee joint so that condensation from my breath could drain out. I know that’s gross, but the condensation builds up. I plugged the tee joint drain when I was blowing a breath sample.
Data Collection (Drinking)
One thing I have learned is that I can’t drink nearly as much as I could in college (20 years ago). Your BAC drops 0.01% for every 40 minutes of drinking, so I had to drink faster than I wanted to in order to get my BAC up. I also learned that after about 4 drinks, I kept forgetting to write down the sensor readings.
Here’s a screenshot of the Processing program reading the value from the Arduino over USB. Download the source code here. The Arduino feeds the data over serial using this simple Arduino sketch. As you can see, the baseline analog reading is about 260 on a scale of 0-1023. When I blow into the sensor chamber, the resistance of the sensor drops dramatically, causing output voltage of the voltage divider to be higher.
Here’s a scatterplot of the sensor readings (x axis) plotted against the “computed” BAC values (y axis): This doesn’t exactly form a nice straight line, does it? If I look at the data points for a particular drinking session, sometimes there was a nice straight line of points. But the sensor behaved differently on different nights, and I drank different types of alcohol, too, even though I tried to stick to the standard definitions of “serving of alcohol”. Overall, I don’t think I was very successful finding an accurate correlation between sensor reading and BAC. Rough approximation, but not an accurate reading.Conclusions
It’s really hard to calibrate this sensor for even an approximate BAC reading. It’s even difficult to correlate readings to looked-up BAC values. There are many environmental factors that affect the resistance within the sensor (humidity, temperature, oxygen concentration), and this is only a $5 device anyway. And as evidenced by the lack of consistency between online BAC calculators, there’s not even concensus about how to compute BAC. Law enforcement agencies have much more sophisticated breathalyzers, and often rely on actual blood tests or urinalysis for evidence.
Despite these disappointments, the MQ-3 is still fun to play with, and maybe it’s good enough to just make some LEDs light up when you blow on the sensor. So just enjoy your beverages and have fun. Cheers!
While this sensor doesn’t seem very useful for discovering a fixed BAC because of its calibration issues, couldn’t it still be useful for relative BAC? If two people blow into it one right after the other, environmental factors would seem to then be controlled. So do you think the sensor would be good for relative intoxication between two people? Or even relative intoxication per drink, say every 10 minutes?
Yes, nebulous, you can still get a sense for the relative amount of alcohol in your breath. The sensor is well-behaved in that regard. One problem, though, is that once you blow on the sensor and get a reading, it takes several minutes for the resistance of the sensor to rise again (causing the measured voltage to drop back down). This takes about 5 minutes. So, you always have to wait a while between readings.
Congratulation to your work!
Relating Breath-Alcohol content to Blood-Alcohol depends on a lot of factors: Age, drinking speed, time lapse after drinking (if you measure to early, you will get values in your breath, which are to high: so you should wait for 1-2 hours, before you begin your “calibrations”. But then your blood alcohol has already dropped by 0.03 !
25 years ago I published some experiments on the correlation between drinking and blood alcohol and drinking-blood alcohol- breathalyzer measurements. (see literature referneces below)
I also did some (unpublished) experiments with gas sensors of the type you used, which I hooked up to a Commodore 64 (a “cheap” arduino precursor which cost almost $1000 at that time. Programming was done in BASIC resp.Simons BASIC. I hooked up the parallel port to a National Semiconductor MM54240 which communicated to other chips over a serial line (some sort of I2C precursor). That way I was able to read the 4-5 digits of the BCD output of the A/D converter hooked up the sensor.
Yngvar
Refs:
# ↑ Ulrich, L., Cramer, Y., Zink, P.: Die Berücksichtigung individueller Parameter bei der Errechnung des Blutalkoholgehaltes aus der Trinkmenge. Blutalkohol 24, 192–198 (1987)
Krämer, M./Haffner, H.-T./Cramer, Y./Linus, U.: Untersuchungen zur Funktion der Restalkoholanzeige beim Atemalkoholtestgerät “Alcomat”, Blutalkohol 24 (1987), S. 49-57
i live near chicago we can get 96.5% alcohol. it’s this stuff from poland. I forget the name but we translated it and google gave us back “rectified spirits” going from polish to english. comes in 3 artificial flavours that you wont mind at the time, but will seem 100% times stronger when you wake up hung over and you cant get them out of your mouth. it’s also like 2 bucks cheaper than everclear.
Let me know if you need “the hookup”
also i have one of these sensors and I never got around to calibrating them from bac, i just had several LEDs green,yellow, red, and calibrated them to go into the red when i was super super drunk. and i made it so that all the lights would come on if i held a mouth full of red wine and blew into it. then i calibrated the first green light to come on after about 1-2 drinks. makes for a useful scale at parties
I see quite a course sensitivity here – moving from 750-950 moves the BAC from 0.2 to (a median of) 0.5 a 25% increase in reading vs 150% increase.
Shouldn’t you be trying a circuit that by taking readings at zero intake and trying to get a low output from the sensor, ie. something closer to 0? That would give you a wider and more stable range of readings (I think).
Sorry, I’m also wondering if rather than using your breath you could calibrate the circuit by using various partial pressures from an enclosed sample of alcohol at different concentrations (and maybe temperatures if you were really keen), and then blown through the tube with a standard rubber bellows. Partial pressures are easy to calculate.
The reason why I say this, is that in a breathalyzer you have actually no idea what the actual blood concentration is, and the standard formula you mention is just what the commercial manufacturers and lawmakers agree is a reasonable conversion. They generally use actual blood concentration in prosecutions and the roadside test is just for screening.
When looked at this way, your calibration problem is reduced from “calibrate against my supposed blood alcohol level” to “calibrate against the standard”
That would also give you more stability in your results because you’re removing the personal factor and a lot of variables.
@JM
The first half of my article is about the difficulties of measuring a known quantity of alcohol. Read it again and you’ll see that measuring against a known quantity is obviously what I wanted to do, but then settled for correlating with a “supposed” quantity. If you have good ideas for how to calibrate this cheap sensor taking into account all the variables, I’d love to hear about it — it seemed really difficult to me (especially since I don’t have a chemistry lab).
I’m am currently trying to a single point calibrate one of these sensors by exposing the sensor to a known concentration of EtOH (0.4 mg/L, using a quantitative pipetter and a 1 L flask) along with the power function of the data (Rs/Ro VS ppm) described in the data sheet. So far I have set the base reading at “100” (on a 0-1023 scale) and measured the readout 3 times from the headspace of the 1L flask containing 0.4 mg (~500 uL of EtOH per L air) at “450” (three reading from 3 flasks were 436, 447, 466)- it gives very consistent readings for 3 separate trials. Have programmed the code needed to convert from reading to resistance and, using the power function interpolated from the data sheet graph (ppm = 0.356(Rs/Ro)^-1.47), ppm in air, which, given a k (partition coefficient) of 2100 for EtOH in blood:air, can be converted to %BAC. Will test with other concentrations above and below to see how well the power function holds up under my conditions (load resistor, temp, humidity, etc). I am hoping this is enough to get a qualitative range for “below DUI” “DUI” and “Dead drunk”. Will keep posted on progress…
@defwheezer, great work, keep us posted!
Thanks for all the good info. Not worrying at all about calibration, I built this fun breathalyzer for my holiday party — the high score was more important than actual usable data:
http://vimeo.com/17752413
@geoff: exactly: worrying about calibration will only lead to tears. The MQ-3 should be used for fun. Great video!
Here’s an idea of how to calibrate an alcohol gas sensor.
Take a reading of alcohol-free air and call that 0%.
Take a sealed jar of strong liquor and bubble air through it,
then through another hose into a jar containing the sensor.
Heat up, by immersion in warm water, the alcohol jar
to increase alcohol evaporation.
Take some readings, and call those 100%, or get ambitious and
compute what it ought to be at given temperature and flow rate,
and call it 95% or whatever.
Then you have a two point calibration.
Ethanol boils at around 78 C, and water at 100 C, so it should be
possible to get near to 100% alcohol in the air (compensating for
the air itself by measuring flow rate).
A makeshift flowrate meter can be constructed with a vertical piece
of glass or plastic pipe, and a pellet that fits loosely inside it.
Force an airflow through it, mark the pellet position, and capture
the air in a balloon immersed in water so you can measure the air volume,
and take volume readings at fixed time interval.
Repeat the airflow procedure with a few different flow rates,
and then you can actually grade you flow meter with a neat scale.
For a makeshift compressed air source, use the spare tire from your car ;)
And what about this sensor :http://www.futurlec.com/Alcohol_Sensor2.shtml
It give you the ppm vs the Vout. I did a testing circuit and it works. The problem is that the characteristic ppm vs Vout is not liear,so i did a polynomial approximation with Excel. But I can not say if the measure is accurate. I know someone, who can lend me a breathanalyser, and i could make sure that my breathanalyser is correct. Moreover, I will make a calibration with the MQ-3.
P.S: Sorry for my bad english, i am french.
@Domi,
Thanks for the link to that sensor. I have never seen it before, and it clearly has addittional circuitry in it to provide the PPM output. This sensor must be much easier to calibrate than the MQ-3.
@domi how did you go with hooking that mr513 sensor up to the arduino? this is a hotwire sensor and is used with majority of breathalyzers. there is no 48hr burn in period aswell which makes this sensor ideal. If you could please post your results + testing that would be very appreciated.
Very interesting posts. You integrated such valuable information into the article, as well as scripted it in an entertaining manner. I look ahead to forthcoming articles and urge you to renew frequently. You will have a huge follow.
put the basic pin details with diagram for the MQ6 gas sensor in the gas leakage alarm circuit.I want brief expalaination
What keind of calibration you did or what kind of corelation ? How many Volts was 0,4mg/L ?
Hey, Great article… I was just thinking, I bet you could find a cop eating or something, or even something like the campus police here at my college, explain to them what you were doing, and ask if he could breathalyze a couple of your friends in order to get calibration data. Just blow into his and blow into yours right after. I’d be willing to bet after a few nos, you’d get a yes.
Hi Michael,
I have a question about value readet from analog pin. What kind of value are you reading, the resistor value, curent value, voltage value ? The heating resistence change’s his resistens when the target alcohol exist? In presence of alcohol the Rh it’s rising or incrising? What do you think about map() function for Arduino? Can I got good result with?
Your answer will help
The Arduino measures the voltage. As the alcohol concentration rises, the sensor resistance goes down, causing the voltage to go up.
My friend is a cop and he said that you have to wait 20 minutes AFTER having your last sip of alcohol before testing. If you do it any sooner, you’ll get mouth alcohol which will give you higher than expected readings. Figured this might help keep your data less scattered like in your graph.
Hi Michael,
the 24-48 hours pre-heating time have to be applicated before every single use or or just for the first time?
It’s just a one-time process to break-in the device. Just the first time.
Please tell me more about this: “I chose to run the Standard Firmata firmware on the Arduino”.
What exactly do I want to upload to my arduino uno board?
Upload this sketch to your board:
File -> Examples -> Firmata -> Standard Firmata
Ok so I’ll use the sketch for Standard Firmata as it is. I’m not getting a sensor reading in processing yet. Can the 2 GND’s after the voltage regulator be connected to GND on Ardunio board? Or do I connect these 2 GRD’s to the GRD pin of voltage regulator? Thanks.
Correct, you need to connect all the grounds, including the Arduino ground. Even when different components have different power supplies, the grounds all need to be connected together.
Hello,
I am trying to use CO detector using MQ 7. I have used simple sketch that reads analog reading and shows on serial monitor. While typing this, I am getting an analog reading of 28-30, which was around 50-60 last night. I am using this sensor first time, so it is still under pre-heating.
Now, I have query that if there is no CO gas around then analog valur suppose to be 0..?? or close to 0..??
ADC gives range of 0 to 1023, so without any gas, it should give 0.. right..??
2. When I blow air in front of sensor, reading increases..!! I don’t know why…?? I exhale CO2 in breath out, then why does this analog value increase..?
3. How would I convert this analog values to PPM..?? If i want to trigger an alarm at certain value then, What suppose to be threshold value fot the alarm..?? I will use it at home, so what would be the safest PPM count for CO at home and howmany PPM count would be dangerous..?? So that i can set my alarm at that value..!!
Plus, I am running the sensor at straight 5 V from Arduino 5V output. Is it okay..? or do i need to feed it 1.4V and 5V alternatively..???
I’m not familiar with the CO sensor, so you’ll need to consult the datasheet. If it’s like the alcohol sensor, then these very inexpensive sensors are not very accurate. I would not power a sensor from the Arduino power supply, as these sensors often require much more current than you should be drawing from the Arduino voltage regulator.
Thank you Michael…!!
Yes, it is same as alcohol sensor, that’s why i thought i would ask for your advise.
Here’s the link for the datasheet. http://www.sparkfun.com/datasheets/Sensors/Biometric/MQ-7.pdf
I will power it up separately. But, the only problem is PPM setting for alert.
Anyways,Thank you once again..!!
Hi there..i am currently working on a similar project and i have used your schematic diagram as a reference..I am still new to all these electronic stuff and i would like to ask a basic question..I have connected everything exactly as your schematic and an additional LCD to display the output..I would like to know whether the output i obtained is it in Volts?or what value does it represent?
It’s a 10 bit value 0-1023 proportional to the voltage range 0-5V.
Thanks Michael…one more question..how do we convert the digital data we obtain into BAC value?
Newbie, read the article!
Hi Michael
I read your work and in your concluciones say that the sensor is of poor quality, know no other alcohol sensor best quality, I’ve read about the MR513 but not their behavior as thanks for your help
Michael..i am having a problem..i have already heated up the sensor for 24 hours..however when i exposed the sensor to alcohol the reading didnt even increase or decrease..it remains constant at 0..why is this so??
Its alright..i have figured out the solution..=)
Hi Michael,the software you used to draw the schematic is called Eagle right? but i cant seem to find the Arduino microcontroller component in the Eagle library..why is that so?
Newbie, please use Google to find things you need.
hi, I have one question if it is ok; what is the output of this breathalyzer? i need to connect the output to a car simulation but i couldn’t find it and besides i am having short circuit for no reason.
Thx
Lucinda, did you read the article at all? What LEDs? There are no LEDs in this project.
also can you please show me the connections from the arduino to the LEDs, for some reaon it is not working, the LEDs don’t lighten up.
Thx
Which program do you use to draw your schematics?
@Anders,
I use Cadsoft EAGLE. It’s a standard for PCB design.
We’re also working on small sensors and for that purpose have developed and published a free software SNTerminal to display data on PC and Android phones, on which USB host feature can be used to power the board, and the sensor itself creates the content to be displayed – making a whole thing portable.
We do not have yet written an Arduino lib, but it is a very simple protocol that must be sent out thru the serial interface, and content description offers rich math with precision/accuracy specs.
i wanted to ask what happens when i use without burning in ..
i just got my sensor … plugged it in and the analog value is showing around 1024 but is constantly decreasing .. is that normal …. i am using a 330k resitor …
will the value settle after the burn in period ??
You need to run the sensor for at least 24 hours in order for it to function properly.
Hi there, I am working on a project with a MQ-3 breath analyzer. when I power up the sensor, it gets really warm after a few minutes. Is this normal behavior for the MQ-3 sensor? Or should I worry that I might have broken the senor by heating it to long while soldering wires to it?
I am not using a voltage regulator. I provide the sensor with a cellphone adapter witch gives me 5.07V DC (measured).
The sensor has a heater, so yes it should get warm. Make sure your power supply can supply 150mA of current.
you didn’t put condensers on the 7805 to stabilize it. How do you know it was outputing the current voltage? Then you aren’t sure if your reads from the sensor are correct.
Hi Michael – I have everything set up and ran the code but the yellow stroke remains at 0 as time goes on. My Arduino is properly computing data from Arduino code but can’t seem to get processing to read the gas measurements. Any thoughts?
-Ken
Ken, that sounds like a communication problem between the Arduino and the Processing program. Check the serial baud rate to make sure they match. You can also try some simpler Arduino program that just writes data to the serial port and see if it is read by the Processing program.
Hello, I am looking at the power consumption of this sensor. The heater will draw about 150mA max. My Arduino has a UA78M05 regulator, which can supply 500mA max. Therefore, if I don’t interface with too many other things, I should be able to power this from my Arduino, right?
Tristan,
Yeah, sounds like it. That’s a very beefy voltage regulator. Not a standard Arduino, then, right?
hello, I can not successfully run the code in processing, this error message appears: “could not find arduino port”
and this line of code shown: throw new RuntimeException (“could not find Arduino port”); ”
I hope you can help me, thanks!
I have yet to try out the Arduino but came on this article while doing some research on the resistors. Have you tried implementing a temperature fan, or possibly heater to keep it at a regulated temperature?
The MQ3 database provides you the resistance vs alcohol content relationship, well the slope too.
With that data You can calibrate the sensor.
I’d be really interested to build a wearable breathalyser using this device with a lilypad. A badge on your punk jacket, or watch etc. However seems we’re getting a bum steer from the technology vendors. Despite sparkfuns claim for the product here: https://www.sparkfun.com/products/8880 the associated mq3 datasheet linked on the page quotes a detection range of 25ppm – 500ppm. 25 ppm = 25000 ug/L. over 10x the upper limit of the expected range for a breath sample. There’s no way this device could be used to reliably detect alcohol on human breath. It was designed for detecting dangerous levels in ambient air – maybe for people working in factories or liquor production.
Hi, can you send me your mesure points in Excel please ? I try to do a breathalyser but I can’t drink alcohol to create a mesure graph =)
Thank in advance.
Best regards
Hi,
Thanks for sharing. You have done a personal funny project in a very professional manner. So impressive.
I’m studying to develop the breathalyzer. Do you know which alcohol sensor is used by the common commercial products (for products about 200$ or 300$, probably)?
Regards,
Thanks for your kind comment. I’m afraid I do not know what type of alcohol sensor is used in professional devices. Clearly it is more sophisticated than the MQ-3, though.
can this sensor be used for measuring the breath acetone content?
in case if the experiment is conducted on a non alcoholic oerson?
Sorry mates, but u forget that real alcohol sensor do not detect ethanol in the air but acetaldehyde! The air content very very low level of ethanol and a lot of acetaldehyde. So, I’m not sure that your measurements of ethanol are right…