Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const int AOUTpin=0; //the AOUT pin of the methane sensor goes into analog pin A0 of the arduino
- const int DOUTpin=8; //the DOUT pin of the methane 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 limit;
- int value;
- void setup()
- {
- Serial.begin(9600); //sets the baud rate
- pinMode(DOUTpin, INPUT);
- pinMode(ledPin, OUTPUT);
- }
- void loop()
- {
- value= analogRead(AOUTpin); //reads the analaog value from the methane sensor's AOUT pin
- limit= digitalRead(DOUTpin); //reads the digital value from the methane sensor's DOUT pin
- Serial.print("CO value: ");
- Serial.println(value); //prints the methane value
- Serial.print("Limit: ");
- Serial.print(limit); //prints the limit reached as either LOW or HIGH (above or below)
- delay(1000);
- if (limit == HIGH)
- {
- digitalWrite(ledPin, HIGH); //if limit has been reached, LED turns ON
- }
- else
- {
- digitalWrite(ledPin, LOW); //if limit not reached, LED remains OFF
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement