/* LABORATORY 3 TASK 3: RGB LED based on DHT Sensor with LCD Display on Arduino UNO
CODED BY: Najito, Czarlean Grace D.
The goal of this program is to display LEDhVal and Temperature in Celsius and Fahrenheit.
The RGB LED will change as the temperature changes.
INSTRUCTIONS:
- Upon clicking the Start Simulation button, will State a comment the feelings of the programmer
while making this program .
- After that sequence it will loop to display the readings of the DHT sensor in terms of LEDhVal,
Celsius and Farenheit
- As the temperature change the RGB LED will change #*/
//Library Setup integrity of the program
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
#define Type DHT22
//pins placement and assignment
//Seting up the pair of RGB LED pins
int r1LED=3,g1LED=5,b1LED=6,r2LED=11,g2LED=10,b2LED=9;
//Setting up DHT22 Sensor pin
int DHPin=2;
DHT DH(DHPin,Type);
//Variables
float h; // LEDhVal
float c; // celcius
float f; // farenheit
String period;
float readVal;
float read1Val;
float read2Val;
float read3Val;
float read4Val;
float read5Val;
float LEDhVal;
float LEDtVal;
float LEDfVal;
float Red1Val;
//delays Time is =
int t=50;
int t1=500;
int t2=1000;
int t3=2500;
int t4=3000;
// setting up LCD 2IC
LiquidCrystal_I2C lcd(0x27, 20, 4);
void setup() {
Serial.begin(9600);
DH.begin();
lcd.begin(20,4);
lcd.backlight();
// Setting up the functions of the vareiables that are assigned
pinMode(r1LED,OUTPUT);
pinMode(g1LED,OUTPUT);
pinMode(b1LED,OUTPUT);
pinMode(r2LED,OUTPUT);
pinMode(g2LED,OUTPUT);
pinMode(b2LED,OUTPUT);
}
void loop() {
// for formula I used "value divided by total value then multiply by 255 as used as analog Write "
// analog LED pair 1
//I used ratio and proportion
h=DH.readHumidity(); // as the reading for LEDhVal
c=DH.readTemperature(); // as the reading for Celsius
f=DH.readTemperature(true); // as the reading for farenheit
//Setting up display placement
lcd.setCursor(1,0);
//printing what is intended
lcd.print("Hello!!");
lcd.setCursor(1,2);
lcd.print("Napalaban sa Coding");
lcd.setCursor(1,3);
lcd.print("are!! Tingnan Natin");
delay(t2);
lcd.clear();
lcd.setCursor(5,2);
lcd.print("DHT Readings");
delay(t2);
lcd.clear();
//Title
lcd.setCursor(3,0);
lcd.print("DHT READINGS");
//h relation to LED
LEDhVal=h;
lcd.setCursor(0,1);
lcd.print("Humidity =");
lcd.print(h);
lcd.print((char)223);
Serial.print("Humidity = ");
Serial.println(LEDhVal);
delay(t2);
//t relation to LED
LEDtVal=c;
lcd.setCursor(0,2);
lcd.print("Celsius=");
lcd.print(c);
lcd.print((char)223),lcd.print("C");
Serial.print("Celsius= ");
Serial.println(LEDtVal);
delay(t2);
//f values LEDfVal=c;
LEDfVal=f;
lcd.setCursor(0,3);
lcd.print("Farenheit = ");
lcd.print(f);
lcd.print((char)223),lcd.print("F");
LEDfVal=f;
Serial.print("Farenheit= ");
Serial.println(LEDfVal);
delay(t2);
lcd.clear();
if (LEDhVal<=10 )
{
analogWrite(r1LED,0);
analogWrite(g1LED, 0);
analogWrite(b1LED, 255);
}
else if (LEDhVal>10 && LEDhVal<=20)
{
analogWrite(r1LED,0);
analogWrite(g1LED, 255);
analogWrite(b1LED, 255);
}
else if (LEDhVal>20 && LEDhVal<=30)
{
analogWrite(r1LED,138);
analogWrite(g1LED, 170);
analogWrite(b1LED, 255);
}
else if (LEDhVal>30 && LEDhVal<=40)
{
analogWrite(r1LED,13);
analogWrite(g1LED, 255);
analogWrite(b1LED, 150);
}
else if (LEDhVal>40 && LEDhVal<=50)
{
analogWrite(r1LED,0);
analogWrite(g1LED, 255);
analogWrite(b1LED, 0);
}
else if (LEDhVal>50 && LEDhVal<=60)
{
analogWrite(r1LED,120);
analogWrite(g1LED, 255);
analogWrite(b1LED, 51);
}
else if (LEDhVal>60 && LEDhVal<=70)
{
analogWrite(r1LED,255);
analogWrite(g1LED, 255);
analogWrite(b1LED, 0);
}
else if (LEDhVal>70 && LEDhVal<=80)
{
analogWrite(r1LED,255);
analogWrite(g1LED, 127);
analogWrite(b1LED, 0);
}
else if (LEDhVal>80 && LEDhVal<=90)
{
analogWrite(r1LED,255);
analogWrite(g1LED, 0);
analogWrite(b1LED, 255);
}
else if (LEDhVal>90 && LEDhVal<=100)
{
analogWrite(r1LED,255);
analogWrite(g1LED, 0);
analogWrite(b1LED, 0);
}
//Temp RGB
if (LEDtVal<=-28)
{
analogWrite(r2LED,0);
analogWrite(g2LED, 0);
analogWrite(b2LED, 255);
}
else if (LEDtVal>-28 && LEDtVal<=-16)
{
analogWrite(r2LED,0);
analogWrite(g2LED, 255);
analogWrite(b2LED, 255);
}
else if (LEDtVal>-16 && LEDtVal<=-4)
{
analogWrite(r2LED,138);
analogWrite(g2LED, 170);
analogWrite(b2LED, 255);
}
else if (LEDtVal>-4 && LEDtVal<=8)
{
analogWrite(r2LED,13);
analogWrite(g2LED, 255);
analogWrite(b2LED, 150);
}
else if (LEDtVal>8 && LEDtVal<=20)
{
analogWrite(r2LED,0);
analogWrite(g2LED, 255);
analogWrite(b2LED, 0);
}
else if (LEDtVal>20 && LEDtVal<=32)
{
analogWrite(r2LED,120);
analogWrite(g2LED, 255);
analogWrite(b2LED, 51);
}
else if (LEDtVal>32 && LEDtVal<=44)
{
analogWrite(r2LED,255);
analogWrite(g2LED, 255);
analogWrite(b2LED, 0);
}
else if (LEDtVal>44 && LEDtVal<=56)
{
analogWrite(r2LED,255);
analogWrite(g2LED, 127);
analogWrite(b2LED, 0);
}
else if (LEDtVal>56 && LEDtVal<=68)
{
analogWrite(r2LED,255);
analogWrite(g2LED, 0);
analogWrite(b2LED, 255);
}
else if (LEDtVal>68 && LEDtVal<=80)
{
analogWrite(r2LED,255);
analogWrite(g2LED, 0);
analogWrite(b2LED, 0);
}
}