Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. /* MQ-3 Alcohol Sensor Circuit with Arduino */
  2.  
  3. const int AOUTpin=0;//the AOUT pin of the alcohol sensor goes into analog pin A0 of the arduino
  4. const int DOUTpin=8;//the DOUT pin of the alcohol sensor goes into digital pin D8 of the arduino
  5. const int ledPin=13;//the anode of the LED connects to digital pin D13 of the arduino
  6.  
  7. int limit;
  8. int value;
  9.  
  10. void setup() {
  11. Serial.begin(115200);//sets the baud rate
  12. pinMode(DOUTpin, INPUT);//sets the pin as an input to the arduino
  13. pinMode(ledPin, OUTPUT);//sets the pin as an output of the arduino
  14. }
  15.  
  16. void loop()
  17. {
  18. value= analogRead(AOUTpin);//reads the analaog value from the alcohol sensor's AOUT pin
  19. limit= digitalRead(DOUTpin);//reads the digital value from the alcohol sensor's DOUT pin
  20. Serial.print("Alcohol value: ");
  21. Serial.println(value);//prints the alcohol value
  22. Serial.print("Limit: ");
  23. Serial.print(limit);//prints the limit reached as either LOW or HIGH (above or underneath)
  24. delay(100);
  25. if (limit == HIGH){
  26. digitalWrite(ledPin, HIGH);//if limit has been reached, LED turns on as status indicator
  27. }
  28. else{
  29. digitalWrite(ledPin, LOW);//if threshold not reached, LED remains off
  30. }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement