Hello, i used the code from Light control, gates, temperature monitoring Now I would like to add a red led as soon as soon the V10 (led6) lights up and a after 7sec when the gate is open a green led has to lights up.
There i have running into a problem. If i disabel all the code for the red and green led the code is ok and works but once i add the code it dont work annymore. Can sombody help me with that.
//wemos d1 mini
//SLOVAKIA
//Vladimir Minar
//22.3.2017
// https://community.blynk.cc/t/light-control-gates-temperature-monitoring/12671
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <SPI.h>
#include <DHT.h>
#define DHTPIN 1 // What digital pin we're connected to TX
int ledState=0;
#define closed 0
#define openend 1
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
//#define DHTTYPE DHT21 // DHT 21, AM2301
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "****";
char ssid[] = "****";// Your WiFi credentials.
char pass[] = "****"; // Set password to "" for open networks.
/**************RELAY********************************/
const int relay1 = 15; //D8-GPIO15 relay1 gate1
const int relay2 = 12; //D6-GPIO12 relay2 gate2
const int relay3 = 14; //D5-GPIO14 relay3 light1
const int relay4 = 16; //D0-GPIO16 relay4 light2
/**************BUTTON************************/
const int button1 = 3; //GPIO3 RX button1 gate1 monostabil
const int button2 = 0; //D3-GPIO0 button2 gate2 monostabil
const int button3 = 2; //D4-GPIO2 button3 light1 bistabil
const int button4 = 13; //D7-GPIO13 button3 light2 bistabil
/**************MAGNETIC SWITCH*************************/
const int magneticswitches1 = 5; // D1-GPIO5 input button gnd /gate 1 open/magneticswitches
const int magneticswitches2 = 4; // D2-GPIO4 input button gnd /gate 2 open/magneticswitches1
const int ledGpioPin1 =9;
const int ledGpioPin2 =10;
/******************************/
DHT dht(DHTPIN, DHTTYPE);
SimpleTimer timer;
/*********************************/
void physicalbutton(); //physical button
/************************************/
int relaystate3 = LOW; // relayState3
int relaystate4 = LOW; // relayState4
/***************************************/
int buttonstate3 = HIGH; // buttonState3
int buttonstate4 = HIGH; // buttonState4
/***************************************/
WidgetLED led1(V5); // led monostabil gate1
WidgetLED led2(V6); // led monostabil gate2
//WidgetLED led3(V7); // light bistabil
//WidgetLED led4(V8); // light1 bistabil
WidgetLED led5(V9); // led online
WidgetLED led6(V10); // garage 1 open/
WidgetLED led7(V11); // garage 2 open/
/*******************************/
WidgetLCD lcd(V15);
//VALUE DISPLAY online V16
//VALUE DISPLAY magneticswitches GATE V17
//VALUE DISPLAY magneticswitches GATE2 V18
/**********************************************/
boolean buttonstate1 = false; // button1 magneticswitches gate 1
boolean buttonstate2 = false; // button2 magneticswitches gate 2
/*****************TEMPERATUUR*********************/
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(V20, t);
Blynk.virtualWrite(V21, h);
}
/******************input button gnd /garage open**************/
void ledmagneticswitches1()
{
boolean isPressed = (digitalRead(magneticswitches1) == LOW);
if (isPressed != buttonstate1) {
if (isPressed) {
led6.on();
Blynk.virtualWrite(V17, "OPEN");
ledState=1;//on
digitalWrite(ledGpioPin1, ledState); //green led
lcd.print(1, 0, "GARAGE OPEN");
Blynk.email("XXX@gmail.com", "GARAGE OPEN!", "Garage open.");
} else {
led6.off();
Blynk.virtualWrite(V17, "CLOSE");
ledState=1;//on
digitalWrite(ledGpioPin2, ledState); //red led
lcd.print(1, 0, "GARAGE CLOSE");
}
buttonstate1 = isPressed;
}
}
/********input button gnd garage 1 open*****************************/
void ledmagneticswitches2()
{
boolean isPressed = (digitalRead(magneticswitches2) == LOW);
if (isPressed != buttonstate2) {
if (isPressed) {
led7.on();
Blynk.virtualWrite(V18, "OPEN");
lcd.print(1, 1, "GARAGE1 OPEN");
Blynk.email("XXX@gmail.com", "GARAGE1 OPEN!", "Garage1 open.");
} else {
led7.off();
Blynk.virtualWrite(V18, "CLOSE");
lcd.print(1, 1, "GARAGE1 CLOSE");
}
buttonstate2 = isPressed;
}
}
/*************************************************/
BLYNK_CONNECTED() {
Blynk.syncVirtual(V1);
Blynk.syncVirtual(V2);
Blynk.syncVirtual(V3);
Blynk.syncVirtual(V4);
}
/************MONOSTABIL push button android*************/
BLYNK_WRITE(V1)
{
if (param.asInt())
{
digitalWrite(relay1, HIGH);
led1.on();
}
else
{
digitalWrite(relay1, LOW);
led1.off();
}
}
/**********MONOSTABIL push button android*******************/
BLYNK_WRITE(V2)
{
if (param.asInt())
{
digitalWrite(relay2, HIGH);
led2.on();
}
else
{
digitalWrite(relay2, LOW);
led2.off();
}
}
/*****************BISTABIL switch button android***************/
BLYNK_WRITE(V3)
{
if (param.asInt())
{
digitalWrite(relay3, HIGH);
}
else
{
digitalWrite(relay3, LOW);
}
}
/**************BISTABIL switch button android**************/
BLYNK_WRITE(V4)
{
if (param.asInt())
{
digitalWrite(relay4, HIGH);
}
else
{
digitalWrite(relay4, LOW);
}
}
/**********MONOSTABIL***************/
void physicalbutton()
{
int sensorVal = digitalRead(3);
Serial.println(sensorVal);
if (sensorVal == HIGH) {
digitalWrite(15, LOW);
Blynk.virtualWrite(V1, LOW);
led1.off();
} else {
digitalWrite(15, HIGH);
Blynk.virtualWrite(V1, HIGH);
led1.on();
}
/**********MONOSTABIL*************/
int sensor1Val = digitalRead(0);
Serial.println(sensor1Val);
if (sensor1Val == HIGH) {
digitalWrite(12, LOW);
Blynk.virtualWrite(V2, LOW);
led2.off();
} else {
digitalWrite(12, HIGH);
Blynk.virtualWrite(V2, HIGH);
led2.on();
}
/**********BISTABIL**************/
if (digitalRead(button3) == LOW) {
if (buttonstate3 != LOW) {
relaystate3 = !relaystate3;
digitalWrite(relay3, relaystate3);
Blynk.virtualWrite(V3, relaystate3);
}
buttonstate3 = LOW;
} else {
buttonstate3 = HIGH;
}
/**********BISTABIL***************/
if (digitalRead(button4) == LOW) {
if (buttonstate4 != LOW) {
relaystate4 = !relaystate4;
digitalWrite(relay4, relaystate4);
Blynk.virtualWrite(V4, relaystate4);
}
buttonstate4 = LOW;
} else {
buttonstate4 = HIGH;
}
}
/*************LED ONLINE*************/
void ledonline()
{
if (led5.getValue()) {
led5.off();
Serial.println("LED on V9: off");
Blynk.virtualWrite(V16, "ERROR");
} else {
led5.on();
Serial.println("LED on V9: on");
Blynk.virtualWrite(V16, "ONLINE");
}
}
/*****************************************/
void setup(){
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
////////////////////////////////////////////
Blynk.email("XXX@gmail.com", "online", "wemos d1 mini je online.");
/****************************************/
pinMode(relay1, OUTPUT); // relay1
pinMode(relay2, OUTPUT);
pinMode(relay3, OUTPUT);
pinMode(relay4, OUTPUT);
/**********************************/
pinMode(button1, INPUT_PULLUP); // button1
pinMode(button2, INPUT_PULLUP);
pinMode(button3, INPUT_PULLUP);
pinMode(button4, INPUT_PULLUP);
/*************************************/
digitalWrite(relay3, relaystate3);
digitalWrite(relay4, relaystate4);
/****************************************/
pinMode(magneticswitches1, INPUT_PULLUP); // input button gnd /garage open/
pinMode(magneticswitches2, INPUT_PULLUP); // input button gnd /garage 1 open/
pinMode(ledGpioPin1, OUTPUT); // led green
pinMode(ledGpioPin2, OUTPUT); // led red
//////////////////////////////////////////
timer.setInterval(500L, ledmagneticswitches1);
timer.setInterval(500L, ledmagneticswitches2);
/*************************************************/
timer.setInterval(1000L, physicalbutton);
timer.setInterval(1000L, ledonline);
/*************************************************/
dht.begin();
timer.setInterval(1000L, sendSensor);// Setup a function to be called every second
/************************************************/
}
void loop()
{
Blynk.run();
timer.run();
}