BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Manual Virtual Button

Hello Community,

i have a litte Problem with my Project, and maybe someone know or can show me where my mistake is.

The Code works fine with the timer, but i want to input a virtual Button (V4) which switch the Relay on, like a manual function.

I tried many ways but it don´t work… and when the relay switch on it will work only for a few seconds.

I use a Wemos D1 R1.

Best Regards,

c0ntem

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <OneWire.h>
#include <DallasTemperature.h> //Temperatur Sensor
#include <LiquidCrystal_I2C.h> // Display 4 Zeilen
#include <Wire.h>
#include <TimeLib.h>

const int oneWireBus = 0;
OneWire oneWire(oneWireBus);
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(0x27, 16, 2);  // Benennung für das LCD

// Token für Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "TiqyltaDUGM
char ssid[] = "
char pass[] = "

SimpleTimer timer;

const int Pumpe = 12; // Relee Pumpensteuerung

float Alarmflag;
float Pumpenstatus;  // Zeigt den Status der Pumpe an.
float SolltempTief = 20; // Minimale Speichertemperatur Vorlauf Heizungspume
float Sicherheitstemp = 35;// Maximale Speichertemperatur Sicherheit
float Sommerentladetemp = 32; // Spezielle Sommerentladetemp
float SolltempMittag = 25; // Mindesttemperatur Mittags im Speicher
float SolltempHoch = 30; // Maximale Speichertemperatur muss kleiner Sicherheitstemp sein.

// Timer bei Start alle Off
int Timer1 = LOW;
int Timer2 = LOW;
int Timer3 = LOW;
int Man;


void checkTimer()
{
  sensors.requestTemperatures();

  float temp = sensors.getTempCByIndex(0);

  Blynk.virtualWrite(V1, temp);
  Blynk.virtualWrite(V2, Pumpenstatus);


  // ##### Sicherheitstemperatur & Sommerentladung

  //if (Man == HIGH)
  //{
  //  digitalWrite (Pumpe,HIGH);
  //}

  if ( temp > Sicherheitstemp )
  {
    digitalWrite (Pumpe, HIGH);
    Alarmflag = true;
  }

  if ( temp < Sicherheitstemp)
  {
    Alarmflag = false;
    digitalWrite (Pumpe, LOW);
  }

  //### Sommerentladung  über Timer 3 (Nacht)
  if ((temp > Sommerentladetemp) && (Timer3))
  {
    digitalWrite(Pumpe, HIGH);
  }

  //## Speicherentladung Morgens
  if ((Timer1 == 1) && (temp > SolltempTief))
  {
    digitalWrite(Pumpe, HIGH);
  }

  //## Regelbetrieb Mittags
  if ((Timer2 == 1) && (temp > SolltempMittag))
  {
    digitalWrite(Pumpe, HIGH);
  }

  //## Regelbetrieb abend & Speicherladung

  if ((Timer3 == 1) && (temp > SolltempHoch))
  {
    digitalWrite(Pumpe, HIGH);
  }

  //################# LCD

  lcd.setCursor(0, 0); //Erste Zeile
  lcd.print("Speicher ");
  lcd.print(temp);
  lcd.print ((char)223);
  lcd.print ("C");

  // LCD zweite Zeile
  lcd.setCursor(0, 1);
  if (Timer1 == 1) {
    lcd.print ("Timer 1  ");
  }
  if (Timer2 == 1) {
    lcd.print ("Timer 2  ");
  }
  if (Timer3 == 1) {
    lcd.print ("Timer 3  ");
  }
  else
  {
    lcd.print("No Timer ");
  }

  if (Alarmflag == true) {
    lcd.setCursor(0, 1);
    lcd.print ("Safty!   ");
  }

  if (digitalRead(Pumpe) == HIGH) {
    lcd.print("P On  ");
    Pumpenstatus = 1;
  }
  else
  {
    lcd.print("P Off ");
    Pumpenstatus = 0;
  }
}


void setup()
{
  lcd.init();
  lcd.backlight();
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  sensors.begin();
  pinMode (Pumpe, OUTPUT);
  timer.setInterval(3000L, checkTimer);

}
BLYNK_WRITE(V4)
{
  Man = param.asInt();
}


BLYNK_WRITE(V5) // Check Timer1
{
  Timer1 = param.asInt();
}

BLYNK_WRITE(V6) // Check Timer2
{
  Timer2 = param.asInt();
}

BLYNK_WRITE(V7) // Check Timer3
{
  Timer3 = param.asInt();
}


BLYNK_WRITE(V10)  //SolltempHoch
{
  SolltempHoch = param.asFloat();
}

BLYNK_WRITE(V11)  // SolltempTief
{
  SolltempTief = param.asFloat();
}

BLYNK_WRITE(V12) // Sicherheitstemp
{
  Sicherheitstemp = param.asFloat();
}

BLYNK_WRITE(V13) //SolltempMittag
{
  SolltempMittag = param.asFloat();
}

BLYNK_WRITE(V14) // Sommerentladetemp
{
  Sommerentladetemp = param.asFloat();
}


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


You’re almost there with the commented-out code, but unfortunately the rest of the if statements are then being processed which overrides the manual setting.

You either need to end the processing of the function with a return command, or put the other if statements inside an else statement so that they only get evaluated if Man is not equal to 1

Pete.

Hey Pete thank you for your quick response.

Sorry for the commented-out part… This was also a tried way from me.

I uncommented the part and put in an else and still not working…

Thank you so much… Sometime there are so many Trees … :smiley:

Post your updated code.

Pete.

Here is the updated code, just the else was missing :slight_smile:

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <OneWire.h>
#include <DallasTemperature.h> //Temperatur Sensor
#include <LiquidCrystal_I2C.h> // Display 4 Zeilen
#include <Wire.h>
#include <TimeLib.h>

const int oneWireBus = 0;
OneWire oneWire(oneWireBus);
DallasTemperature sensors(&oneWire);
LiquidCrystal_I2C lcd(0x27, 16, 2);  // Benennung für das LCD

// Token für Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "TiqyltaDUGM
char ssid[] = "
char pass[] = "

SimpleTimer timer;

const int Pumpe = 12; // Relee Pumpensteuerung

float Alarmflag;
float Pumpenstatus;  // Zeigt den Status der Pumpe an.
float SolltempTief = 20; // Minimale Speichertemperatur Vorlauf Heizungspume
float Sicherheitstemp = 35;// Maximale Speichertemperatur Sicherheit
float Sommerentladetemp = 32; // Spezielle Sommerentladetemp
float SolltempMittag = 25; // Mindesttemperatur Mittags im Speicher
float SolltempHoch = 30; // Maximale Speichertemperatur muss kleiner Sicherheitstemp sein.

// Timer bei Start alle Off
int Timer1 = LOW;
int Timer2 = LOW;
int Timer3 = LOW;
int Man;


void checkTimer()
{
  sensors.requestTemperatures();

  float temp = sensors.getTempCByIndex(0);

  Blynk.virtualWrite(V1, temp);
  Blynk.virtualWrite(V2, Pumpenstatus);


  // ##### Sicherheitstemperatur & Sommerentladung

  if (Man == HIGH)
 {
  digitalWrite (Pumpe,HIGH);
  }
else
{
  if ( temp > Sicherheitstemp )
  {
    digitalWrite (Pumpe, HIGH);
    Alarmflag = true;
  }

  if ( temp < Sicherheitstemp)
  {
    Alarmflag = false;
    digitalWrite (Pumpe, LOW);
  }

  //### Sommerentladung  über Timer 3 (Nacht)
  if ((temp > Sommerentladetemp) && (Timer3))
  {
    digitalWrite(Pumpe, HIGH);
  }

  //## Speicherentladung Morgens
  if ((Timer1 == 1) && (temp > SolltempTief))
  {
    digitalWrite(Pumpe, HIGH);
  }

  //## Regelbetrieb Mittags
  if ((Timer2 == 1) && (temp > SolltempMittag))
  {
    digitalWrite(Pumpe, HIGH);
  }

  //## Regelbetrieb abend & Speicherladung

  if ((Timer3 == 1) && (temp > SolltempHoch))
  {
    digitalWrite(Pumpe, HIGH);
  }

  //################# LCD

  lcd.setCursor(0, 0); //Erste Zeile
  lcd.print("Speicher ");
  lcd.print(temp);
  lcd.print ((char)223);
  lcd.print ("C");

  // LCD zweite Zeile
  lcd.setCursor(0, 1);
  if (Timer1 == 1) {
    lcd.print ("Timer 1  ");
  }
  if (Timer2 == 1) {
    lcd.print ("Timer 2  ");
  }
  if (Timer3 == 1) {
    lcd.print ("Timer 3  ");
  }
  else
  {
    lcd.print("No Timer ");
  }

  if (Alarmflag == true) {
    lcd.setCursor(0, 1);
    lcd.print ("Safty!   ");
  }

  if (digitalRead(Pumpe) == HIGH) {
    lcd.print("P On  ");
    Pumpenstatus = 1;
  }
  else
  {
    lcd.print("P Off ");
    Pumpenstatus = 0;
  }
}


void setup()
{
  lcd.init();
  lcd.backlight();
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  sensors.begin();
  pinMode (Pumpe, OUTPUT);
  timer.setInterval(3000L, checkTimer);

}
BLYNK_WRITE(V4)
{
  Man = param.asInt();
}


BLYNK_WRITE(V5) // Check Timer1
{
  Timer1 = param.asInt();
}

BLYNK_WRITE(V6) // Check Timer2
{
  Timer2 = param.asInt();
}

BLYNK_WRITE(V7) // Check Timer3
{
  Timer3 = param.asInt();
}


BLYNK_WRITE(V10)  //SolltempHoch
{
  SolltempHoch = param.asFloat();
}

BLYNK_WRITE(V11)  // SolltempTief
{
  SolltempTief = param.asFloat();
}

BLYNK_WRITE(V12) // Sicherheitstemp
{
  Sicherheitstemp = param.asFloat();
}

BLYNK_WRITE(V13) //SolltempMittag
{
  SolltempMittag = param.asFloat();
}

BLYNK_WRITE(V14) // Sommerentladetemp
{
  Sommerentladetemp = param.asFloat();
}


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