Guest User

Untitled

a guest
Nov 24th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. /*
  2.  
  3. HUERTO DIGITAL
  4.  
  5. - TEMPERATURE SENSOR
  6. - HUMIDITY SENSOR
  7. - LIGHT SENSOR
  8. - LCD
  9. - LEDS
  10.  
  11. */
  12.  
  13. #include "DHT.h"
  14. #define DHTPIN 8
  15. #define DHTTYPE DHT11
  16. DHT dht(DHTPIN, DHTTYPE);
  17.  
  18. #include <LiquidCrystal.h>
  19. LiquidCrystal lcd(7,6,5,4,3,2);
  20.  
  21. const int lightPin = 1;
  22. const int tempPin = 0;
  23.  
  24. // int buzzerPin = 9;
  25. int lightLevel;
  26.  
  27. void setup(){
  28. Serial.begin(9600); // bound rate
  29. Serial.println("Medidas para nuestras plantitas!");
  30.  
  31. pinMode(10, OUTPUT); // LEDs amarillos
  32. pinMode(11, OUTPUT); // LEDs rojos
  33. pinMode(9, OUTPUT); // LED azul para la luminosidad
  34.  
  35. dht.begin();
  36.  
  37. lcd.begin(16, 2); // activamos todos los cuadros del LCD
  38. lcd.clear(); // lo reseteamos cada vez que iniciemos la máquina
  39. lcd.print("TEMP");
  40. lcd.setCursor(3,1);
  41. lcd.print("C");
  42. // lcd.setCursor(14,1);
  43. // lcd.print("F");
  44. lcd.setCursor(6,0);
  45. lcd.print("HUM");
  46. lcd.setCursor(9,1);
  47. lcd.print("%");
  48. lcd.setCursor(11,0);
  49. lcd.print("LUM");
  50. lcd.setCursor(14,1);
  51. lcd.print("%");
  52. }
  53.  
  54.  
  55. void loop(){
  56. delay(2000); // tiempo entre medidas (2s)
  57.  
  58. lightLevel = analogRead(lightPin);
  59. manualTune();
  60. analogWrite(9, 255-lightLevel);
  61.  
  62. int h = dht.readHumidity();
  63. int t = dht.readTemperature(); // en Celsius
  64. float f = dht.readTemperature(true); // en Fahrenheits (isFahrenheit = true)
  65. // Check if any reads failed and exit early (to try again).
  66. if (isnan(h) || isnan(t) || isnan(f)) {
  67. Serial.println("Failed to read from DHT sensor!");
  68. return;
  69. }
  70. float hif = dht.computeHeatIndex(f, h); // índice de calor
  71. float hic = dht.computeHeatIndex(t, h, false); // en Fahreheits (isFahreheit = false)
  72.  
  73. Serial.print("Humidity: ");
  74. Serial.print(h);
  75. Serial.print(" % ");
  76. Serial.print("Temperature: ");
  77. Serial.print(t);
  78. Serial.print(" C ");
  79. Serial.print(f);
  80. Serial.print(" F ");
  81. Serial.print("Heat index: ");
  82. Serial.print(hic);
  83. Serial.print(" *C ");
  84. Serial.print(hif);
  85. Serial.print(" *F ");
  86. Serial.print(" Luminosity: ");
  87. Serial.print(lightLevel*100/255);
  88. Serial.println(" %");
  89.  
  90. lcd.setCursor(1,1);
  91. lcd.print(t); // saco por el LCD la temp en ºC
  92. lcd.setCursor(7,1);
  93. lcd.print(h);
  94. lcd.setCursor(12,1);
  95. lcd.print(int(lightLevel*100/255));
  96.  
  97. if(t >= 27){
  98. digitalWrite(10, HIGH); // enciendo los LEDs amarillos
  99. }
  100. if(t >= 30){
  101. digitalWrite(11, HIGH); // enciendo los LEDs rojos
  102. }
  103. if(t < 30){
  104. digitalWrite(11, LOW); // apago los LEDs rojos
  105. }
  106. if(t < 27){
  107. digitalWrite(10, LOW); // apago los LEDs amarillos
  108. }
  109. }
  110.  
  111.  
  112. // Regulamos la luz manualmente
  113. void manualTune(){
  114. // void autoTune()
  115. // if (lightLevel < low){
  116. // low = lightLevel;
  117. // }
  118. // if (lightLevel > high){
  119. // high = lightLevel;
  120. // }
  121. // lightLevel = map(lightLevel, low+30, high-30, 0, 255);
  122. // lightLevel = constrain(lightLevel, 0, 255);
  123. lightLevel = map(lightLevel, 200, 1023, 0, 255);
  124. lightLevel = constrain(lightLevel, 0, 255);
  125. }
Add Comment
Please, Sign In to add comment