Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- #include <Adafruit_Sensor.h>
- #include <DHT.h>
- #define DHTPIN A0 // what pin we're connected to
- #define DHTTYPE DHT11 // we are using the DHT11 sensor
- #define Blue_LED 8 //Blue LED on pin 8
- #define Red_LED 7 //Red LED on pin 7
- LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
- DHT dht(DHTPIN, DHTTYPE);
- void setup()
- {
- Serial.begin(9600);
- {
- pinMode(Blue_LED, OUTPUT);
- pinMode(Red_LED, OUTPUT);
- }
- lcd.begin(16,2); //16 by 2 character display
- dht.begin();
- }
- void loop()
- {
- delay(1000);
- // Reading temperature or humidity takes about 250 milliseconds!
- float h = dht.readHumidity(); //retrieve humidity data from sensor
- float t = dht.readTemperature(true); // Retrieve Temperature data from sensor and convert to Farenheite (true)
- lcd.clear();
- lcd.setCursor(0,0);
- lcd.print("Temp: ");
- lcd.print(t); //print temperarture data to the LCD display
- lcd.print("F"); //print F for Farenheite after the temperature
- lcd.setCursor(0,1);
- lcd.print("Hum : ");
- lcd.print(h); //print humidity data to the LCD display
- lcd.print("%"); //print % after the humidity level
- //the 2-led setup process
- if (t < 70)
- {
- digitalWrite(Blue_LED, HIGH); //If temperature is less than 70 turn on BLUE LED
- digitalWrite(Red_LED, LOW); //If temperature is less than 70 turn off Red LED
- }
- else if (t > 70)
- {
- digitalWrite(Blue_LED, LOW); //If temperature is less than 70 turn off BLUE LED
- digitalWrite(Red_LED, HIGH); //If temperature is less than 70 turn on Red LED
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement