Gas Sensor (MQ-135)
The working principle of the MQ135 gas sensor is based on the adsorption of target gases by semiconductor gas-sensitive materials, which changes the resistance value. The sensor contains a sensitive element and a heater, with the sensitive element typically made of metal oxide semiconductor materials, such as tin dioxide (SnO2). When there are pollutant gases in the environment, these gas molecules react chemically with the metal oxide semiconductor on the surface of the sensitive element, causing its resistance value to change.
This change in resistance value is then converted into an electrical signal and processed by a data processor to ultimately obtain the concentration value of the target gas. In practical applications, the MQ135 sensor is commonly used to detect harmful gases in the air, such as ammonia, hydrogen sulfide, carbon monoxide, and formaldehyde.
The MQ135 sensor also has two output modes: digital output (DOUT) and analog output (AOUT). In digital output mode, when the sensor detects the target gas, the voltage value at pin 2 of the comparator LM393 is compared with the threshold set by the potentiometer RP. When the concentration exceeds the threshold, the comparator outputs a low level, and the LED lights up; conversely, it outputs a high level. In analog output mode, the sensor directly converts the resistance change into a voltage signal output, with the voltage increasing as the gas concentration rises.
Arduino and the gas sensor read the voltage value through the analog pin; a higher voltage value indicates a higher concentration of the detected gas. The measurement results are sent via the serial port.

int astl=0;
void setup()
{
Serial.begin(9600);
pinMode(A0, INPUT);
}
void loop()
{
astl=analogRead(A0);
Serial.println(astl);
delay(1000);
}
