Introduction: Breathalyzer With Arduino

The objective of this project is to build a functional breathalyzer using an Arduino.

Step 1: Materials and Tools

  • LCD screen 16x2
  • MQ-3 alcohol sensor
  • Arduino UNO
  • 5V passive buzzer
  • 10kOhm resistor
  • Solderless Breadboard
  • Soldered breadboard
  • PVC tube (2 cm of diameter)
  • 20 male/male jumper wires
  • 20 female/male jumper wires
  • 6 batteries AA
  • 6 battery holders
  • Tactil Switch
  • Button
  • Welding kit
    • Soldering iron 30W
  • Hot glue
  • Cutter
  • Potentiometer 5K
  • Carton box (20x6x13)
  • Insulating tape
  • Tights

Step 2: Welding the LCD Screen.

Once you have all your materials and tools, you will realize that your LCD screen does not have pins. In order to fix this, you will need to weld the necessary pins to the respective holes in the screen. You can find on the internet how to weld a pin as it is a simple process. The final result should look like the image above. Once you finish building the circuit, there will be the second part of welding, as you will proceed to build the circuit without a breadboard.

Step 3: Building the Circuit

Using the protoboard and jumpers, make the connections according to the Diagram.

Step 4: Welding the Circuit

Once the circuit is functioning using the protoboard, you need to replicate it but without the protoboard. In order to do this, you will need to weld the following things:

- 2 male/male jumper to a female pin line (one to + and other to -)

- Replicate the button system in a soldered breadboard, and weld it to it.

- Weld the battery holders in series, connect the final 5V wire to the switch by welding it.

- Weld the Ground end wire to a male/male jumper, and then connect it to ground.

Step 5: Coding

// The program for the breathalyzer is below:

// Libraries
#include #include

// Warmup

int TIME_UNTIL_WARMUP = 20;

unsigned long time;

// Measurement

int TIME_UNTIL_MEASURE = 5;

unsigned long measurement_start;

// Sensor readings

int analogPin = A0;

int val = 0;

// Buzzer

const int buzzerPin = 3;

// Button

const int buttonPin = 2;

// Modes

bool measurement_mode;

bool measurement_done;

// LCD

// jm_LiquidCrystal_I2C.h lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display

const int rsPin = 9;

const int enablePin = 8;

const int d4Pin = 4;

const int d5Pin = 5;

const int d6Pin = 6;

const int d7Pin = 7;

LiquidCrystal lcd(rsPin, enablePin, d4Pin, d5Pin, d6Pin, d7Pin);

void setup() {

// Serial

Serial.begin(9600);

// Init LCD

analogWrite(10,120);

lcd.begin(16,2);

digitalWrite(13,LOW);

}

void loop() {

// Read button state

int button_state = digitalRead(buttonPin);

if (button_state && !measurement_mode) {

lcd.clear();

measurement_mode = true;

measurement_start = millis()/1000;

measurement_done = false;

}

if(button_state && measurement_done){ delay(500);

}

if (measurement_mode) {

digitalWrite(13,HIGH);

} else {

digitalWrite(13,LOW);

}

// Wait

delay(100);

// Get time

time = millis()/1000;

// Warmup

if(time<=TIME_UNTIL_WARMUP)

{

int progress_time = map(time, 0, TIME_UNTIL_WARMUP, 0, 100);

printWarming(progress_time);

}

else

{

if (measurement_mode == false && !measurement_done) {

// Instruction

printPress();

}

if (measurement_mode && !measurement_done) {

// Instruction

printMeasure();

// Sound

tone(buzzerPin, 1000);

// Read alcohol level

val = readAlcohol();

}

if (measurement_mode && !measurement_done && ((time - measurement_start)> TIME_UNTIL_MEASURE)){

noTone(buzzerPin);

measurement_mode = false;

measurement_done = true;

lcd.clear();

}

if(measurement_done) {

printAlcohol(val);

printAlcoholLevel(val);

//delay(5000);

//measurement_done = false;

}

}

}

void printWarming(int progress)

{

Serial.print("Warming up: ");

Serial.print(progress);

Serial.println("%");

lcd.setCursor(0,0);

lcd.print("Warming up: ");

lcd.setCursor(0,1);

lcd.print(progress, DEC);

lcd.print("%");

}

void printPress()

{

Serial.println("Press to start ...");

lcd.setCursor(0,0);

lcd.print("Press to start ... ");

}

void printMeasure()

{

Serial.print("Breathe until the ");

Serial.println("sound stops...");

lcd.setCursor(0,0);

lcd.print("Breathe until the");

lcd.setCursor(0,1)

lcd.print("sound stops...");

}

void printAlcohol(int value)

{

Serial.print("Sensor reading: ");

Serial.println(val);

lcd.setCursor(0,0);

lcd.print("Detecting...");

lcd.print(val,DEC);

}

void printAlcoholLevel(int value)

{

lcd.setCursor(0,1);

if(value<200)

{

Serial.println("You are sober");

lcd.print("You are sober");

}

if (value>=200 && value<280)

{

Serial.println("One beer.");

lcd.print("Una chela.");

}

if (value>=280 && value<350)

{

lcd.print("two or more beers");

Serial.println("two or more beers");

}

if (value>=350 && value <450)

{

lcd.print("Too much...");

Serial.println("Too much...

}

if(value>450)

{

lcd.print("You're drunk");

Serial.println("You're drunk");

}

}

int readAlcohol()

{

// Number measurements

int nb_measurements = 5;

int measurements;

// Measure

for (int i = 0; i < nb_measurements; i++) {

measurements = measurements + analogRead(analogPin);

}

measurements = measurements/nb_measurements;

return measurements;

}

Upload this program to the arduino

Step 6: Designing the Container

Once the circuit is complete and functional, it has to fit into a container/box (preferably a carton box). The model used was: link .

Using the cutter, cut a rectangle on the A side of the box (see image) for the LCD screen. Cut another one for the switch and a square for the button.

On side B cut 2 circles, one in the centre ( 2 cm of diameter) for the sensor and another one on the lower left part (2 cm of diameter) for the buzzer.

Cut a section of the PVC tube, one of 3cm and the other of 6cm. These sections will protect the sensor and buzzer and place them in their respective holes.

**If you want you can print your own stickers to show the ranges of each category and to label the buttons.

Step 7: Assemble

Hot glue the arduino and the batteryholders to the inside of the box. Hot glue the button, switch and LCD screen to their respective holes.

Cut a small square (3x3cm) of the tights and cover one of the ends of the 6cm PVC tube, place the buzzer and hot glue it in its hole.

Hot glue the 3cm PVC tube with the sensor to its hole.

**Cut the stickers and put them wherever you want!