lunes, 11 de septiembre de 2017

Arduino ESP8266 y 4 Relay


ARDUINO ESP8266 WIFI Y 4 RELAY

Se debe instalar la aplicación Blink en celular
Esta te da "YourAuthToken" que se inserta en sketch Arduino.
ejemplo:  "f9aded304f2e45c09859228db158867a"
Se debe usar transistores de potencia 2N2222A o BCT547 y otra fuente de poder para energizar los Leds






/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************

  You’ll need:
   - Blynk App (download from AppStore or Google Play)
   - ESP8266 board
   - Decide how to connect to Blynk
     (USB, Ethernet, Wi-Fi, Bluetooth, ...)

  There is a bunch of great example sketches included to show you how to get
  started. Think of them as LEGO bricks  and combine them as you wish.
  For example, take the Ethernet Shield sketch and combine it with the
  Servo example, or choose a USB sketch and add a code from SendData
  example.
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "YourAuthToken";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
}

void loop()
{
  Blynk.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}





sábado, 20 de mayo de 2017

Relay in Aduino uno & DS3132 timer

Mayo 2017
Aduino uno Relay & DS3132 timer





#include <Wire.h>
#include "RTClib.h"
 #define RELAY_ON 0
#define RELAY_OFF 1
#define RELAY_1  9

const int outputPin = 9; // conectar activador de Relay
bool state = false;

// RTC_DS1307 rtc;
RTC_DS3231 rtc;

void setup() {
   Serial.begin(9600);
   delay(1000);

 // Set pin as output.
  pinMode(RELAY_1, OUTPUT);

  // Initialize relay one as off so that on reset it would be off by default
  digitalWrite(RELAY_1, RELAY_OFF);
 //pinMode(9, OUTPUT);

   if (!rtc.begin()) {
      Serial.println(F("Couldn't find RTC"));
      while (1);
   }

   if (rtc.lostPower()) {
      rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
   }
}

// Comprobar si esta programado el encendido
bool isScheduledON(DateTime date)
{
   int weekDay = date.dayOfTheWeek();
   float hours = date.hour() + date.minute() / 60.0;

   // De 09:30 a 11:30 y de 21:00 a 23:00
   bool hourCondition = (hours > 6.30 && hours < 15.50) || (hours > 16.00 && hours < 6.00);

   // Miercoles, Sabado o Domingo
   bool dayCondition = (weekDay == 1 || weekDay == 2 || weekDay == 3|| weekDay == 4|| weekDay == 5|| weekDay == 6); 
   if (hourCondition && dayCondition)
   {
      return true;
   }
   return false;
}

void loop() {
   DateTime now = rtc.now();

   if (state == false && isScheduledON(now))      // Apagado y debería estar encendido
   {
      digitalWrite(RELAY_1, LOW);
      state = true;
    // Serial.print("Activado");
   }
   else if (state == true && !isScheduledON(now))  // Encendido y deberia estar apagado
   {
      digitalWrite(RELAY_1, HIGH);
      state = false;
      //Serial.print("apaga Relay");
   }

  // delay(3000);
}