Skip to content

Instantly share code, notes, and snippets.

@RoboCore
Last active September 24, 2018 22:49
Show Gist options
  • Save RoboCore/4f3c08edf42e0f6c48eaf6306b9bf665 to your computer and use it in GitHub Desktop.
Save RoboCore/4f3c08edf42e0f6c48eaf6306b9bf665 to your computer and use it in GitHub Desktop.
Controle o Módulo Relé Serial da RoboCore com o aplicativo Blynk.
/*************************************************************
Pinos-Virtuais-e-Relay-Serial-no-Blynk
// Controle o Módulo Relé Serial da RoboCore com o aplicativo Blynk.
Produtos e tutoriais: http://robocore.net
Siga a RoboCore: http://facebook.com/robocore
http://youtube.com/robocore
http://instagram.com/robocore
__________
Baseado no exemplo de ESP8266 da biblioteca Blynk.
Modificado em 30 Ago 2018 por RoboCore.
Faça o download da última versão da biblioteca SerialRelay em:
https://github.com/RoboCore/SerialRelay
**************************************************************/
#include <SerialRelay.h>
SerialRelay relays(4, 5, 1); // (data, clock, número de módulos)
#define BLYNK_PRINT Serial
#include "ESP8266_Lib.h"
#include "BlynkSimpleShieldEsp8266.h"
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "seu-token-aqui";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "sua-rede-wifi-aqui";
char pass[] = "sua-senha-da-rede-wifi-aqui";
#include "SoftwareSerial.h"
SoftwareSerial EspSerial(10, 11); // RX, TX
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
BLYNK_WRITE(V0){
int pinValue = param.asInt();
//Serial.println(pinValue);
if (pinValue == 1) {
relays.SetRelay(1, SERIAL_RELAY_ON, 1); // liga o relé 01
} else {
relays.SetRelay(1, SERIAL_RELAY_OFF, 1); // desliga o relé 01
}
}
BLYNK_WRITE(V1){
int pinValue = param.asInt();
//Serial.println(pinValue);
if (pinValue == 1) {
relays.SetRelay(2, SERIAL_RELAY_ON, 1); // liga o relé 02
} else {
relays.SetRelay(2, SERIAL_RELAY_OFF, 1); // desliga o relé 02
}
}
BLYNK_WRITE(V2){
int pinValue = param.asInt();
//Serial.println(pinValue);
if (pinValue == 1) {
relays.SetRelay(3, SERIAL_RELAY_ON, 1); // liga o relé 03
} else {
relays.SetRelay(3, SERIAL_RELAY_OFF, 1); // desliga o relé 03
}
}
BLYNK_WRITE(V3){
int pinValue = param.asInt();
//Serial.println(pinValue);
if (pinValue == 1) {
relays.SetRelay(4, SERIAL_RELAY_ON, 1); // liga o relé 04
} else {
relays.SetRelay(4, SERIAL_RELAY_OFF, 1); // desliga o relé 04
}
}
void setup(){
Serial.begin(9600);
delay(10);
EspSerial.begin(ESP8266_BAUD);
delay(10);
Blynk.begin(auth, wifi, ssid, pass);
}
void loop(){
Blynk.run();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment