เครื่องวัดปริมาณเเอลกอฮอล์
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4);
const int buttonPin = 2;
const int buzzerPin = 7;
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
int ledpin1 = 3;
int ledpin2 = 4;
int ledpin3 = 5;
int limit;
int value;
int buttonState = 0;
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
pinMode(buttonPin, INPUT);
pinMode(buzzerPin,OUTPUT);
pinMode(DOUTpin, INPUT);//sets the pin as an input to the arduino
pinMode(ledpin1, OUTPUT);
pinMode(ledpin2, OUTPUT);
pinMode(ledpin3, OUTPUT);//sets the pin as an output of the arduino
}
void loop(){
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
value= analogRead(AOUTpin);//reads the analaog value from the alcohol sensor's AOUT pin
Serial.println(value);
if(value<200)
{
Serial.println("You are fine.");
lcd.print("Result ");
lcd.print(value);
lcd.setCursor(0,1);
lcd.print("You are fine.");
digitalWrite(buzzerPin,LOW);
digitalWrite(ledpin1, HIGH);
delay(1000);
digitalWrite(buzzerPin,HIGH);
digitalWrite(ledpin1, LOW);
}
if (value>=200 && value<280)
{
Serial.println("Alcohol detected");
lcd.print("Result ");
lcd.print(value);
lcd.setCursor(0,1);
lcd.print("Alcohol Detected");
digitalWrite(buzzerPin,LOW);
digitalWrite(ledpin2, HIGH);
delay(750);
digitalWrite(buzzerPin,HIGH);
digitalWrite(ledpin2, LOW);
}
if (value>=280 && value<350)
{
Serial.println("Just A Little.");
lcd.print("Result ");
lcd.print(value);
lcd.setCursor(0,1);
lcd.print("Just A Little.");
digitalWrite(buzzerPin,LOW);
digitalWrite(ledpin2, HIGH);
delay(500);
digitalWrite(buzzerPin,HIGH);
digitalWrite(ledpin2, LOW);
}
if (value>=350 && value <450)
{
Serial.println("Serious Booze here! ");
lcd.print("Result ");
lcd.print(value);
lcd.setCursor(0,1);
lcd.print("No More Drink!");
digitalWrite(buzzerPin,LOW);
digitalWrite(ledpin3, HIGH);
delay(250);
digitalWrite(buzzerPin,HIGH);
digitalWrite(ledpin3, LOW);
}
if(value>450)
{
Serial.println("You are drunk!");
lcd.print("Result ");
lcd.print(value);
lcd.setCursor(0,1);
lcd.print("R.I.P");
digitalWrite(buzzerPin,LOW);
digitalWrite(ledpin3, HIGH);
}
delay (500);
lcd.clear();
}
else{
lcd.setCursor(0,0);
lcd.print("Alcohor Meter");
lcd.setCursor(0,1);
lcd.print("Press Button...");
digitalWrite(buzzerPin,HIGH);
delay(500);
lcd.clear();
}
}
ไม่มีความคิดเห็น:
แสดงความคิดเห็น