Gas Sensor Reference
An MQ-series style gas/smoke sensor with both analog and threshold digital outputs.
Pin names
| Name | Description |
|---|---|
| AOUT | Analog Out — voltage proportional to gas concentration |
| DOUT | Digital Out — HIGH/LOW based on a threshold (adjustable via onboard trimmer on real hardware) |
| GND | Ground |
| VCC | Power (5V) |
Attributes
This component has no configurable attributes.
Usage
Connect VCC to 5V, GND to GND, and either AOUT to an analog input pin for a continuous reading, or DOUT to a digital input pin for a simple threshold alarm.
const int GAS_ANALOG_PIN = A0;
const int GAS_DIGITAL_PIN = 2;
void setup() {
pinMode(GAS_DIGITAL_PIN, INPUT);
Serial.begin(9600);
}
void loop() {
int level = analogRead(GAS_ANALOG_PIN);
bool alarm = digitalRead(GAS_DIGITAL_PIN) == HIGH;
Serial.print("Level: "); Serial.print(level);
Serial.print(" Alarm: "); Serial.println(alarm ? "YES" : "no");
delay(300);
}
Real MQ sensors need several minutes to warm up before readings stabilize — the simulator model skips this warm-up period.
Examples
| Description | Attrs |
|---|---|
| Default gas sensor | {} |
See also
- Flame Sensor — same analog/digital pin pattern for fire detection
- Photoresistor — same analog/digital pin pattern for light