Advertisement
Guest User

Untitled

a guest
Feb 5th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.82 KB | None | 0 0
  1. #define BLYNK_PRINT Serial
  2.  
  3. #include <SPI.h>
  4. #include <Ethernet.h>
  5. #include <BlynkSimpleEthernet.h>
  6. #include <DHT.h>
  7. #include <Wire.h>
  8. #include <DHT.h>
  9. #include <TimeLib.h>
  10. #include <WidgetRTC.h>
  11.  
  12. char auth[] = "xxxxx";
  13.  
  14. #define W5100_CS 10
  15. #define SDCARD_CS 4
  16. #define DHTPIN 33
  17. #define DHTTYPE DHT11 // DHT 11
  18. BlynkTimer timer;
  19. DHT dht(DHTPIN, DHTTYPE);
  20. WidgetRTC rtc;
  21.  
  22. const int LuzCuarto = 21;
  23. const int BotonCuarto = 22;
  24.  
  25. const int ReflectorPorton = 24;
  26. const int ReflectorTerreno = 26;
  27. const int AperturaPorton = 27;
  28. const int SensorPorton = 25;
  29.  
  30. const int BombaAgua = 30;
  31. const int SensorBombaAgua = 29;
  32. const int ReflectorPatio = 28;
  33. const int SelenoideTanke = 31;
  34. const int BombaPresurizadora = 32;
  35.  
  36. int EstadoLuzCuarto = LOW;
  37. int EstadoBotonCuarto = LOW;
  38.  
  39. int EstadoReflectorPorton = LOW;
  40. int EstadoReflectorTerreno = LOW;
  41. int EstadoAperturaPorton = LOW;
  42. int EstadoSensorPorton = LOW;
  43.  
  44. int EstadoBombaAgua = LOW;
  45. int EstadoSensorBombaAgua = LOW;
  46. int EstadoReflectorPatio = LOW;
  47. int EstadoBombaPresurizadora = LOW;
  48.  
  49. int EstadoSelenoideTanke = HIGH;
  50.  
  51.  
  52. BLYNK_CONNECTED() {
  53. Blynk.syncAll();
  54. }
  55.  
  56. BLYNK_WRITE(V0) {
  57. EstadoLuzCuarto = param.asInt();
  58. digitalWrite(LuzCuarto, EstadoLuzCuarto);
  59. }
  60. BLYNK_WRITE(V3) {
  61. EstadoReflectorPorton = param.asInt();
  62. digitalWrite(ReflectorPorton, EstadoReflectorPorton);
  63. }
  64. BLYNK_WRITE(V4) {
  65. EstadoReflectorTerreno = param.asInt();
  66. digitalWrite(ReflectorTerreno, EstadoReflectorTerreno);
  67. }
  68. BLYNK_WRITE(V5) {
  69. EstadoReflectorPatio = param.asInt();
  70. digitalWrite(ReflectorPatio, EstadoReflectorPatio);
  71. }
  72. BLYNK_WRITE(V6) {
  73. EstadoBombaAgua = param.asInt();
  74. digitalWrite(BombaAgua, EstadoBombaAgua);
  75. }
  76. BLYNK_WRITE(V8) {
  77. EstadoAperturaPorton = param.asInt();
  78. digitalWrite(AperturaPorton, EstadoAperturaPorton);
  79. }
  80. BLYNK_WRITE(V9) {
  81. EstadoSensorBombaAgua = param.asInt();
  82. digitalWrite(BombaAgua, EstadoSensorBombaAgua);
  83. }
  84. BLYNK_WRITE(V10) {
  85. EstadoSelenoideTanke = param.asInt();
  86. digitalWrite(SelenoideTanke, EstadoSelenoideTanke);
  87. }
  88. BLYNK_WRITE(V111) {
  89. EstadoBombaPresurizadora = param.asInt();
  90. digitalWrite(BombaPresurizadora, EstadoBombaPresurizadora);
  91. }
  92.  
  93.  
  94. void checkbotones()
  95. {
  96. if (digitalRead(BotonCuarto) == LOW) {
  97. if (EstadoBotonCuarto != LOW) {
  98. EstadoLuzCuarto = !EstadoLuzCuarto;
  99. digitalWrite(LuzCuarto, EstadoLuzCuarto);
  100. Blynk.virtualWrite(V0, EstadoLuzCuarto);
  101. }
  102. EstadoBotonCuarto = LOW;
  103. } else {
  104. EstadoBotonCuarto = HIGH;
  105. }
  106. }
  107. void portonabierto()
  108. {
  109. if (hour() < 05) {
  110. if (digitalRead(SensorPorton) == LOW) {
  111. if (EstadoSensorPorton != LOW) {
  112. EstadoReflectorPorton = !EstadoReflectorPorton;
  113. digitalWrite(ReflectorPorton, HIGH);
  114. Blynk.virtualWrite(V3, HIGH);
  115. Blynk.notify("Porton Abierto");
  116. }
  117. EstadoSensorPorton = LOW;
  118. } else {
  119. EstadoSensorPorton = HIGH;
  120. digitalWrite(ReflectorPorton, LOW);
  121. Blynk.virtualWrite(V3, LOW);
  122. }
  123. }
  124. }
  125.  
  126. void presurizadora()
  127. {
  128. if (hour() < 14)
  129. {
  130. if (EstadoBombaPresurizadora != HIGH) {
  131. EstadoBombaPresurizadora = !EstadoBombaPresurizadora;
  132. digitalWrite(BombaPresurizadora, EstadoBombaPresurizadora);
  133. Blynk.virtualWrite(V11, EstadoBombaPresurizadora);
  134. digitalWrite(SelenoideTanke, LOW);
  135. Blynk.virtualWrite(V10, SelenoideTanke );
  136. Blynk.notify("Agua Normal");
  137.  
  138. EstadoBombaPresurizadora = HIGH;
  139. } else {
  140. EstadoBombaPresurizadora = LOW;
  141. digitalWrite(BombaPresurizadora, HIGH);
  142. Blynk.notify("Agua Presurizada");
  143. }
  144. }
  145. }
  146.  
  147. void temperaturayhumedad()
  148. {
  149. float h = dht.readHumidity();
  150. float t = dht.readTemperature();
  151. if (isnan(h) || isnan(t)) {
  152. Blynk.notify("Error al enviar SENSONR TEMPERATURA CUARTO KEVIN");
  153. return;
  154. }
  155. Blynk.virtualWrite(V2, h);
  156. Blynk.virtualWrite(V1, t);
  157.  
  158. }
  159. void checkconnect()
  160. {
  161. bool result = Blynk.connected();
  162. if (result == false) {
  163. Blynk.connect();
  164. Blynk.syncAll();
  165. Serial.println("Reconectando");
  166. }
  167. }
  168.  
  169. void setup()
  170. {
  171. Serial.begin(9600);
  172.  
  173. pinMode(SDCARD_CS, OUTPUT);
  174. digitalWrite(SDCARD_CS, HIGH);
  175.  
  176. Blynk.begin(auth, IPAddress(192, 168, 1, 14), 8080);
  177. dht.begin();
  178. rtc.begin();
  179.  
  180. pinMode(LuzCuarto, OUTPUT);
  181. pinMode(ReflectorPorton, OUTPUT);
  182. pinMode(ReflectorTerreno, OUTPUT);
  183. pinMode(BombaAgua, OUTPUT);
  184. pinMode(ReflectorPatio, OUTPUT);
  185. pinMode(SelenoideTanke, OUTPUT);
  186.  
  187. pinMode(BotonCuarto, INPUT_PULLUP);
  188. pinMode(SensorPorton, INPUT_PULLUP);
  189. pinMode(SensorBombaAgua, INPUT_PULLUP);
  190.  
  191. timer.setInterval(100L, checkbotones);
  192. timer.setInterval(1000L, temperaturayhumedad);
  193. timer.setInterval(1000L, checkconnect);
  194. timer.setInterval(100L, portonabierto);
  195. timer.setInterval(1000L, presurizadora);
  196.  
  197. }
  198.  
  199. void loop()
  200. {
  201. Blynk.run();
  202. timer.run();
  203. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement