Arduino

Build Your Own Arduino Breathalyzer

In this article, we are going to use the Arduino platform to build a really cool project: your very own alcohol breathalyser. To do that, we are going to use a simple Arduino Uno board, along with an ethanol gas sensor, to sense the level of alcohol in your breath. To display the results, we will use an LCD screen. As the 'interface' with the system, we will just use a simple push button and a piezo buzzer.

Note that because of possible sensor calibration issues, this project should be used for educational purposes only, and not to determine your real alcohol blood levels before driving for example. Let's start!

What You'll Need

ComponentQty
Arduino Uno1
MQ-3 Ethanol Sensor1
Piezo Buzzer1
Push Button1
I2C LCD Screen1
10k Ohm Resistor1
Breadboard1
Jumper Wires (Male/Male and Male/Female)Multiple

Step by Step

1

Hardware & Software Requirements

<p style="text-align: justify;">Let's first see what we need for this project. We will of course need an Arduino Uno board, that will be the 'brain' of the project.</p><p style="text-align: justify;">Then, we will need a sensor to measure the alcohol levels in your breath. Here, I used an MQ-3 ethanol sensor, mounted on a breakout board:</p><p href="/cdn/storage/Images/CYJbEgiwzQ8cQyEuE/original/CYJbEgiwzQ8cQyEuE.jpg" style="text-align: justify;"><img src="https://makecademy.com/cdn/storage/Images/jGhCC333qLwPXFFuo/original/jGhCC333qLwPXFFuo.jpg"></p><p style="text-align: justify;">As the interface for the project, we will also use a push button (with a 10k Ohm resistor) and a piezo buzzer. I also used an I2C LCD screen to display the results.</p><p style="text-align: justify;">Finally, you will also need a breadboard and a bunch of jumper wires.</p><p style="text-align: justify;">On the software side, you will need the latest version of the Arduino IDE, as well as the I2C LCD library that you can get using the library manager from the Arduino IDE.</p>

2

Hardware Configuration

<p style="text-align: justify;">Let's now assemble the project. This is a top view showing all the connections between the components of the project:</p><p href="/cdn/storage/Images/2i2MhFcfMtfiEdTkJ/original/2i2MhFcfMtfiEdTkJ.png" style="text-align: justify;"><img src="https://makecademy.com/cdn/storage/Images/XQEJShSK7vuwDxGLu/original/XQEJShSK7vuwDxGLu.png"></p><p style="text-align: justify;">Let's see how to assemble the different parts of the project. First, let's connect the power supply from the Arduino board to the breadboard. Connect the Arduino 5V pin to the red power rail of the breadboard, and the GND pin to the blue power rail of the breadboard.</p><p style="text-align: justify;">For the MQ-3 sensor, connect the VCC pin to the red power rail, the GND pin to the blue power rail, and finally the signal pin to analog pin A0 of the Arduino board.</p><p style="text-align: justify;">For the push button, connect one side of the button in series with the 10k Ohm resistor. Then, connect this side as well to pin 2 of the Arduino board. Then, connect the other side of the resistor to the ground, and the other side of the button to VCC.</p><p style="text-align: justify;">For the piezo buzzer, connect the + pin on pin 7 of the Arduino board, and the other pin on the ground.</p><p style="text-align: justify;">Finally, connect the LCD screen using the I2C interface (SDA and SCL on the Arduino board).</p><p style="text-align: justify;">This is the picture of the completely assembled project:</p><p href="/cdn/storage/Images/jXQqKtbCHdRG5HLGr/original/jXQqKtbCHdRG5HLGr.jpg" style="text-align: justify;"><img src="https://makecademy.com/cdn/storage/Images/9p25kdWAwWpvgFKPZ/original/9p25kdWAwWpvgFKPZ.jpg"></p>

3

Building the Code for the Project

<p style="text-align: justify;">We are now going to write the code for the project. Here, we are simply going to go over the most important parts of the code. You will be able to find the complete version of the code later on the GitHub repository of the project.</p><p style="text-align: justify;">First, we declare the libraries that are necessary for the LCD screen:</p><pre style="text-align: justify;"><span style="font-weight: bold;">#include &lt;LiquidCrystal_I2C.h&gt;</span></pre><p style="text-align: justify;">We declare a warmup time of 20 seconds for the MQ-3 sensor, which is necessary for a good functioning of the sensor:</p><pre style="text-align: justify;"><span style="font-weight: 700;">int</span> TIME_UNTIL_WARMUP = <span>20</span>; <span style="font-weight: 700;">unsigned</span> <span style="font-weight: 700;">long</span> time;</pre><p style="text-align: justify;">We also declare a time for each measurement, which is basically the time for which the user will have to blow on the sensor for the measurement:</p><pre style="text-align: justify;"><span style="font-weight: 700;">int</span> TIME_UNTIL_MEASURE = <span>5</span>; <span style="font-weight: 700;">unsigned</span> <span style="font-weight: 700;">long</span> measurement_start;</pre><p style="text-align: justify;">Then, we declare the pin of the MQ-3 sensor, and we initialise the value of the sensor to 0:</p><pre style="text-align: justify;"><span style="font-weight: 700;">int</span> analogPin = A0; <span style="font-weight: 700;">int</span> val = <span>0</span>;</pre><p style="text-align: justify;">We also declare the pin of the piezo buzzer:</p><pre style="text-align: justify;"><span style="font-weight: 700;">const</span> <span style="font-weight: 700;">int</span> buzzerPin = <span>7</span>;</pre><p style="text-align: justify;">And the pin of the push button:</p><pre style="text-align: justify;"><span style="font-weight: 700;">const</span> <span style="font-weight: 700;">int</span> buttonPin = <span>2</span>;</pre><p style="text-align: justify;">Then, we initialise the I2C LCD instance:</p><pre style="text-align: justify;"><span>LiquidCrystal_I2C <span style="font-weight: 700;">lcd</span><span>(<span>0x27</span>,<span>20</span>,<span>4</span>)</span></span>;</pre><p style="text-align: justify;">In the setup() function of the sketch, we initialise the LCD screen, and activate the backlight:</p><pre style="text-align: justify;"><span style="font-weight: 700;">lcd</span><span>.init</span>(); <span style="font-weight: 700;">lcd</span><span>.backlight</span>();</pre><p style="text-align: justify;">In the loop() part of the sketch, we check if the button was pressed. If that's the case, we reset the whole measurement process:</p><pre style="text-align: justify;"><span style="font-weight: 700;">int</span> button_state = digitalRead(buttonPin); <span style="font-weight: 700;">if</span> (button_state &amp;&amp; !measurement_mode) { &nbsp; lcd.clear(); &nbsp; measurement_mode = <span>true</span>; &nbsp; measurement_start = millis()/<span>1000</span>;&nbsp; &nbsp; measurement_done = <span>false</span>; }</pre><p style="text-align: justify;">We also keep track of the time with a counter:</p><pre style="text-align: justify;"><span>time</span> = millis()/<span>1000</span>;</pre><p style="text-align: justify;">If we are still in the warmup process, we wait, and print this status on the LCD screen:</p><pre style="text-align: justify;"><span style="font-weight: 700;">if</span>(time&lt;=time_until_warmup) { printwarming(progress_time); }</pre><p style="text-align: justify;">Once the warmup is done, we wait until the user press the button to start the measurement process:</p><pre style="text-align: justify;"><span style="font-weight: 700;">else</span> { &nbsp; <span style="font-weight: 700;">if</span> (measurement_mode == <span>false</span> &amp;&amp; !measurement_done) { &nbsp; &nbsp; printPress(); &nbsp; } <span style="font-weight: 700;">if</span> (measurement_mode &amp;&amp; !measurement_done) { printMeasure(); tone(buzzerPin, <span>1000</span>); val = readAlcohol(); } <span style="font-weight: 700;">if</span> (measurement_mode &amp;&amp; !measurement_done &amp;&amp; ((time - measurement_start)&gt; TIME_UNTIL_MEASURE)){ noTone(buzzerPin); measurement_mode = <span>false</span>; measurement_done = <span>true</span>; lcd.clear(); } <span style="font-weight: 700;">if</span>(measurement_done) { printAlcohol(val); printAlcoholLevel(val); } }</pre>

4

Testing The Breathalyzer

<p style="text-align: justify;">Let's now test the project. Make sure that you made all the correct hardware connections. Then, open the code with the Arduino IDE, and upload it to the board.</p><p style="text-align: justify;">Then, you should see the warming up part of the sketch, indicating the sensor is initializing. The project will then ask you to press the button to start.</p><p style="text-align: justify;">You can then breathe into the sensor until you don't hear the sound from the buzzer anymore.</p><p style="text-align: justify;">After that, you will get the reading, and also a message indicating if you are sober or not (according to the threshold you set in the code).</p><p style="text-align: justify;">Congratulations, you just build your own breathalizer based on Arduino!</p>

5

How to Go Further

<p style="text-align: justify;">In this project, we built a very simple breathalizer project based on Arduino, using a MQ-3 Ethanol sensor. Of course, the next step would be to really carefully calibrate the sensor so it can give more accurate readings. If you did such calibration step with your project, please share below!</p>

Wrapping Up

You have successfully built your own Arduino-based breathalyzer! This project demonstrates practical applications of Arduino microcontrollers, sensor interfacing, and user interaction through buttons and feedback mechanisms. While this educational version provides a foundation for understanding alcohol vapor detection, remember that real breathalyzers require precise calibration for accurate results. You can further enhance this project by implementing data logging, wireless connectivity, or integrating additional sensors for improved accuracy.