You are on page 1of 2

Write a program for Arduino UNO to read analog temperature and humidity data using

analog read and there is a R-G-B LED as output device. When the temperature value is less
that 50º C and humidity is less than 50% the Green LED should glow. When the
temperature is in between 50 º C to 100º C and humidity is above 75% blue LED should
glow. When the temperature is above 100º C and humidity is above 90% red LED should
glow. If none of these three condition satisfies no LED should glow.

Code:

#include<dht.h>
dht DHT;
float temp;
float hum;
int GREEN=0;
int BLUE=0;
int RED=0;

// if you require to change the pin number, Edit the pin with your
arduino pin.
#define DHT11_PIN 3
void setup()
{
Serial.begin(9600);
Serial.println("welcome to TechPonder Humidity and temperature
Detector");
pinMode(2, OUTPUT); // GREEN LED Connected to D2
pinMode(3, OUTPUT); // BLUE LED Connected to D3
pinMode(4, OUTPUT); // RED LED Connected to D4
}

void loop()
{ // READ DATA
int chk = DHT.read11(DHT11_PIN);
Serial.println(" Humidity " );
Serial.println(DHT.humidity, 1);
Serial.println(" Temparature ");
Serial.println(DHT.temperature, 1);
temp= DHT.humidity;
hum= DHT.temperature;

if(temp<50 && hum <50)


{
GREEN=1;
}
elseif(temp >=50 && temp <100 && hum >75 )
{
GREEN=0;
BLUE=1;
}
elseif(temp > 100 && hum > 90)
{
BLUE=0;
RED=1;
}
else()
{
GREEN=0;
BLUE=0;
RED=0;
}
digitalOut(2,GREEN);
digitalOut(3,BLUE);
digitalOut(4,RED);

delay(2000);
}

You might also like