//#include <OneWire.h>
//#include <DallasTemperature.h>
//const float BETA = 3950; // should match the Beta Coefficient of the thermistor
//#define heater 13
//#define sensors A0
//#define suhu A0
//#define ONE_WIRE_BUS sensords
//OneWire oneWire(ONE_WIRE_BUS);
//DallasTemperature sensors(&oneWire);
//void setup(void)/
//{
// start serial port
//Serial.begin(9600);
//Serial.begin(115200);
//Serial.println("Wemos + DS18b20 + fan");
//pinMode (heater, OUTPUT);
//digitalWrite (heater, HIGH);
//delay (2000);
//digitalWrite (heater, LOW);
//sensors.begin();
//}
//void loop()
//void loop(void)
//{
// ceksuhu();
//}
//void ceksuhu(){
//int analogValue = analogRead(A0);
//float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
//Serial.print("Temperature: ");
//Serial.print(celsius);
//Serial.println(" ℃");
//delay(1000);
//Serial.print("Requesting temperatures...");
//sensors.requestTemperatures(); // Send the command to get temperatures
//Serial.println("DONE");
//float suhu=sensors.getTempCByIndex(0);
//Serial.print("Suhu: ");
//Serial.println(suhu);
//if (suhu>32) digitalWrite (fan,HIGH);
//if (suhu<29) digitalWrite (fan,LOW);
//if (suhu > 32){
//Serial.print("heater mati (");
//digitalWrite(heater, LOW);
//}
//else {
//Serial.print("heater nyala(");
// digitalWrite(heater, HIGH);
//}
//}
const float BETA = 3950; // should match the Beta Coefficient of the thermistor
#define heater 13
const int sensor = A0;
int tempc;
float tempf;
float vout;
float adc;
void setup() {
Serial.begin(9600);
Serial.println("https://mahirelektro.com");
Serial.println("Tutorial Arduino: Mengakses sensor suhu LM35");
Serial.println(" ");
pinMode(sensor, INPUT);
delay(800);
pinMode (heater, OUTPUT);
digitalWrite (heater, HIGH);
delay (2000);
digitalWrite (heater, LOW);
}
void loop() {
int analogValue = analogRead(A0);
float celsius = 1 / (log(1 / (1023. / analogValue - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println(" ℃");
delay(1000);
if (sensor < 32){
Serial.print("heater mati (");
digitalWrite(heater, LOW);
}
else {
Serial.print("heater nyala(");
digitalWrite(heater, HIGH);
}
}