first commit
This commit is contained in:
parent
fe5d76ff29
commit
205cf8811a
|
@ -0,0 +1,37 @@
|
|||
#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Ω)
|
||||
|
||||
MQ135 gasSensor(MQ135_PIN);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
delay(1000); // Beri waktu untuk serial monitor
|
||||
|
||||
Serial.println("Kalibrasi awal sensor MQ135...");
|
||||
|
||||
float R0 = getRZero();
|
||||
Serial.print("Nilai R0: ");
|
||||
Serial.println(R0);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// Tidak ada yang perlu dilakukan dalam loop untuk kalibrasi
|
||||
}
|
||||
|
||||
float getRZero() {
|
||||
const int numReadings = 50;
|
||||
float Rs = 0.0;
|
||||
|
||||
for (int i = 0; i < numReadings; i++) {
|
||||
Rs += analogRead(MQ135_PIN);
|
||||
delay(100);
|
||||
}
|
||||
|
||||
Rs /= numReadings;
|
||||
float R0 = Rs / (1023.0 - Rs) * RLOAD;
|
||||
|
||||
return R0;
|
||||
}
|
Loading…
Reference in New Issue