LPG Gas Measurement with the MQ-5 (PPM)
Intermediate30 minA project that reads the MQ-5 gas sensor's analog output, turns it first into a voltage and then into the ratio of the sensor's resistance to its resistance in clean air (Rs/Ro), and writes an estimated LPG concentration (PPM), worked out with the datasheet curve formula, to the Serial Monitor every two seconds. At start-up it waits 10 seconds for the heater to settle. In clean air the ratio is high and the PPM low; with gas around, the ADC and PPM values rise clearly. The PPM value is an estimate: for an accurate result, calibrate the sensor in clean air and update the Ro value. No extra library needed.
Build it step by step in the appWhat you need
1 × Arduino Uno R3
1 × MQ-5 LPG / Natural Gas Sensor
4 × Jumper Wire - Male/Female
Wiring steps
- 1
Power the sensor

Plug a red jumper wire into the 5V pin on the Arduino's POWER header. Connect its other end to the top pin, pin 1 (VCC), in the MQ-5 module's pin row. The sensor's heater runs on 5V and gets warm while it runs.
- 2
Ground (GND) connection

Plug a black jumper wire into the GND pin on the Arduino's POWER header. Connect its other end to the module's pin 2 (GND).
- 3
Connect the digital output (DOUT)

Plug a blue jumper wire into the Arduino's digital pin 2. Connect its other end to the module's pin 3 (DOUT). This pin changes state when the gas level crosses the threshold set with the trimmer on the board. The code in this project only uses the analog output; this connection is there in case you want to add a threshold alarm.
- 4
Connect the analog output (AOUT)

Plug a green jumper wire into pin A0 on the Arduino's ANALOG IN header. Connect its other end to the module's bottom pin, pin 4 (AOUT). The code reads the gas concentration on this pin as a value from 0 to 1023 and works out the PPM from it (sensorPin = A0).
Arduino sketch
const int sensorPin = A0;
// Sensör modülünün arkasındaki SMD direncin değeri (Genelde 1k ile 10k Ohm arasıdır)
const float RL = 10.0;
// Temiz havadaki sensör direnci (Bu değeri gerçekte kalibrasyon koduyla bulman gerekir, örnek olarak 9.83 verilmiştir)
const float Ro = 9.83;
// MQ-2 datasheet'indeki logaritmik grafikten çıkarılmış LPG eğri eğimi ve kesişim noktası
const float m = -0.473;
const float b = 1.413;
void setup() {
Serial.begin(9600);
Serial.println("Sensor isiniyor, lutfen bekleyin...");
delay(10000); // Sensörün içindeki ısıtıcının stabil hale gelmesi için süre
}
void loop() {
int adc_value = analogRead(sensorPin);
// 1. Adım: 0-1023 arası ADC değerini 0-5V arası voltaja çevir
float voltaj = adc_value * (5.0 / 1023.0);
// Sıfıra bölme hatasını engellemek için güvenlik kontrolü
if (voltaj == 0) {
Serial.println("Sensörden veri okunamiyor veya baglanti hatali.");
delay(2000);
return;
}
// 2. Adım: Sensörün o anki direncini (Rs) hesapla formül: Rs = RL * (5V - Voltaj) / Voltaj
float Rs = RL * (5.0 - voltaj) / voltaj;
// 3. Adım: Rs / Ro oranını bul
float oran = Rs / Ro;
// 4. Adım: Datasheet'teki log-log grafiği formülüne göre PPM'i hesapla
// Formül: ppm = 10 ^ ((log10(Rs/Ro) - b) / m)
float ppm = pow(10, ((log10(oran) - b) / m));
// Çıktıyı yazdır
Serial.print("Ham ADC: ");
Serial.print(adc_value);
Serial.print(" | Voltaj: ");
Serial.print(voltaj, 2);
Serial.print("V | Rs/Ro Orani: ");
Serial.print(oran, 2);
Serial.print(" | Tahmini PPM: ");
Serial.println(ppm, 2);
delay(2000); // 2 saniyede bir ölçüm al
}
What the Serial Monitor shows
Sensor isiniyor, lutfen bekleyin... Ham ADC: 145 | Voltaj: 0.71V | Rs/Ro Orani: 6.15 | Tahmini PPM: 21.34 Ham ADC: 148 | Voltaj: 0.72V | Rs/Ro Orani: 6.04 | Tahmini PPM: 22.18 Ham ADC: 152 | Voltaj: 0.74V | Rs/Ro Orani: 5.86 | Tahmini PPM: 23.50 Ham ADC: 410 | Voltaj: 2.00V | Rs/Ro Orani: 1.53 | Tahmini PPM: 456.82 Ham ADC: 435 | Voltaj: 2.13V | Rs/Ro Orani: 1.37 | Tahmini PPM: 580.14
If a wire is loose
Sensörden veri okunamiyor veya baglanti hatali.
In the app, tick off every wire, match the parts to your inventory and pick up where you left off.
Build it step by step in the app