Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*The Pololu Carbon Monoxide & Flammable Gas Sensor MQ-7 is an analog gas sensor that detects the presence of carbon monoxide (CO) and flammable gases such as propane, methane, and butane. Here's an example code in Arduino that reads the gas concentration from the sensor:
- Note: This code assumes that the Pololu Carbon Monoxide & Flammable Gas Sensor MQ-7 is connected to pin A0 of the Arduino board. If you're using a different pin, you'll need to modify the SENSOR_PIN definition accordingly. Also, the equations used to calculate the gas concentrations were determined experimentally, so you may need to adjust them for your specific sensor. Finally, note that the sensor is designed to detect specific gases and may not detect all flammable gases or CO concentrations in the area.
- */
- const int SENSOR_PIN = A0; // the pin connected to the sensor
- float voltage; // the voltage reading from the sensor
- float co_concentration; // the carbon monoxide concentration calculated from the voltage
- float flammable_concentration; // the flammable gas concentration calculated from the voltage
- void setup() {
- Serial.begin(9600);
- pinMode(SENSOR_PIN, INPUT);
- }
- void loop() {
- // read the voltage from the sensor
- voltage = analogRead(SENSOR_PIN) * (5.0 / 1023.0);
- // calculate the carbon monoxide concentration in parts per million (ppm)
- co_concentration = pow(10, ((1.662 * voltage) - 1.185));
- // calculate the flammable gas concentration in parts per million (ppm)
- flammable_concentration = pow(10, ((1.662 * voltage) - 1.185)) * 2.5;
- // print the gas concentrations
- Serial.print("Carbon Monoxide Concentration: ");
- Serial.print(co_concentration);
- Serial.println(" ppm");
- Serial.print("Flammable Gas Concentration: ");
- Serial.print(flammable_concentration);
- Serial.println(" ppm");
- // delay before reading from the sensor again
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement