//TUGAS 3
#include <OneWire.h>
#include <DallasTemperature.h>
#include "DHT.h"
//define DHT22
#define DHTPIN 33
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//LM35
#define ADC_VREF_mV 5000.0 // in millivolt
#define ADC_RESOLUTION 1024
#define PIN_LM35 34
//DS18B20
OneWire oneWire(35);
DallasTemperature sensor(&oneWire);
//DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
dht.begin();
}
void loop() {
//LM35
// get the ADC value from the temperature sensor
int adcVal = analogRead(PIN_LM35);
// convert the ADC value to voltage in millivolt
float milliVolt = adcVal * (ADC_VREF_mV / ADC_RESOLUTION);
// convert the voltage to the temperature in Celsius
float tempC = milliVolt / 10;
// convert the Celsius to Fahrenheit
float tempF = tempC * 9 / 5 + 32;
// print the temperature in the Serial Monitor:
Serial.print("Suhu dalam komponen LM35 : ");
Serial.print(tempC); // print the temperature in Celsius
Serial.print("°C");
Serial.print(" ~ "); // separator between Celsius and Fahrenheit
Serial.print(tempF); // print the temperature in Fahrenheit
Serial.println("°F");
//DS18B20
sensor.requestTemperatures();
Serial.print("Suhu dalam komponen DS18B20 : ");
Serial.print(sensor.getTempCByIndex(0));
Serial.println("°C");
//DHT22
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// Check if any reads failed and exit early (to try again).
if (isnan(temperature) || isnan(humidity)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(F("Suhu dalam komponen DHT22 : "));
Serial.print(temperature);
Serial.print(F("°C Kelembaban: "));
Serial.print(humidity);
Serial.println("%");
Serial.println();
delay(1000);
}