Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 NormalHigh=600;
- int flag;
- int limit;
- int value;
- //Include LCD library
- #include <LiquidCrystal.h>
- // initialize the library with the numbers of the interface pins
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- void displaycontrol(int prt) {
- // set the cursor to column 0, line 1
- // (note: line 1 is the second row, since counting begins with 0):
- lcd.setCursor(0, 1);
- //Serial.print(prt);
- //Serial.print("\n");
- //Print a message to second line of LCD
- //lcd.print(prt);
- if (prt==1){
- //lcd.print("Chemical");
- lcd.print("YES");
- }
- else{
- //lcd.print("Normal");
- lcd.print(" ");
- lcd.print("NO");
- }
- }
- void setup() {
- Serial.begin(115200);//sets the baud rate
- pinMode(DOUTpin, INPUT);//sets the pin as an input to the arduino
- pinMode(ledPin, OUTPUT);//sets the pin as an output of the arduino
- // set up the LCD's number of columns and rows:
- lcd.begin(16, 2);
- // Print a message to the LCD.
- lcd.print("Food Chemical ==");
- }
- void loop()
- {
- value= analogRead(AOUTpin);//reads the analaog value from the alcohol sensor's AOUT pin
- limit= digitalRead(DOUTpin);//reads the digital value from the alcohol sensor's DOUT pin
- Serial.print("Alcohol value: ");
- Serial.println(value);//prints the alcohol value
- Serial.print("Limit: ");
- Serial.print(limit);//prints the limit reached as either LOW or HIGH (above or underneath)
- delay(100);
- if (value >600){
- digitalWrite(ledPin, HIGH);//if limit has been reached, LED turns on as status indicator
- Serial.print("Alcohol");
- flag=1;
- displaycontrol(flag);
- }
- else{
- digitalWrite(ledPin, LOW);//if threshold not reached, LED remains off
- Serial.print("Normal");
- flag=0;
- displaycontrol(flag);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement