Advertisement
EnemyBorat

Temp/Humidty/LED/LCD

Nov 18th, 2017
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.56 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2. #include <Adafruit_Sensor.h>
  3. #include <DHT.h>
  4.  
  5. #define DHTPIN A0     // what pin we're connected to
  6. #define DHTTYPE DHT11   // we are using the DHT11 sensor
  7. #define Blue_LED 8 //Blue LED on pin 8
  8. #define Red_LED 7  //Red LED on pin 7
  9.  
  10. LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  11.  
  12. DHT dht(DHTPIN, DHTTYPE);
  13.  
  14. void setup()
  15. {
  16.   Serial.begin(9600);
  17.    
  18.  {
  19.   pinMode(Blue_LED, OUTPUT);
  20.   pinMode(Red_LED, OUTPUT);
  21.  }
  22.   lcd.begin(16,2);  //16 by 2 character display
  23.  
  24. dht.begin();
  25. }
  26.  
  27. void loop()
  28. {
  29.   delay(1000);
  30.   // Reading temperature or humidity takes about 250 milliseconds!
  31.  
  32.   float h = dht.readHumidity();  //retrieve humidity data from sensor
  33.   float t = dht.readTemperature(true);  // Retrieve Temperature data from sensor and convert to Farenheite (true)
  34.  
  35.   lcd.clear();
  36.   lcd.setCursor(0,0);
  37.   lcd.print("Temp: ");
  38.   lcd.print(t);  //print temperarture data to the LCD display
  39.   lcd.print("F");  //print F for Farenheite after the temperature
  40.  
  41.   lcd.setCursor(0,1);
  42.   lcd.print("Hum : ");
  43.   lcd.print(h);  //print humidity data to the LCD display
  44.   lcd.print("%");  //print % after the humidity level
  45.  
  46.  
  47. //the 2-led setup process
  48.  if (t < 70)
  49.   {
  50.   digitalWrite(Blue_LED, HIGH); //If temperature is less than 70 turn on BLUE LED
  51.   digitalWrite(Red_LED, LOW);  //If temperature is less than 70 turn off Red LED
  52.  
  53.   }
  54.   else if (t > 70)
  55.   {
  56.   digitalWrite(Blue_LED, LOW); //If temperature is less than 70 turn off BLUE LED
  57.   digitalWrite(Red_LED, HIGH); //If temperature is less than 70 turn on Red LED
  58.   }
  59.  
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement