first commit
This commit is contained in:
parent
9a1aabda21
commit
fe5d76ff29
|
@ -0,0 +1,32 @@
|
|||
#include <Arduino.h>
|
||||
#include "MQ135.h"
|
||||
|
||||
#define MQ135_PIN A0 // Pin analog yang digunakan untuk sensor MQ135
|
||||
#define RLOAD 10.0 // Nilai resistansi beban (10kΩ)
|
||||
#define VCC 5.0 // Tegangan referensi (dalam volt)
|
||||
|
||||
MQ135 gasSensor(MQ135_PIN);
|
||||
float R0 = 0.41; // Nilai R0 yang telah dikalibrasi, sesuaikan dengan hasil kalibrasi Anda
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(1000); // Beri waktu untuk serial monitor
|
||||
|
||||
Serial.println("Program dimulai...");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Baca nilai resistansi sensor (Rs)
|
||||
int sensorValue = analogRead(MQ135_PIN);
|
||||
float voltage = sensorValue * (VCC / 1023.0); // Konversi nilai bacaan analog ke tegangan (dalam volt)
|
||||
float Rs = (VCC - voltage) / voltage * RLOAD;
|
||||
|
||||
// Hitung PPM menggunakan rumus yang sesuai
|
||||
float PPM = pow(10, ((log10(Rs / R0) - 0.12) / -0.27));
|
||||
|
||||
// Tampilkan hasil PPM
|
||||
Serial.print("Nilai PPM: ");
|
||||
Serial.println(PPM);
|
||||
|
||||
delay(1000); // Beri jeda sebelum membaca ulang sensor
|
||||
}
|
Loading…
Reference in New Issue