// Tugas UTS
// Almas Gilang Ramadhan
// 21410300489
#include <DHT.h>
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
// Membaca data dari sensor DHT22
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// Menampilkan data di Serial Monitor
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C, Humidity: ");
Serial.print(humidity);
Serial.println(" %");
// Menghitung slope (kemiringan) dan intercept (konstanta)
float x[] = {230,1446,2786,3800,4540,6320,7546,9170,11875,13089,13218,15809,17532,17988,19475};
float y[] = {5,35,45,65,85,105,135,158,195,228,287,291,305,325,345};
int n = sizeof(x) / sizeof(x[0]);
float sumX = 0, sumY = 0, sumXY = 0, sumX2 = 0;
for (int i = 0; i < n; i++) {
sumX += x[i];
sumY += y[i];
sumXY += x[i] * y[i];
sumX2 += x[i] * x[i];
}
float slope = (n * sumXY - sumX * sumY) / (n * sumX2 - sumX * sumX);
float intercept = (sumY - slope * sumX) / n;
// Menampilkan hasil regresi linier
Serial.print("Slope: ");
Serial.print(slope);
Serial.print(", Intercept: ");
Serial.println(intercept);
delay(2000);
}