In this tutorial, you will learn how to detect gas with an MQ-135 sensor and an Arduino.
Parts Required
- Arduino
- MQ-135 Gas Sensor
- Jumper wires
- Breadboard
Circuit
To use the LED connect it to digital pin 13.
Code
int sensorValue;
int digitalValue;
void setup()
{
Serial.begin(9600); // sets the serial port to 9600
pinMode(13, OUTPUT);
pinMode( 3, INPUT);
}
void loop()
{
sensorValue = analogRead(0); // read analog input pin 0
digitalValue = digitalRead(2);
if(sensorValue>400)
{
digitalWrite(13, HIGH);
}
else
digitalWrite(13, LOW);
Serial.println(sensorValue, DEC); // prints the value read
Serial.println(digitalValue, DEC);
delay(1000); // wait 100ms for next reading
}
References
[1] https://microcontrollerslab.com/interfacing-mq-135-gas-sensor-arduino/