Pin Name | Pin Number | Description |
---|---|---|
VCC | 1 | Power supply input (5V DC) |
GND | 2 | Ground connection |
AOUT | 3 | Analog output signal proportional to gas concentration |
DOUT | 4 | Digital output signal (high/low) based on a user-defined threshold |
// MQ-9 Gas Sensor Example Code for Arduino UNO
// This code reads analog data from the MQ-9 sensor and prints the gas concentration
// to the Serial Monitor. Ensure the sensor is connected to the correct pins.
const int analogPin = A0; // Connect AOUT pin of MQ-9 to Arduino analog pin A0
const int digitalPin = 2; // Connect DOUT pin of MQ-9 to Arduino digital pin 2
void setup() {
Serial.begin(9600); // Initialize serial communication at 9600 baud
pinMode(digitalPin, INPUT); // Set DOUT pin as input
}
void loop() {
int analogValue = analogRead(analogPin); // Read analog value from AOUT
int digitalValue = digitalRead(digitalPin); // Read digital value from DOUT
// Convert analog value to voltage (assuming 5V reference)
float voltage = analogValue * (5.0 / 1023.0);
// Print the readings to the Serial Monitor
Serial.print("Analog Value: ");
Serial.print(analogValue);
Serial.print(" | Voltage: ");
Serial.print(voltage);
Serial.print("V | Digital Value: ");
Serial.println(digitalValue);
delay(1000); // Wait for 1 second before the next reading
}
By following this documentation, users can effectively integrate the MQ-9 Gas Sensor Module into their projects and ensure reliable gas detection performance.