0% found this document useful (0 votes)
16 views

Coding Humidity Lampu

This Arduino code uses a DHT11 temperature and humidity sensor to monitor temperature. It defines pin connections for the sensor and a relay connected to a fan. The code reads the temperature and humidity values, and will turn the fan on via the relay if the temperature exceeds the defined upper threshold or falls below the lower threshold.

Uploaded by

mdnabil209
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Coding Humidity Lampu

This Arduino code uses a DHT11 temperature and humidity sensor to monitor temperature. It defines pin connections for the sensor and a relay connected to a fan. The code reads the temperature and humidity values, and will turn the fan on via the relay if the temperature exceeds the defined upper threshold or falls below the lower threshold.

Uploaded by

mdnabil209
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include "DHT.

h"

#define RELAY_FAN_PIN A5 // Arduino pin connected to relay which connected to fan

#define DHTPIN 12 // Arduino pin connected to relay which connected to DHT sensor

#define DHTTYPE DHT11

const int TEMP_THRESHOLD_UPPER = 25; // upper threshold of temperature, change to your desire
value

const int TEMP_THRESHOLD_LOWER = 20; // lower threshold of temperature, change to your desire
value

DHT dht(DHTPIN, DHTTYPE);

float temperature; // temperature in Celsius

void setup()

Serial.begin(9600); // initialize serial

dht.begin(); // initialize the sensor

pinMode(RELAY_FAN_PIN, OUTPUT); // initialize digital pin as an output

void loop()

// wait a few seconds between measurements.

delay(2000);

// read humidity

float humi = dht.readHumidity();

// read temperature as Celsius

float tempC = dht.readTemperature();

// read temperature as Fahrenheit


float tempF = dht.readTemperature(true);

// check if any reads failed

if (isnan(humi) || isnan(tempC) || isnan(tempF)) {

Serial.println("Failed to read from DHT sensor!");

} else {

Serial.print("Humidity: ");

Serial.print(humi);

Serial.print("%");

Serial.print(" | ");

Serial.print("Temperature: ");

Serial.print(tempC);

Serial.print("°C ~ ");

Serial.print(tempF);

Serial.println("°F");

You might also like