Skip to content

Instantly share code, notes, and snippets.

@HackMEAny
Created January 27, 2021 14:50
Show Gist options
  • Save HackMEAny/3bf40b0ec4b479c306c838fce55964fd to your computer and use it in GitHub Desktop.
Save HackMEAny/3bf40b0ec4b479c306c838fce55964fd to your computer and use it in GitHub Desktop.
Drunk Driver Detector using Arduino & MQ3 Gas Sensor
//#include <LiquidCrystal.h> For using 12x2 lcd array
//LiquidCrystal lcd(12,11,6,5,4,3,2);
const int AOUTpin=0;//the AOUT pin of the alcohol sensor goes into analog pin A0 of the arduino
const int DOUTpin=8;//the DOUT pin of the alcohol sensor goes into digital pin D8 of the arduino
const int ledPin=13;//the anode of the LED connects to digital pin D13 of the arduino
const int motorPin=7;
int limit;
int value;
void setup() {
Serial.begin(9600);
pinMode(DOUTpin, INPUT);//sets the pin as an input to the arduino
pinMode(ledPin, OUTPUT);//sets the pin as an output of the arduino
pinMode(motorPin,OUTPUT);
digitalWrite(motorPin, HIGH);
// lcd.begin(16,2);
// lcd.clear();
// analogWrite(9,100);
// analogWrite(6,0);
}
void loop()
{
value=analogRead(AOUTpin);//reads the analaog value from the alcohol sensor's AOUT pin
Serial.print("Alcohol value : ");
Serial.print(value);
Serial.print("~~");
if(value<300)
{
Serial.println("You are sober.");
}
/*if (value>=200 && value<280)
{
Serial.print("Alcohol detected");
}*/
if (value>=301 && value<400)
{
Serial.println("You are sober.");
}
if (value>=401 && value<800)
{
Serial.println("Serious Booze here! ");
}
if(value>=800)//510
{
digitalWrite(ledPin, HIGH);
Serial.println("You are drunk!");
// lcd.print(value);
digitalWrite(motorPin, LOW);
}
else
{
digitalWrite(motorPin, HIGH);
digitalWrite(ledPin, LOW);
}
delay (500);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment