Advertisement
Guest User

shuvo-hit

a guest
Dec 7th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1.  
  2. const int AOUTpin=0;//the AOUT pin of the alcohol sensor goes into analog pin A0 of the arduino
  3. const int DOUTpin=8;//the DOUT pin of the alcohol sensor goes into digital pin D8 of the arduino
  4. const int ledPin=13;//the anode of the LED connects to digital pin D13 of the arduino
  5. const int NormalHigh=600;
  6. int flag;
  7. int limit;
  8. int value;
  9.  
  10. //Include LCD library
  11. #include <LiquidCrystal.h>
  12. // initialize the library with the numbers of the interface pins
  13. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  14.  
  15.  
  16.  
  17.  
  18. void displaycontrol(int prt) {
  19. // set the cursor to column 0, line 1
  20. // (note: line 1 is the second row, since counting begins with 0):
  21. lcd.setCursor(0, 1);
  22. //Serial.print(prt);
  23. //Serial.print("\n");
  24. //Print a message to second line of LCD
  25. //lcd.print(prt);
  26. if (prt==1){
  27. //lcd.print("Chemical");
  28. lcd.print("YES");
  29. }
  30. else{
  31. //lcd.print("Normal");
  32. lcd.print(" ");
  33. lcd.print("NO");
  34. }
  35. }
  36.  
  37.  
  38.  
  39.  
  40. void setup() {
  41. Serial.begin(115200);//sets the baud rate
  42. pinMode(DOUTpin, INPUT);//sets the pin as an input to the arduino
  43. pinMode(ledPin, OUTPUT);//sets the pin as an output of the arduino
  44.  
  45. // set up the LCD's number of columns and rows:
  46. lcd.begin(16, 2);
  47. // Print a message to the LCD.
  48. lcd.print("Food Chemical ==");
  49. }
  50.  
  51.  
  52. void loop()
  53. {
  54. value= analogRead(AOUTpin);//reads the analaog value from the alcohol sensor's AOUT pin
  55. limit= digitalRead(DOUTpin);//reads the digital value from the alcohol sensor's DOUT pin
  56. Serial.print("Alcohol value: ");
  57. Serial.println(value);//prints the alcohol value
  58. Serial.print("Limit: ");
  59. Serial.print(limit);//prints the limit reached as either LOW or HIGH (above or underneath)
  60. delay(100);
  61. if (value >600){
  62. digitalWrite(ledPin, HIGH);//if limit has been reached, LED turns on as status indicator
  63. Serial.print("Alcohol");
  64. flag=1;
  65. displaycontrol(flag);
  66. }
  67. else{
  68. digitalWrite(ledPin, LOW);//if threshold not reached, LED remains off
  69. Serial.print("Normal");
  70. flag=0;
  71. displaycontrol(flag);
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement