Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. const int AOUTpin=0; //the AOUT pin of the methane sensor goes into analog pin A0 of the arduino
  2. const int DOUTpin=8; //the DOUT pin of the methane sensor goes into digital pin D8 of the arduino
  3. const int ledPin=13; //the anode of the LED connects to digital pin D13 of the arduino
  4.  
  5. int limit;
  6. int value;
  7.  
  8. void setup()
  9. {
  10. Serial.begin(9600); //sets the baud rate
  11. pinMode(DOUTpin, INPUT);
  12. pinMode(ledPin, OUTPUT);
  13. }
  14.  
  15. void loop()
  16. {
  17.  
  18. value= analogRead(AOUTpin); //reads the analaog value from the methane sensor's AOUT pin
  19. limit= digitalRead(DOUTpin); //reads the digital value from the methane sensor's DOUT pin
  20.  
  21. Serial.print("CO value: ");
  22. Serial.println(value); //prints the methane value
  23. Serial.print("Limit: ");
  24. Serial.print(limit); //prints the limit reached as either LOW or HIGH (above or below)
  25. delay(1000);
  26.  
  27. if (limit == HIGH)
  28. {
  29. digitalWrite(ledPin, HIGH); //if limit has been reached, LED turns ON
  30. }
  31. else
  32. {
  33. digitalWrite(ledPin, LOW); //if limit not reached, LED remains OFF
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement