-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsensor_SO2.ino
21 lines (17 loc) · 1.01 KB
/
sensor_SO2.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//Here is the code to use an MQ135 sensor with an Arduino to measure sulfur dioxide (SO2) levels:
#define RL_VALUE 10.0
#define RO_CLEAN_AIR_FACTOR 9.83
const int mq135Pin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(mq135Pin);
float rs_ro_ratio = (RL_VALUE * 1.0) / (1023.0 / sensorValue - 1.0);
float ppm = pow(10, ((log10(rs_ro_ratio) - log10(RO_CLEAN_AIR_FACTOR)) / -0.8));
Serial.print("SO2 Concentration: ");
Serial.print(ppm);
Serial.println(" ppm");
delay(1000);
}
//The RL_VALUE and RO_CLEAN_AIR_FACTOR constants are used to calculate the resistance of the sensor in clean air, which is then used to calculate the concentration of SO2 in parts per million (ppm). The analogRead function is used to read the analog value from the sensor, which is connected to the A0 pin of the Arduino. The resulting concentration is printed to the serial monitor through the Serial.println function. The delay function is used to pause the program for 1 second between readings.