Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define BLYNK_PRINT Serial
- #include <SPI.h>
- #include <Ethernet.h>
- #include <BlynkSimpleEthernet.h>
- #include <DHT.h>
- #include <Wire.h>
- #include <DHT.h>
- #include <TimeLib.h>
- #include <WidgetRTC.h>
- char auth[] = "xxxxx";
- #define W5100_CS 10
- #define SDCARD_CS 4
- #define DHTPIN 33
- #define DHTTYPE DHT11 // DHT 11
- BlynkTimer timer;
- DHT dht(DHTPIN, DHTTYPE);
- WidgetRTC rtc;
- const int LuzCuarto = 21;
- const int BotonCuarto = 22;
- const int ReflectorPorton = 24;
- const int ReflectorTerreno = 26;
- const int AperturaPorton = 27;
- const int SensorPorton = 25;
- const int BombaAgua = 30;
- const int SensorBombaAgua = 29;
- const int ReflectorPatio = 28;
- const int SelenoideTanke = 31;
- const int BombaPresurizadora = 32;
- int EstadoLuzCuarto = LOW;
- int EstadoBotonCuarto = LOW;
- int EstadoReflectorPorton = LOW;
- int EstadoReflectorTerreno = LOW;
- int EstadoAperturaPorton = LOW;
- int EstadoSensorPorton = LOW;
- int EstadoBombaAgua = LOW;
- int EstadoSensorBombaAgua = LOW;
- int EstadoReflectorPatio = LOW;
- int EstadoBombaPresurizadora = LOW;
- int EstadoSelenoideTanke = HIGH;
- BLYNK_CONNECTED() {
- Blynk.syncAll();
- }
- BLYNK_WRITE(V0) {
- EstadoLuzCuarto = param.asInt();
- digitalWrite(LuzCuarto, EstadoLuzCuarto);
- }
- BLYNK_WRITE(V3) {
- EstadoReflectorPorton = param.asInt();
- digitalWrite(ReflectorPorton, EstadoReflectorPorton);
- }
- BLYNK_WRITE(V4) {
- EstadoReflectorTerreno = param.asInt();
- digitalWrite(ReflectorTerreno, EstadoReflectorTerreno);
- }
- BLYNK_WRITE(V5) {
- EstadoReflectorPatio = param.asInt();
- digitalWrite(ReflectorPatio, EstadoReflectorPatio);
- }
- BLYNK_WRITE(V6) {
- EstadoBombaAgua = param.asInt();
- digitalWrite(BombaAgua, EstadoBombaAgua);
- }
- BLYNK_WRITE(V8) {
- EstadoAperturaPorton = param.asInt();
- digitalWrite(AperturaPorton, EstadoAperturaPorton);
- }
- BLYNK_WRITE(V9) {
- EstadoSensorBombaAgua = param.asInt();
- digitalWrite(BombaAgua, EstadoSensorBombaAgua);
- }
- BLYNK_WRITE(V10) {
- EstadoSelenoideTanke = param.asInt();
- digitalWrite(SelenoideTanke, EstadoSelenoideTanke);
- }
- BLYNK_WRITE(V111) {
- EstadoBombaPresurizadora = param.asInt();
- digitalWrite(BombaPresurizadora, EstadoBombaPresurizadora);
- }
- void checkbotones()
- {
- if (digitalRead(BotonCuarto) == LOW) {
- if (EstadoBotonCuarto != LOW) {
- EstadoLuzCuarto = !EstadoLuzCuarto;
- digitalWrite(LuzCuarto, EstadoLuzCuarto);
- Blynk.virtualWrite(V0, EstadoLuzCuarto);
- }
- EstadoBotonCuarto = LOW;
- } else {
- EstadoBotonCuarto = HIGH;
- }
- }
- void portonabierto()
- {
- if (hour() < 05) {
- if (digitalRead(SensorPorton) == LOW) {
- if (EstadoSensorPorton != LOW) {
- EstadoReflectorPorton = !EstadoReflectorPorton;
- digitalWrite(ReflectorPorton, HIGH);
- Blynk.virtualWrite(V3, HIGH);
- Blynk.notify("Porton Abierto");
- }
- EstadoSensorPorton = LOW;
- } else {
- EstadoSensorPorton = HIGH;
- digitalWrite(ReflectorPorton, LOW);
- Blynk.virtualWrite(V3, LOW);
- }
- }
- }
- void presurizadora()
- {
- if (hour() < 14)
- {
- if (EstadoBombaPresurizadora != HIGH) {
- EstadoBombaPresurizadora = !EstadoBombaPresurizadora;
- digitalWrite(BombaPresurizadora, EstadoBombaPresurizadora);
- Blynk.virtualWrite(V11, EstadoBombaPresurizadora);
- digitalWrite(SelenoideTanke, LOW);
- Blynk.virtualWrite(V10, SelenoideTanke );
- Blynk.notify("Agua Normal");
- EstadoBombaPresurizadora = HIGH;
- } else {
- EstadoBombaPresurizadora = LOW;
- digitalWrite(BombaPresurizadora, HIGH);
- Blynk.notify("Agua Presurizada");
- }
- }
- }
- void temperaturayhumedad()
- {
- float h = dht.readHumidity();
- float t = dht.readTemperature();
- if (isnan(h) || isnan(t)) {
- Blynk.notify("Error al enviar SENSONR TEMPERATURA CUARTO KEVIN");
- return;
- }
- Blynk.virtualWrite(V2, h);
- Blynk.virtualWrite(V1, t);
- }
- void checkconnect()
- {
- bool result = Blynk.connected();
- if (result == false) {
- Blynk.connect();
- Blynk.syncAll();
- Serial.println("Reconectando");
- }
- }
- void setup()
- {
- Serial.begin(9600);
- pinMode(SDCARD_CS, OUTPUT);
- digitalWrite(SDCARD_CS, HIGH);
- Blynk.begin(auth, IPAddress(192, 168, 1, 14), 8080);
- dht.begin();
- rtc.begin();
- pinMode(LuzCuarto, OUTPUT);
- pinMode(ReflectorPorton, OUTPUT);
- pinMode(ReflectorTerreno, OUTPUT);
- pinMode(BombaAgua, OUTPUT);
- pinMode(ReflectorPatio, OUTPUT);
- pinMode(SelenoideTanke, OUTPUT);
- pinMode(BotonCuarto, INPUT_PULLUP);
- pinMode(SensorPorton, INPUT_PULLUP);
- pinMode(SensorBombaAgua, INPUT_PULLUP);
- timer.setInterval(100L, checkbotones);
- timer.setInterval(1000L, temperaturayhumedad);
- timer.setInterval(1000L, checkconnect);
- timer.setInterval(100L, portonabierto);
- timer.setInterval(1000L, presurizadora);
- }
- void loop()
- {
- Blynk.run();
- timer.run();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement