Tutorial: Breathalyzer using Alcohol Gas Sensor with Arduino

In this tutorial, we will demonstrate how to use the gas sensors and also how you can make a homemade Breathalyzer using an alcohol sensor, Arduino and LEDs

 

Material List

1x Arduino

1x Alcohol Sensor

1x Breadboard

7x LEDS

6x Resistor 330Ω

1x Resistor 10KΩ

Some jumpers

1. How it works

1.1) Gas Sensor

The gas sensor operates as potentiometer, but instead of get the resistance variation, we will take the variation of gas concentration(0d to 1023d).

1.2) LEDs (Bargraph)

Arduino will transform the variation of gas concentration, that ranging 0d to 1023, in a scale of 6 LEDs using the function map(maxreading01023, 0, qtyLED).

1.3) Adaptations

For this aplication we use a mouthwash, so we changed  the scale of (0d to 1023) to (0d to 200d), because the mouthwash not contain a high level of alcohol. So we use the funcion map(maxreading0200, 0, qtyLED).

2. The Sketch


#define qtyLED 6  //Declare the quantity of LED's for the bar graph
int LEDs[qtyLED]; //Array to store the states of the LEDs
int sensorPin = 0; //Variable that will hold the current value of the sensor
int time; //Variable that will hold the amount of time for the sensor to be read
int maxreading; //Variable to store the maximum value read during the last reading
//For loop counting variables
int i;
int j;
 
void setup()

  //Initialize the counting variables
  i=0;
  j=2;
  
  while(i < qtyLED) //While i is less than the number of defined LED's
  {                 //...save the value of i+2 in the LEDs array. we add 2 so that it represents one of our digital pins
    LEDs[i] = j;
    i++;
    j++;
  }
  
  for(i=0;i<qtyLED;i++) //Define the LED Pins as outputs. In this case 2->7
  {
    pinMode(LEDs[i], OUTPUT);
  }
  pinMode(13, OUTPUT); //Define pin 13 as an output so we can show when we are not taking a reading from the sensor(Blinkin
                       //...Or when we are taking a reading from the sensor (Solid)
}

void loop()
{
  PORTB = PORTB ^ 100000;  //Invert pin 13 to give the LED a blinking effect
  delay(100); //Delay so that the user can see the blinking happen
  int sensor = analogRead(sensorPin); //Read the sensors value and store it in the sensor variable
  if(sensor >= 40) //If the value is less that 40(value for the chemical being used in this example)
  {  
    digitalWrite(13, HIGH); //Turn on the blue LED indecating that the sensor detected a minimal amount of alcohol (sensor >= 40)
    maxreading = 0;         //Initiate the max reading to 0
    for(time = 0;time <= 5000;time++) //Read the sensor for 5 seconds
    {                                 //...every millisecond update the value of the max reading of the sensor
      int sensor = analogRead(sensorPin);
      delay(1);
      if(sensor > maxreading)
      {
        maxreading = sensor;
      }
    }
    digitalWrite(13, LOW); //As soon as the reading is complete turn off the blue LED
    int level = map(maxreading, 0, 200, 0, qtyLED); //Map the value from 0 to 200(reading from sensor) to 0 and the number of LEDs which is 6
                                                    //...0 to 6(LEDs) level determines how many of them turn on.
    for(i=0;i<qtyLED;i++) //Compare all the leds current state with the value of the level that was read
    {                     //if for example the level read was 5, then LEDs 2->6 would turn on.
      if (i < level) //If the current LED being checked is less that the level
      {
        digitalWrite(LEDs[i], HIGH); //...Turn it on
      }
      else //If the current LED being checked is higher than the level
      {
        digitalWrite(LEDs[i], LOW); //...Turn it off
      }
    }
    delay(10000); //Wait 10 seconds for the user to get the reading from the led bar graph
    for(i=0;i<qtyLED;i++) //Turn off all the LEDs
    {
      digitalWrite(LEDs[i],LOW);
    }
  }
}

3. The Circuit

Reference:

https://www.sparkfun.com/products/8880

Views: 1482

Tags: Alcohol, Arduino, Breathalyzer, Gas, Sensor

Comment

You need to be a member of GarageLab (arduino, electronics, robotics, hacking) to add comments!

Join GarageLab (arduino, electronics, robotics, hacking)

Latest Activity

Chas Stearns updated their profile
13 hours ago
Shannon Bradley and Marcelo Rodrigues are now friends
Wednesday
Terry Renner is now a member of GarageLab (arduino, electronics, robotics, hacking)
Wednesday
Andy S posted a discussion

Arduino MEGA boolean?

Hi everyone,been banging my head against the wall a few days now.i have a small project, where i…See More
Wednesday
Bobby Marshall posted a video

SELFIE Mirror

Meet the S.E.L.F.I.E., the "The Self Enhancing Live Feed Image Engine". Find out how it works: http://istrategylabs.com/2014/04/take-an-instant-selfie-with-t...
Tuesday
GarageLab posted a blog post
Apr 15
pj jones posted a status
"Designing an Home Automation Project"
Apr 14
Profile Iconpj jones, Robert Kribel and Lars Goldschlager joined GarageLab (arduino, electronics, robotics, hacking)
Apr 14
Fontaine Pierre commented on GarageLab's blog post Tutorial: Using GPS Shield as an Anti-Theft Device
"Hi, Is it possible to make a car tracker with this GPS + GSM shield to send a message if limits…"
Apr 11
GarageLab posted a blog post
Apr 11
Profile Iconeslam mohamed haredy, Wesley Castillo and Lise Pape joined GarageLab (arduino, electronics, robotics, hacking)
Apr 10
Terry Dark left a comment for Beula Isaac
"Hi Beulah, Greetings from down under (Australia) Please tell me about yourself and your interests…"
Apr 9
Terry Dark and Beula Isaac are now friends
Apr 9
GarageLab posted blog posts
Apr 9
GarageLab posted a blog post

Festo's BionicKangaroo gets the hop on energy-efficiency

The BionicKangaroo features pneumatic actuators that provide the jumping power and at the same time…See More
Apr 7
Profile IconAnthony Parker, John Nicosia and Tom Devey joined GarageLab (arduino, electronics, robotics, hacking)
Apr 7
wani sageer posted photos
Apr 6
GarageLab posted a blog post

Using a 3D Printer to Draw Tattoos: InkD

 It’s one thing to allow a professional tattoo artist to ink your arm. It’s another thing…See More
Apr 4
GarageLab posted a blog post

Dispensing Solder Paste With A 3D Printer

There’s a strange middle ground in PCB production when it comes to making a few boards. Dispensing…See More
Apr 3
Duong Nguyen is now a member of GarageLab (arduino, electronics, robotics, hacking)
Apr 3

© 2014   Created by Marcelo Rodrigues.

Badges  |  Report an Issue  |  Terms of Service