//Pembuat Program
// Nama : Fuad Satriyaji
// NIM : 20200130160
// Kelas : E
#include "DHT.h" // Library untuk sensor DHT
#define dhtPin 12 // data pin
//#define dhtType DHT11 // tipe sensor: DHT 11
#define dhtType DHT22 // DHT 22 (AM2302), AM2321
//#define dhtType DHT21 // DHT 21 (AM2301)
DHT dht(dhtPin, dhtType); // Initialise the DHT library
float humidityVal; // humidity %
float tempValC; // temperature in degrees Celcius
void setup() {
Serial.begin(9600); // Initialise the serial monitor
dht.begin(); // start with reading the DHT sensor
pinMode(4, OUTPUT);
}
void loop() {
humidityVal = dht.readHumidity(); // humidity
tempValC = dht.readTemperature(); // temperatur Celcius
if(tempValC <60 ){ //pengatur led
digitalWrite(4, HIGH);
}
else{
digitalWrite(4, LOW);
}
// Print all values to the serial monitor, \t prints a tab character
Serial.print("Humidity: ");
Serial.print(humidityVal);
Serial.print(" %\t");
Serial.print("Temperature: ");
Serial.print(tempValC);
Serial.println(" °C ");
delay(2000);
}