Simple Arduino based breathalyzer with display output

 A breathalyzer is a generic name for a type of device used to measure blood alcohol content from a sample of exhaled breath. This means that the device can detect the amount of alcohol you have drunk. This device becomes very useful for preventing accidents caused by drunk driving.


Simple Arduino based breathalyzer with display output

With this device, you can easily alert the car driver when he is too drunk to drive. It is important to note that this project is not accurate enough to replace a standard breathalyzer, however, it can be used to understand that a person has drunk enough to avoid driving.


In this project we will be using an MQ3 alcohol sensor. It is a low cost semiconductor sensor capable of detecting the presence of alcohol in air at concentrations ranging from 0.05 to 10 mg / L. The sensor uses a chemical reaction to determine the alcohol level, and the main sensing element in the sensor is SnO2, the conductivity of SnO2 is low in clean air, but increases as the concentration of gaseous alcohol in the air (breathing) increases. It has high sensitivity to alcohol and good resistance to interference and noise from things like smoke and gasoline. Alcohol level data with warning will be displayed on a compact LCD display via the I2C serial interface.


The connection diagram of the Arduino-based breathalyzer components is presented below:


Simple Arduino based breathalyzer with display output

The program code is as follows:



#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET 4
int TIME_UNTIL_WARMUP = 900;
unsigned long time;


int analogPin = 0;
int val = 0;
Adafruit_SSD1306 display(OLED_RESET);


void setup()   {                

 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
 display.clearDisplay();
}


void loop() {  
  
  delay(100);

  val = readAlcohol();
  printTitle();
  printWarming();

  time = millis()/1000;
  
  if(time<=TIME_UNTIL_WARMUP)
  {
    time = map(time, 0, TIME_UNTIL_WARMUP, 0, 100);
    display.drawRect(10, 50, 110, 10, WHITE);
    display.fillRect(10, 50, time,10,WHITE);
  }else
  {
     printTitle();
     printAlcohol(val);
     printAlcoholLevel(val);  
  }
  display.display();

}


void printTitle()
{
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(22,0);
  display.println("Breath Analyzer");
}

void printWarming()
{
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(0,20);
  display.println("Warming up");
}

void printAlcohol(int value)
{
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(45,25);
  display.println(val);
}

void printAlcoholLevel(int value)
{
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(10,55);
  
  if(value<200)
  {
      display.println("You are sober.");
  }
  if (value>=200 && value<280)
  {
      display.println("You had a beer.");
  }
  if (value>=280 && value<350)
  {
      display.println("Two or more beers.");
  }
  if (value>=350 && value <450)
  {
      display.println("I smell Oyzo!");
  }
  if(value>450)
  {
     display.println("You are drunk!");
  }
 }
 
 int readAlcohol()
 {
  int val = 0;
  int val1;
  int val2;
  int val3; 


  display.clearDisplay();
  val1 = analogRead(analogPin); 
  delay(10);
  val2 = analogRead(analogPin); 
  delay(10);
  val3 = analogRead(analogPin);
  
  val = (val1+val2+val3)/3;
  return val;
 }

Previous Post Next Post

Contact Form