Detects the amount of alcohol in your breath and will, using 3 LEDs, show you if you have been drinking too much…

What will I learn?

You will learn how to read analog values from a connected sensor and perform some action based on the value read from the sensor.

Prerequisites

A Computer with a configured Arduino IDE tested and working. If you don’t know how to get the basic set up working, check out my guide for Getting started (1/5)

Important notes

  • This project contains components that cannot handle 5V, so take care to use resistors (1 KOhm) with the LEDs.
  • Respect minus and plus, otherwise you may damage the components.
  • The MQ-3 sensor can get pretty hot, so take care if you’ve kept it running for a while!
  • The sensor must be calibrated for production use, so do not expect an 100% accurate result.
  • Start out by figuring out what components can handle 5V and what components can’t. If you connect a component that cant handle 5V you may destroy the component.

What you need

  • Breadboard
  • Dupont wires & jumper wires
  • CP2102
  • Arduino Pro Mini
  • MQ-3: Alcohol sensor
  • 3 KOhm resistor
  • 3 Color LED, one red, one yellow and one green.

Connecting instructions

  • Arduino VCC -> MQ-3 VCC
  • Arduino GND -> MQ-3 GND
  • Arduino A0 -> MQ-3 A0
  • Arduino D7 -> Positive pin of Green LED
  • Green LED negative pin -> 1KOhm resistor and then to GND
  • Arduino D8 -> Positive pin of Yellow LED
  • Yellow LED negative pin -> 1KOhm resistor and then to GND
  • Arduino D9 -> Positive pin of Red LED
  • Red LED negative pin -> 1KOhm resistor and then to GND

 

Fritzing

alcohol-sensor_bb

Code

 

/**
* Alcohol alarm - Registers the level of Alcohol and uses three LEDs to determine if
* you've had enough. Remember - this is just a prototype and should not
* be considered accurate!
*
* Connections:
* - Arduino VCC -> MQ-3 VCC
* - Arduino GND -> MQ-3 GND
* - Arduino A0 -> MQ-3 A0
* - Arduino D7 -> Positive pin of Green LED
* - LED negative pin -> 1KOhm resistor and then to GND
* - Arduino D8 -> Positive pin of Yellow LED
* - LED negative pin -> 1KOhm resistor and then to GND
* - Arduino D9 -> Positive pin of Red LED
* - LED negative pin -> 1KOhm resistor and then to GND
*
*  Author: Jakob Maaloe
*  https://wackydeveloper.wordpress.com
*/

int alcoholSensorPin = A0;

int greenLedPin = 7;
int yellowLedPin = 8;
int redLedPin = 9;

int value;

void setup() {
Serial.begin(115200); // Sets the baud rate for logging

pinMode(greenLedPin, OUTPUT);
pinMode(yellowLedPin, OUTPUT);
pinMode(redLedPin, OUTPUT);
}

void loop() {
value = analogRead(alcoholSensorPin); // reads the sensor value

Serial.print("Alcohol value: ");
Serial.println(value); // prints the alcohol value

if (value > 0 && value = 350 && value = 500) {
Serial.println("That's it... Taxi!");
digitalWrite(greenLedPin, HIGH);
digitalWrite(yellowLedPin, HIGH);
digitalWrite(redLedPin, HIGH);
}
delay(300); // wait a little while before doing another read
}

Next steps

I wonder what the D0 pin is for on the sensor? Google and try it out… or try out the next project, the Distance alarm.

Advertisements