Guest User

Untitled

a guest
Dec 14th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. //For the screen
  2. #include <Wire.h>
  3. #include <LiquidCrystal_I2C.h>
  4. LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); // Set the LCD I2C address
  5. //For the sensor
  6. #include <dht.h>
  7. dht DHT;
  8. #define DHT11_PIN 7
  9.  
  10. int ledBlue = 4;
  11. int ledRed = 5;
  12. int ledYell = 8;
  13. int ledGreen = 9;
  14.  
  15.  
  16. void setup()
  17. {
  18.  
  19. pinMode(ledBlue, OUTPUT);
  20. pinMode(ledRed, OUTPUT);
  21. pinMode(ledYell, OUTPUT);
  22. pinMode(ledGreen, OUTPUT);
  23.  
  24.  
  25.  
  26. Serial.begin(9600);
  27.  
  28. lcd.begin(16,2);
  29.  
  30. for(int i = 0; i< 3; i++)
  31. {
  32. lcd.backlight();
  33. delay(150);
  34. lcd.noBacklight();
  35. delay(150);
  36. }
  37. lcd.backlight();
  38.  
  39.  
  40. lcd.setCursor(0,0);
  41. lcd.print(" Lets see ");
  42. delay(1000);
  43. lcd.setCursor(0,1);
  44. lcd.print(" the weather! ");
  45. delay(3000);
  46.  
  47. lcd.clear();
  48. lcd.setCursor(0,0);
  49. lcd.print("By Calvin Hobs");
  50. delay(1000);
  51. lcd.setCursor(0,1);
  52. lcd.print("& John Rand");
  53. delay(2000);
  54. }
  55.  
  56.  
  57. void loop()
  58. {
  59. int chk = DHT.read11(DHT11_PIN);
  60. Serial.print("Temperature = ");
  61. Serial.println(DHT.temperature);
  62. Serial.print("Humidity = ");
  63. Serial.println(DHT.humidity);
  64. delay(1000);
  65.  
  66. double f = ((DHT.temperature * 1.8) + 32);
  67. lcd.clear();
  68. lcd.setCursor(0,0);
  69. lcd.print("Temp: ");
  70. lcd.print(f);
  71. lcd.print((char)223);
  72. lcd.print("F");
  73.  
  74.  
  75. lcd.setCursor(0,1);
  76. lcd.print("Humidity: ");
  77. lcd.print(DHT.humidity);
  78.  
  79. if(f > 50){
  80. digitalWrite(ledBlue, LOW);
  81. digitalWrite(ledRed, HIGH);
  82. }
  83. else{
  84. digitalWrite(ledRed, LOW);
  85. digitalWrite(ledBlue, HIGH);
  86. }
  87.  
  88. if(DHT.humidity > 25){
  89. digitalWrite(ledYell, LOW);
  90. digitalWrite(ledGreen, HIGH);
  91. }
  92. else{
  93. digitalWrite(ledGreen, LOW);
  94. digitalWrite(ledYell, HIGH);
  95. }
  96. {
  97. if (Serial.available()) {
  98. delay(100);
  99. lcd.clear();
  100. while (Serial.available() > 0) {
  101. lcd.write(Serial.read());
  102. }
  103. }
  104. }
  105.  
  106. }
Add Comment
Please, Sign In to add comment