Mar 7, 2010

Building an Breathalyzer with MQ-3 and Arduino

During the First Meeting of Electronic Arts in Florianópolis, we built a Breathalyzer using the Alcohol Gas Sensor MQ-3 and a Arduino Board to use in the last day of the meeting, in which we gave a party. You can see a quick video two posts below. Last days I received many emails asking for the code or how to make one, so I decided to build the sensor again, take pictures/videos and make a tutorial showing how you can make one, so here it is.


Parts Needed:

  • Arduino Board
  • 10x 5mm LEDs (Green, Yellow and Red)
  • 100KΩ Potentiometer (to calibrate the sensor)
  • 10x ≈ 220Ω Resistor (anything between 220Ω and 470Ω is OK)
  • BreadBoard
  • MQ-3 Sensor from Sparkfun

Here are some pictures from the building process:

IMG_3025

IMG_3028

IMG_3029

IMG_3030

IMG_3042

To make the LEDs work, I have connected them in sequence using the Digital Pins 2 till 11 (ten LEDs total). Remember to use a resistor between 220Ω and 470Ω for each LED, like shown on the picture below:

To connect the sensor, you have to connect one of the H pin to +5V Supply (use an external power supply for that, it may be too much current for the arduino) and the other one to Ground.

Pin B (any of them) you connect to Ground. And the A pin (also any of them) you connect to the 100KΩ potentiometer as shown on the picture below. In the same pin where you are connecting the pin A, you need to connect a wire to the Analog/Digital Converter in Arduino, that is where you are going to read the Alcohol information.

This is a quick and easy DIY project, but if you have any problem building it, please feel free to post questions!

You can DOWNLOAD the .PDE file HERE.

/*

@ Code for interfacing Alcohol Gas Sensor MQ-3 with Arduino
@ Code by Daniel Spillere Andrade and Daniel Amato Zabotti
@ [email protected] / [email protected]
@     www.DanielAndrade.net

*/



const int analogPin = 0;    // the pin that the potentiometer is attached to
const int ledCount = 10;    // the number of LEDs in the bar graph

int ledPins[] = {
  10,9,8,7,6,5,4,3,2,1 // Here we have the number of LEDs to use in the BarGraph
  };  


void setup() {

  for (int thisLed = 0; thisLed < ledCount; thisLed++) {
    pinMode(ledPins[thisLed], OUTPUT);
  }}

void loop() {
  //This is the code to light up LED's
  int sensorReading = analogRead(analogPin);

  int ledLevel = map(sensorReading, 500, 1023, 0, ledCount);


  for (int thisLed = 0; thisLed < ledCount; thisLed++) {

    if (thisLed < ledLevel) {
      digitalWrite(ledPins[thisLed], HIGH);
    }

    else {
      digitalWrite(ledPins[thisLed], LOW);
    }  }}

And now, have a great drinking!!!

Remember, if you gonna drive, don’t drink,
but if you do, call me! :P

97 Comments

  • hilarious! joão, how can u be so hilarious!!
    great boys, congrat…
    1. does the beer integrate the part list?
    2. did you use fritzing to draw your schematics?

    kisses

  • @carol

    1. not beer, but Velho Barreiro (stronger 35%, soon I will add video)
    2. I used EagleCad. I tried using Fritzing, but I didn’t liked.
    :)

    • RE Fritzing: I love it. But to grow to love it, I had to get the latest beta version. It is very much improved. The version that is in most Linux repos is old.

      If you’re using the Windows version, well, there’s your first problem.

  • [...] pouvez retrouver l’intégralité du projet sur : danielandrade.net [...]

  • [...] wrote up a quick tutorial on interfacing with the MQ-3, or better known Breathalyzer from SparkFun with Arduino. While we would have used perhaps an [...]

  • Have you done any work on converting the lvls to Alc/Vol
    eg millilitre(alcohol)/Litre(air)

  • Good job on the excellent writeup.

  • Great project! I have no need for one but I could test it for you. :)

  • On the datasheet of MQ3 I’ve read that this sensor need a pre-heat time >24hours. Is really needed to preheat the sensor all this time?

  • @Gianni time > 24h is a lot!
    I’m not sure about that, I didn’t used it to make exact measurements so I can’t tell about it. :)

  • Cool. I love that the Arduino can be used for projects like this.

  • @Daniel: Yes I know >24 is a lot… I suppose that this time period is to obtain most precise measurements

  • [...] un éthylomètre ? plus d’info là http://www.danielandrade.net [...]

  • Did you use a resistor on the sensor?then what is the value of resistor?thnx!

  • @dan I used a 100KΩ Potentiometer to calibrate :)

  • what is the use of pulldown resistor at pin-A of the sensor?should i connect the port A to a resistor?thanx!

  • @dan http://en.wikipedia.org/wiki/Pull-up_resistor
    and yes, you need to connect the resistor :)

  • [...] Creating a Breathalyzer with Arduino [...]

  • good job. you can make the schematic of the entire assembly and post it?

  • can you pls post the schematic and all the connections to the breadboard?thanx in advance..=)

  • can you explain this line of code:

    int ledLevel = map(sensorReading, 500, 1023, 0, ledCount);

    and how can we measure the electrical current from the analog input converting to digital output ???

  • could u post the complete code please? :)
    thanks a lot :)

  • This will NOT work if wired the way you describe. Sensor pin B needs to be connected to VCC, not GND. Current needs to flow between A and B (direction does not matter). If you connect B to GND, and A to GND (through a resistor) no current flows. I have the MQ-3 and use it for similar circuits. Look at the datasheet. Just to verify, I did wire a circuit just as you describe, and of course there is no voltage at the analog input of the Arduino. Just connect B to VCC and everything will work.

    • Michael is right. Sensor pin B needs to be connected to power for this to work.

  • [...] Breathalyzer Image by Daniel Spillere Andrade Tutorial on: http://www.danielandrade.net/2010/03/07/building-an-breathalyzer…; [...]

  • Is it possible to build the breathalyzer using the MQ-3, but not using the arduino?

    • Sure it is possible! But you will need a way to measure the voltage from the sensor some other way.

  • [...] The write-up has the software, hardware and a video of the working project in action. PyroFactor: Read Permalink  |   Email This [...]

  • [...] Breathalyzer Image by Daniel Spillere Andrade Tutorial on: http://www.danielandrade.net/2010/03/07/building-an-breathalyzer…; [...]

  • Hi, how good is this breathalyzer, for how long it can measure the alcohol in blood, or this is only measure for a short period of time when the alcohol ate in the mouth?

  • Thanks for this. Very informative, and it helped me build this fireplace breathalyzer for my Christmas party:

    http://vimeo.com/17752413

    I used the light to indicate when it was taking the reading, not display the result — but the inspiration came from your version.

  • For people who are asking how to calibrate it or convert values to mg/L blood alchohol levels, see page 2 on this pdf http://nootropicdesign.com/projectlab/downloads/mq-3.pdf

  • @geoff Congrats!!
    @hammy Thanks for the info! :)

  • [...] alcohol breath tester – [Link] Tags: alcohol, Arduino, breath, MQ3 Filed in Arduino, Sensor | 1 views No Comments [...]

  • Very good this project! But, how many doses of “Velho Barreiro” were necessary to test? eheheheheh….

    Daniel

  • [...] based breath analyzer – [Link] Tags: alcohol, Arduino, Gas sensor, MQ-3 Filed in Arduino, Sensor | 2 views No Comments [...]

  • DO you have the circuit of this project?

  • @jaclyn what do you mean by that? If I have the scheme?

  • Why we need to calibrate the sensor? The pin A of MQ-3 connect to port analog/digital pin 0. The potentiometer 100k one leg connect to gnd and another leg connect to analog/digital pin 0?

  • How to calibrate the sensor?

  • i bought a Figaro TGS822 sensor, anyone use it??! there is any way to calibrate it…??!

  • what a superb project…………… if even provided with brief circuit

  • @omee what do you mean by that? The circuit is there, just read the post ;)

  • I am in a robotics class in highschool and I am trying to do this for a final project I was wondering if i could use any other boards other than the Arduino board?

  • Is it possible to use a Propellor microcontroller?

  • how many leg does mq-3 have? 6 or 4?

  • I recently built this breathalyzer to a T. The only problem I have with it is that when its turned on all the LEDS are lite. Why is this? Do I have to edit the code at all? PLEASE HELP!

  • @Kevin you have to calibrate it with the potentiometer :)

  • Great tutorial guys. This helps loads for my final project.

    I just have one question about the wiring in this picture http://img.photobucket.com/albums/v107/tigerbr/MQ-3.gif

    Is there any way to tell which side is A and which is B? Or can it work either way?

  • @Ian you can check that there is a difference between A side and B side just looking! :)

  • [...] ! Si ce n’est juste de bricoler un peu… Et d’où vient cette idée ??  D’ici et du foy de Telecom Bretagne bien sur [...]

  • What type of arduino board did you use for the proejct could you direct me to the exact model number?

  • Can u give me a link to ur schematic or circuit diagram about ur project cz i m facing a problem regarding my circuit…
    thx in Advance

  • @Ishan you can make your own schematic looking in the datasheet http://www.sparkfun.com/datasheets/Sensors/MQ-3.pdf

    @Alex You can use any arduino board, i used the 2009. http://www.arduino.cc/en/Main/ArduinoBoardDuemilanove

  • How can we take the output from the ardiuino board to some other application other than the ‘serial monitor’ in the arduino s/w?? we are tryin to develop an electronic nose using artificial neural nw, so we hav to get d o/p in analog form… also the sensor is always showing some values even if we remov it frm ‘alchoholic air’…
    do help me
    thanx!!

  • How should the potentiometer be wired? Should it be connected to my A0 analog port??

  • What are some cool things one might make with the Arduino board?…

    The Arduino is a small, cheap, microcontroller platform that’s easy to get started with. Artists and people with ideas, who may not know a lot about electronics can get good results fairly quickly. What you might make depends upon your imagination. :)

  • [...] mq3 danielandrade.net [...]

  • [...] circuit with an alcohol gas sensor and LEDs. (You can find an example of a similar circuit and code here)The circuits themselves were really simple to understand. We actually had exact diagrams (using [...]

  • Tentei reproduzir o projeto usando o mesmo esquema é o Arduino Mega 2650, mas o sensor MQ-3 retorna apenas o valor 0 (zero), mesmo quando há presença de alchool. O que está errado? Como posso identificar o problema?

  • Sir you could have shown the complete circuit diagram along with procedure

  • Sir you could have given the circuit diagram along with procedure. Next day after posting this comment could you please show the daigram

  • Could you show the circuit diagram

  • I ran across your blog, i believe your web site is awsome, keep writing.

  • Are you still active in answering questions for this project? Or are you tired of it? Ha
    I have what appears to be a common question that I still can’t seem to understand.

    I have the whole circuit built. The potentiometer part I still can’t dem to get right. Or I need to know its right so I can rule it out as my current problem.

    I am realatitvly new to all this, but I have built my own projects in the past

    Let’s please keep it in simpliest terms for everyone.

    100k pot has three legs. One SIDE leg goes to ground. The CENTER leg goes to analog input A0. The OTHER SIDE leg goes to MQ-3 pin A.

    Can you please confirm or correct. Thank you very much!

  • [...] model uses the MQ3 Alcohol Gas sensor and gets a significant jumpstart from Daniel Andrade’s implementation. Here’s a video of the first test. It plays “Take on Me” when you’re [...]

  • Hey guys this is an awesome project and I am interested in doing the same for a biomed electronics project. Anyway you could e-mail me a parts list and any pointers? Thanks alot!

  • do i have to use the mq-3 or can i use everey gas sensor i want?

    great work btw ;)

  • Hi Daniel,

    did you connect all 6 pins from sensor to the Arduino or only 4 of them ? What value did you used for load resistence ?
    The detection concentration scope of your sensor was 0.05 to 10 mg/L of alcohol or 0.04 to 4 mg/L of alcohol ? I ask you this because I have found on Internet 2 differnts datasheets…

    Thanks

  • Or did you connected like in the link below???

    http://wiring.org.co/learning/basics/airqualitymq135.html

    • Yeah, I just used 4 pins! Because the two A are the same.

  • Hi, would you happen to have a schematic of this project? This project looks exciting and I am just getting involved with Arduino so a lot of the terminology I am still getting familiar with.

    • What do you mean what happened?
      The schematic is fine, it doesnt show it all.

      Anything I can help you

  • Hi Daniel,
    The schematic is great. Just being as though I am new to this… I can’t see how everything is connected via the photos. Like I see multiple wires going into the (-) negative section but I don’t see in the diagrams what is connected in (-). I’m guessing because I don’t know how to read the schematic being as though I’m just starting off.

  • hi daniel
    awesome work!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    i am new and cant understand by the photo pls give a video or something showing how to connect pppppllllllllllllllllsssssssssss
    help me plsplsplsplsplspls

  • i have only 1 week left for the exhibition
    and can u show me how to take the reading digitally or by computer

  • Hi, there im currently doing a final year project about MQ-3 Sensor, so by just measuring the resistance drop on the load resistor, we will be able to know the concentration of the alchohol? as in ppm? Im totally confused, can anyone help to explain this? what does the graph in the datasheet refers to? How do i measure the concentration of gas?

  • HELLO!! CAN YOU POST FURTHER INFO ON HOW TO CONNECT THE 100 OHM RESISTOR, IM HAVING TRIUBLE READING THE VALUES FROM THE SENSOR

  • would you please explain the working principle ? i think it will be quite helpful for my final year project.

  • i have made it,,but the sensor is tgs2620..and i can’t calibrating the sensor,,can you help me? simulating by proteus..please send your project in my email,,[email protected]

  • [...] For more detail: Building an Breathalyzer with MQ-3 and Arduino [...]

  • boas, qual é o código usado, apenas para receber e enviar para o ecra (como os valores certos de alcool no ar)

    • é simplesmente o int sensorReading = analogRead(analogPin);

  • Is the pull down resistor the potentiometer?how do you connect the potentiometer?Urgently need to hear from you =)

    • one more thing..how can i calibrate the sensor using a potentiometer? am still new to these kind of stuff

  • el sketch tiene un error tiene el numero de led’s al revés tiene que comenzar del 2 al 11

  • Hi,
    I am a third year student, and i have my project abt how to prevent drink driving. Basically my professor last minute he asked me to build a breathalyzer and your work is very good. I had some questions if it’s ok?!
    1. Is it ok to use arduino uno board?
    2. the LEDs are connected to 330ohm resistors right?!
    3. The sensor has 4legs so there are connected to the board and the potentiometer right?!
    Thank you
    :) x

  • hi, I have one more 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

  • And the connection from the arduino to the LEDs please
    thx

  • Hello..I’m building Alcohol Sensor for my university project but I have to use an mbed instead of audrino and show the results on a LCD display. Can you please guide me how the circuit diagram will look? Thanks

    • Hi, I don’t know how is the mbed circuit.

  • Hey Daniel,
    I was really excited about your project, so i decided to use the idea for part of my thesis by adding lcd and buzzer and stuff. I want to use a potentiometer for calibrating my sensor, but its a bit confusing for me with the mq3 “useless” legs. Could you please send me the schematic by email, because I didn’t find it in the comment section :( ? Thanks in advance!

    • Like it’s said on the pos, you connect the pin B to ground and the A to the AnalogPic that connects to one leg of the potentiometer.

Leave a comment