LED won't stay on to indicate door status

I’m creating a monitor that will give me the status of my ATV battery over the winter as well as monitor the shed door. I’d like to know when it is opened.
The Voltage monitor is working. The reed status event is sent via notification. My virtual LED does light but goes out when I acknowledge the notification on my iPhone.
Where am I going wrong with the LED to make sure it stays on the entire time the door is open / closed?
***I’m adding temperature sensors in and out of the shed. Having got that far with the installation nor troubleshooting the code if it doesn’t work as written.

#define BLYNK_PRINT Serial

#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SoftwareSerial.h>
#include <SimpleTimer.h>
#include <SPI.h>
#include <Wire.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define VT_PIN A0
#define ONE_WIRE_BUS 4
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

// Assign the addresses of your 1-Wire temp sensors.
DeviceAddress Probe01 = { 0x28, 0xff, 0x40, 0x93, 0x3c, 0x04, 0x00, 0x96 }; //S1
DeviceAddress Probe02 = { 0x28, 0xff, 0x82, 0x93, 0x3c, 0x04, 0x00, 0x37 }; //S2
DeviceAddress Probe03 = { 0x28, 0xff, 0xe6, 0x70, 0x3b, 0x04, 0x00, 0x82 }; //S3
DeviceAddress Probe04 = { 0x28, 0xff, 0x8d, 0x51, 0x3a, 0x04, 0x00, 0xb7 }; //S4




char auth[] = "KCSR4fK8VgjFC_Eh5-jI7Slq2PAxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "XXXXXXX";
char pass[] = "XXXXXXXXXXXX";

SimpleTimer timer;



// This function sends Arduino's up time every second to Virtual Pin (1).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void myTimerEvent()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V1, millis() / 1000);
  
}

int reed_s = D0; // Reed sensor

int flag = 0; 

void getVoltage()
{
int vt_read = analogRead(VT_PIN);
  float reading = vt_read * (3.09 / 1024.0) * 5.0; //3.2 changed to lower voltage reading
  Blynk.virtualWrite(V15, reading);  
}

void getTempData()
{
  sensors.requestTemperatures();
  Blynk.virtualWrite(V1, sensors.getTempFByIndex(0));
  Blynk.virtualWrite(V2, sensors.getTempFByIndex(1));
  Blynk.virtualWrite(V3, sensors.getTempFByIndex(2));
  Blynk.virtualWrite(V4, sensors.getTempFByIndex(3));
  Blynk.virtualWrite(V8, sensors.getTempFByIndex(4));
}

void sensorvalue1()
{

if((digitalRead(reed_s) == LOW) && ( flag == 0  ))
{
  Blynk.virtualWrite(V2,0 ); //Turns off Red LED
  Blynk.virtualWrite(V3,255 ); // Turns on Green LED
 Blynk.notify("Door Closed!!!"); 
  flag = 1; 
}

if((digitalRead(reed_s) == HIGH) && ( flag == 1) )
{
  Blynk.virtualWrite(V2,255 ); // Turns on Red LED
  Blynk.virtualWrite(V3,0 ); // Turns off Green LED 
  Blynk.notify("Door Opened!!!"); 
  flag = 0; 
  
}
}

void setup()
{
  // Debug console
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
 pinMode(reed_s, INPUT_PULLUP); 
  timer.setInterval(1000L,sensorvalue1);
  sensors.begin();
  sensors.setResolution(10);
 
  //timer.setInterval(1000L, sendSensor);
  timer.setInterval(1500L, getTempData);
  timer.setInterval(2000L, getVoltage); // no need to add another of these! v instead of V

}

void loop()
{
  Blynk.run();
  timer.run(); // Initiates BlynkTimer   

}```

You appear to be using pins V2 and V3 for LED widgets and also as a way of displaying the temperature values.

Pete.

:roll_eyes:
Yes, that was my issue. Thanks for looking it over Pete

1 Like