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

IMG_3047

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
@ daniel@danielandrade.net / danielzabotti@gmail.com
@ 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
IMG_3052

Share/Save/Bookmark

22 Replies

No one has
  1. 1 carol

    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

  2. 2 DanielAndrade

    @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.
    :)

  3. 3 ioniser

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

  4. 4 Tyler

    Good job on the excellent writeup.

  5. 5 Alan Parekh

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

  6. 6 Gianni

    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?

  7. 7 DanielAndrade

    @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. :)

  8. 8 Michael Hodgins

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

  9. 9 Gianni

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

  10. 10 dan

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

  11. 11 DanielAndrade

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

  12. 12 dan

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

  13. 13 DanielAndrade

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

  14. 14 Alejandro

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

  15. 15 dan

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

  16. 16 Jowie Jabillo

    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 ???

  17. 17 ms

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

  18. 18 Michael

    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.

  1. 1 DIY : Construire un ethylomètre avec un kit Arduino. | Semageek
  2. 2 Don’t worry occifer, there is no blood in my alchohol! - Hack a Day
  3. 3 Arduino un monde d’inventions | Aux Zamis
  4. 4 Arduino Examples «

Leave a Reply