const int LM35Pin = 35; // Pin analog ESP32 yang terhubung ke sensor LM35
const int numReadings = 10; // Jumlah pembacaan yang akan digunakan untuk moving average
int readings[numReadings]; // Array untuk menyimpan pembacaan
int readingIndex = 0; // Indeks saat ini dalam array readings
int total = 0; // Total pembacaan untuk perhitungan moving average
float Pt_prev, R, Q;
void setup() {
Serial.begin(9600);
pinMode(LM35Pin, INPUT);
analogReadResolution(12); // Resolusi ADC 12-bit
R=0;
Q=0.05;
Pt_prev=1;
for (int i = 0; i < numReadings; i++) {
readings[i] = 0;
}
}
void loop() {
// get the ADC value from the temperature sensor
int sensorValue = analogRead(LM35Pin);
// Ubah nilai bacaan menjadi suhu dalam derajat Celsius
float temperatureC = (sensorValue / 4095.0) * 330.0;
// print the temperature TANPA FILTER in the Serial Monitor:
Serial.print("Temperature: ");
Serial.print(temperatureC); // print the temperature in Celsius
Serial.print("°C");
Serial.println(" ~ ");
delay(1000);
}