Hi,
The code for my room on an ESP12E to control the light and my roller shutters worked for almost a year till today.
The roller shutters are still working (control them with direct pins) but my two relay switch (need it for the light) wont work anymore. it just wont change state when i press a button in the app. I did some testing and it seems to be that the pins that are reserved for the virtual pin are no more able to change state (even tried it manually by setting a button in the app digital for one of them). Maybe they ignore the pinMode output?
Thats the whole code:
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "";
char pass[] = "";
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
int light = 0;
void sendSensor()
{
float h = dht.readHumidity();
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V6, h);
Blynk.virtualWrite(V7, t);
}
long unsigned int switchActivated;
long unsigned int switchActivated2;
void setup()
{
Serial.begin(115200);
Blynk.begin(auth, ssid, pass);
dht.begin();
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
// Setup a function to be called every second
timer.setInterval(1000L, sendSensor);
}
BLYNK_WRITE(V1) //Button Widget is writing to pin V
{
if (param.asInt()){
switchActivated2 = millis();
digitalWrite(16, HIGH);
Blynk.virtualWrite(V1, HIGH);
Blynk.virtualWrite(V5, 1023);
Blynk.virtualWrite(V4, 0);
}
}
BLYNK_WRITE(V2) //Button Widget is writing to pin V
{
if (param.asInt()){
switchActivated = millis();
digitalWrite(5, HIGH);
Blynk.virtualWrite(V2, HIGH);
Blynk.virtualWrite(V4, 1023);
Blynk.virtualWrite(V5, 0);
}
}
BLYNK_WRITE(V3) //Button Widget is writing to pin V
{
if (param.asInt()){
if (light == 0) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
light = 1;
}
else {
digitalWrite(3, HIGH);
digitalWrite(2, LOW);
light = 0;
}
}
}
void loop()
{
Blynk.run();
timer.run();
if(switchActivated > 0 && switchActivated + 20000 < millis())
{
switchActivated = 0;
digitalWrite(5, LOW);
Blynk.virtualWrite(V2, LOW);
}
if(switchActivated2 > 0 && switchActivated2 + 20000 < millis())
{
switchActivated2 = 0;
digitalWrite(16, LOW);
Blynk.virtualWrite(V1, LOW);
}
}
Thats the code needed for the light:
BLYNK_WRITE(V3) //Button Widget is writing to pin V
{
if (param.asInt()){
if (light == 0) {
digitalWrite(2, HIGH);
digitalWrite(3, LOW);
light = 1;
}
else {
digitalWrite(3, HIGH);
digitalWrite(2, LOW);
light = 0;
}
}
}
Maybe theres just a stupid mistake but it worked till today