Basic physical LED Control via Blynk

Marketing most likely.

Yes, but I also still use Arduino and ESP-01… born to be a lone wolf I guess ::smiley:

@Hannes.P Sorry, this side discussion is probably best in that other semi related topic. Meanwhile, stick with proper Arduino pin designation and let us know if you got your code working with pinMode()

Yeah men, thanks! You are the best!
First step, switch on an off a LED works now, lets go on, there is still much more potential in Blynk. :star_struck::star_struck::star_struck:
If someone need in future a sketch to switch something which is hardware interrupt with a microcotroller, here is a sketch which works (used with a Wemos D1 mini):

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "b5a2426a237549448f9dff83xxxxxxxx"
char ssid[] = "Fritzboxxxxx";
char pass[] = "xxxx37094862xxxxxxxx";

BLYNK_WRITE(V1)
{
  int pinValue = param.asInt();         // assigning incoming value from pin V1 to a variable
  if (pinValue == 1) {                        // If value is 1 run this command
    digitalWrite(D4, HIGH);              //D4 output from Wemos D1 mini
  }
  else {                                           // If value is 0 run this command
    digitalWrite(D4, LOW);
  }
  Serial.print("V1 Button value is: ");
  Serial.println(pinValue);
}

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode(D4, OUTPUT);
}

void loop()
{
  Blynk.run();
}

@Hannes.P Please remember to format any code you paste here… I fixed your last post, so you can look back at how it is done.

Blynk - FTFC

Hi guys I would need again help from you :hugs:
Also now I wrote a lot of codes, as much that I can no longer lost my view :joy:
Joke not really, but I had a question to a simple sequence. To understand better I copy below an extract from my sketch. Also I would realize a central function which means in my case:
Only if button V3 is pressed, the action from slider V4 can start, which means only when button V3 is pressed, I am able to dim an led which is conected on D3. Only dimming a led without any condition (in my case if pinValue == 1 in row 28) works but I would like to add it in my sketch :blush:
Thanks in the meantime :wink:

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "b5a2426a237549448f9dff83a354xxxx";
char ssid[] = "Fritzboxxxxx";
char pass[] = "67033709486218110xxxx";

int pinValue = 0;                       //status from Button V1
int brightness = 0;                     //value from Slider V3

BLYNK_WRITE(V1)
{
  int pinValue = param.asInt();         // assigning incoming value from pin V1 to a variable (Button)
  if (pinValue == 1) {                  // If value is 1 run this command
    digitalWrite(D4, HIGH);             // D1 output from Wemos D1 mini
  }
  else {                                // If value is 0 run this command
    digitalWrite(D4, LOW);              // D1 output from Wemos D1 mini
  }
  Serial.print("V1 Button value is: "); // Output the value "pinValue" in Serial Monitor
  Serial.println(pinValue);
}

BLYNK_WRITE(V3)
{
  int brightness = param.asInt();       // assigning incoming value from pin V3 to a variable
  if (pinValue == 1){
  analogWrite (D3, brightness);         // D3 output from Wemos D1 mini
  }
  Serial.print("V1 Slider value is: "); // Output the value "brightness" in Serial Monitor
  Serial.println(brightness);
}

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode(D4, OUTPUT);                  // D4 is an output (digital)
  pinMode(D3, OUTPUT);                  // D3 is an output (analog)
}

void loop()
{
  Blynk.run();
}

Basically same general issue, so I merged your last post back into original topic.

Sorry I can not follow you…
I missing the forest through the trees :joy:

You 2nd to last post (above) was basically about same general issue as this whole topic… but posted in a new topic. But having multiple topics on same issue is not really allowed, so I merged your last post back into this original topic… hope this clears that up :stuck_out_tongue_winking_eye:

Please stop creating new topics about your confusion of the same general issue :stuck_out_tongue:

Just clarify your point in this topic and we will keep trying to assist.

Hey Gunner,
recently I really would not spam, it was only a wrong click because of my gaucherie :rofl: Hope you can forgive me :pray:
No about me problem with the understanding from Blynk… now I would program something which works like a lock, which means, only when something is happen, the other thing can work. I would use this for a central off funciton of the final sketch. Now I wrote this sketch, where led on D4 lights, when button V1 is pressed and led on D1 should light only if button V1 and V7 is pressed. I just can not find my error… To test I use only digitaloutputs so I wrote digitalWrite(D1, HIGH). The declaration with the output Pins from the wemos we clarified just last one, also that I have to declare the outputPin in void setup() as an output… I did all. If I let away the condition that D1 lights only when button v1 is also pressedork i can control both leds with to different buttons but is not what I want. Thereby I can also exclude an error by wiring. Here the sketch

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "b5a2426a237549448f9dff83a354xxxx";
char ssid[] = "Fritzboxxxxx";
char pass[] = "6703370948621811xxxx";

int StatusV1 = 0;                       //status from Button V1
int StatusV7 = 0;                       //value from Slider V3

BLYNK_WRITE(V1)
{
  int StatusV1 = param.asInt();         // assigning incoming value from pin V1 to a variable (Button)
  if (StatusV1 == 1) {                  // If value is 1 run this command
    digitalWrite(D4, HIGH);             // D1 output from Wemos D1 mini
  }
  else {                                // If value is 0 run this command
    digitalWrite(D4, LOW);              // D1 output from Wemos D1 mini
  }
  Serial.print("StatusV1 is: ");        // Output the value "pinValue" in Serial Monitor
  Serial.println(StatusV1);
}

BLYNK_WRITE(V7)
{
  int StatusV7 = param.asInt();         // assigning incoming value from pin V1 to a variable (Button)
  if ((StatusV7 == 1) && (StatusV1 == 1)) // If value is 1 run this command
  {
    digitalWrite(D1, HIGH);             // D1 output from Wemos D1 mini
  }
  else {                                // If value is 0 run this command
    digitalWrite(D1, LOW);              // D1 output from Wemos D1 mini
  }
  Serial.print("StatusV7 is: ");        // Output the value "pinValue" in Serial Monitor
  Serial.println(StatusV7);
}

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode(D4, OUTPUT);                  // D4 is an output (digital)
  pinMode(D1, OUTPUT);                  // D1 is an output (digital)
}

void loop()
{
  Blynk.run();
}

Could it be problem from the declartion from the variable “StatusV1”? Can I use it only in the function from BLYNK_WRITE(V1) or it´s possible to declare it as an global variable how I did it at the begin from the sketch?
But this work:

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "b5a2426a237549448f9dff83a354xxxx";
char ssid[] = "Fritzboxxxxx";
char pass[] = "6703370948621811xxxx";

int StatusV1 = 0;                       //status from Button V1
int StatusV7 = 0;                       //status from Button V7

BLYNK_WRITE(V1)
{
  int StatusV1= param.asInt();         // assigning incoming value from pin V1 to a variable (Button)
  if (StatusV1 == 1) {                  // If value is 1 run this command
    digitalWrite(D4, HIGH);             // D1 output from Wemos D1 mini
  }
  else {                                // If value is 0 run this command
    digitalWrite(D4, LOW);              // D1 output from Wemos D1 mini
  }
  Serial.print("StatusV1 is: ");        // Output the value "pinValue" in Serial Monitor
  Serial.println(StatusV1);
}

BLYNK_WRITE(V7)
{
  int StatusV7 = param.asInt();         // assigning incoming value from pin V1 to a variable (Button)
  if (StatusV7 == 1)                    // If value is 1 run this command
  {
    digitalWrite(D1, HIGH);             // D1 output from Wemos D1 mini
  }
  else {                                // If value is 0 run this command
    digitalWrite(D1, LOW);              // D1 output from Wemos D1 mini
  }
  Serial.print("StatusV7 is: ");        // Output the value "pinValue" in Serial Monitor
  Serial.println(StatusV7);
}

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode(D4, OUTPUT);                  // D4 is an output (digital)
  pinMode(D1, OUTPUT);                  // D1 is an output (digital)
}

void loop()
{
  Blynk.run();
}

Here I control both LED with two different buttons, but without any condition between the lights (not what I want but hope you can help me :crossed_fingers:)

Try this… it is something like what I will be adding soon to my Code Collection Topic

Each button press (or release) triggers it’s Function and sets the sate of it’s button.

That Function will check if both button states are HIGH, and if so, turns on the LED

But if one state is LOW then it turns OFF the LED and calls the other Function, which repeats the check.

Thus, regardless of which button gets called pressed first, nothing happens until the second on is also pressed.

This will work with buttons in “button” or “switch” mode for different conditions (e.g. both must be pressed down to activate, one or the other can be a safety switch for the other momentary button, or both can be safety switches)

int Button1, Button2, DevLED=D4;  // D4 can also be indicated as pin 2)
BLYNK_WRITE(V1) {  // Button 1
  Button1 = param.asInt(); // Get value as integer
  if (Button1 && Button2 == 1) {
    digitalWrite(DevLED, HIGH);  // If both buttons ON, turn on LED...
  } else {
    digitalWrite(DevLED, LOW);  // ...else turn OFF LED
  }
  Blynk.syncVirtual(V7);  // Check button 2
}

BLYNK_WRITE(V7) { // Button 2
  Button2 = param.asInt(); // Get value as integer
  if (Button1 && Button2 == 1) {
    digitalWrite(DevLED, HIGH);  // If both buttons ON, turn on LED...
  } else {
    digitalWrite(DevLED, LOW);  // ...else turn OFF LED
  }
  Blynk.syncVirtual(V1);  // Check button 1
}

Hi Gunnar, sorry to disturb you again, but trying to make my code more flexible and to avoid the row

Blynk.syncVirtual(V7);

I think, I have found an other solution which should (with accent to should) work. :rofl: The reality says something other… sadly :disappointed_relieved:
Once I learnt something about counters and flags, so I thought it should works also with Blynk. For the reason that I do not like switches (because usually I forget to switch them off afer I switched them on) I want write something which works like an impulse. When I push a Button the first time it sets a flag HIGH with the second push again LOW). So I could avoid usually the row when I write more functions where I have to request the status from the flag “varCentralOut”.

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

char auth[] = "aace274ad74842ea93387312b6xxxxx";                     
char ssid[] = "Fritzbox3272";                                          
char pass[] = "xxxxxxxxxxxxxxxxxx";   

int varCentralOut = 0;            //flag central Out
int varMode1 = 0;                 //flag Modue 1
int varMode2 = 0;                 //flag Modue 2
int varMode3 = 0;                 //flag Modue 3
int varMode4 = 0;                 //flag Modue 4
int varLedOutput = 0;           //flag to simulate output signal
int LedPin = D3;                   //LED conected to D3                               

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode (D3, OUTPUT);                         //Pin D3 is an output Pin
}

BLYNK_WRITE(V20)                                //Function Central Out
{
  int CentralOut = param.asInt();               //Get value from Button V20 
  if (CentralOut == 1) {                        //if it is HIGH
    varCentralOut++;                           //count the flag "varCentralOut" ++
  }
  if (varCentralOut == 2) {                    //if the Button get pushed a second one
    varCentralOut = 0;                         //flag "varCentralOut" is again 0
  }
  Serial.print ("CentralOut is ");             //Output the text "CentralOut is " in Serial Monitor
  Serial.println (CentralOut);                 //Output the status from Button V20 in Serial Monitor  
  Serial.print ("varCentralOut is ");        //Output the text "varCentralOut" in Serial Monitor
  Serial.println (varCentralOut);            //Output the flag "varCentralOut" in Serial Monitor

}
BLYNK_WRITE(V21)                                //Function Mode 1
{
  int Mode1 = param.asInt();               //Get value from Button V21 
  if (Mode1 == 1) {                        //if it is HIGH
    varMode1++;                           //count the flag "varMode1" ++
  }
  if (Mode1 == 2) {                    //if the Button get pushed a second one
    varMode1= 0;                         //flag "varCentralOut" is again 0
  }
if ((varMode1 == 1) && (varCentralOut == 0)) {
     (varLedOutput = 1);
     digitalWrite (LedPin, HIGH); 
  Serial.print ("Mode1 is ");             //Output the text "CentralOut is " in Serial Monitor
  Serial.println (Mode1);                 //Output the status from Button V21 in Serial Monitor  
  Serial.print ("varMode1 is ");        //Output the text "varMode1 is " in Serial Monitor
  Serial.println (varMode1);            //Output the flag "varMode1" in Serial Monitor
  Serial.print ("varLedOutput is ")   //Output the text "varLedOutput" in Serial Monitor
  Serial.println (varLedOutput);      //Output the flag "varLedOutput" in Serial Monitor
}
......Mode 2 how Mode 1  (Button V22)
......Mode 3 how Mode 1  (Button V23)
......Mode 3 how Mode 1  (Button V24)
~~~
To explain you how it should work: There are four differnt modes which all became started/switched on by pushing them different button. When I push the central off button, all flags become reseted and everything become switch off. I do not know why but I get the real values in Serial Monitor when I press the buttons. 
I see for example that varMode1 == 1 and that varCentralOut == 1 but varLedOutput change never his  value from 0 to 1, so I think there must be the error. Where I could than write the condition, because
~~~
if ((varMode1 == 1) && (varCentralOut == 1)) {
  varLedOutput = 1;
   digitalWrite (LedPin, HIGH);

So… I arrived at the end from my sermon. You know on? Where is the error of my thinking hidden?
Would be very nice if (you could help me == 1) {
thanks in the meantime; }
else {frack you;}
No, joke, you are the best
Yeah, I am the hero of the loops :joy::joy::joy:
:+1::+1::+1::blush::blush:

I am really not very good at troubleshooting code… even my own :stuck_out_tongue_winking_eye: But I think this line need less brackets…

if (varMode1 && varCentralOut == 1) {
// do something if both conditions are TRUE
}

Hi guys,
hope you can help me on, Gunnar could not, so I decided to ask the whole community.
Hope it´s okay :+1: (But he remains again usually the best :joy:) Not let`s come to my question. It is a simply thinking but it does not work how I want.
How is it possible to compare flags. Also, I would like that I push a button in Blynk App, which is set to PUSH, after I set a flag HIGH. With the next push on the same button, the flag gets reseted to LOW. So far so good, it works until there.
Now I want have more different buttons which works all like this.
So I think, I can write a more flexible sketch. The main reason I need to realize a central out function. With one click I want switch down all functions with works at the same time. To explain you. I have a sketch with more modes. All I switch from the App with seperate buttons. If I click then at the central out button, all should go off.

Here a part of the sketch:

int varMode2 = 0;                 //flag Modue 2
int varMode3 = 0;                 //flag Modue 3
int varMode4 = 0;                 //flag Modue 4
int varLedOutput = 0;           //flag to simulate output signal
int LedPin = D3;                   //LED conected to D3                               

void setup()
{
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  pinMode (D3, OUTPUT);                         //Pin D3 is an output Pin
}

BLYNK_WRITE(V20)                                //Function Central Out
{
  int CentralOut = param.asInt();               //Get value from Button V20 
  if (CentralOut == 1) {                        //if it is HIGH
    varCentralOut++;                           //count the flag "varCentralOut" ++
  }
  if (varCentralOut == 2) {                    //if the Button get pushed a second one
    varCentralOut = 0;                         //flag "varCentralOut" is again 0
  }
  Serial.print ("CentralOut is ");             //Output the text "CentralOut is " in Serial Monitor
  Serial.println (CentralOut);                 //Output the status from Button V20 in Serial Monitor  
  Serial.print ("varCentralOut is ");        //Output the text "varCentralOut" in Serial Monitor
  Serial.println (varCentralOut);            //Output the flag "varCentralOut" in Serial Monitor

}
BLYNK_WRITE(V21)                                //Function Mode 1
{
  int Mode1 = param.asInt();               //Get value from Button V21 
  if (Mode1 == 1) {                        //if it is HIGH
    varMode1++;                           //count the flag "varMode1" ++
  }
  if (Mode1 == 2) {                    //if the Button get pushed a second one
    varMode1= 0;                         //flag "varCentralOut" is again 0
  }
if ((varMode1 == 1) && (varCentralOut == 0)) {
     (varLedOutput = 1);
     digitalWrite (LedPin, HIGH); 
  Serial.print ("Mode1 is ");             //Output the text "CentralOut is " in Serial Monitor
  Serial.println (Mode1);                 //Output the status from Button V21 in Serial Monitor  
  Serial.print ("varMode1 is ");        //Output the text "varMode1 is " in Serial Monitor
  Serial.println (varMode1);            //Output the flag "varMode1" in Serial Monitor
  Serial.print ("varLedOutput is ")   //Output the text "varLedOutput" in Serial Monitor
  Serial.println (varLedOutput);      //Output the flag "varLedOutput" in Serial Monitor
}

…Mode 2 how Mode 1 (Button V22)
…Mode 3 how Mode 1 (Button V23)
…Mode 3 how Mode 1 (Button V24)

In Serial Monitor I see that the flags get set, only the flag “varLedOutput” does not work. There must be somethink wrong with the line, where I ask the programm if ((varMode1 == 1) && (varCentralOut == 0)).
varLedOutput gets never 1.
Hope you understood my “problem” and there is someone who can help me on
Thanks in the meantime

This topic is still visible to the “whole forum” :stuck_out_tongue: so no need to create a new topic. I merged it back :wink:

PS, if others do NOT intervene, that means they are either not around, do not want to troubleshoot your code (as it is not really a Blynk related issue) or they can’t… there is no benefit to repeated requests. You could Google around for other related tutorials on how boolean comparators and flags work :wink:

Thank you… I try, but am not omniscient… or often awake enough to think clearly :stuck_out_tongue_winking_eye:

The variable varCentralOut isn’t declared in the code that you’ve shared here. It must be declared somewhere, otherwise your code wouldn’t compile, so there must be more code that you’ve not shared.

That makes it difficult for people to work-out what’s going wrong with your code/logic. Try sharing your whole sketch.

Pete.

Shouldn’t this be:

BLYNK_WRITE(V21) //Function Mode 1
{
int Mode1 = param.asInt(); //Get value from Button V21
if (Mode1 == 1) { //if it is HIGH
varMode1++; //count the flag “varMode1” ++
}
if (varMode1 == 2) { //if the Button get pushed a second one
varMode1= 0; //flag “varCentralOut” is again 0
}

As Mode1 will never be 2 if the button is sending 1 and 0

No mode1 is only the status from the button. I know it can be only 1 or 0… if this button is clicked I sai to the variable varMode1 count on. By the first click it counts to 1. By the second click it counts to 2, but immediatelly after I say if varMode1 == 2, varMode1 = 0. So it can begin from new

Yes, but your if statement is looking for Mode1 to be equal to 2.

No, it says

Or am I missing something here…

Sorry there was an error by my side, that happens if you code on blynk website. :wink:
But also if I write it like you, and also in my sketch it does not work. My question: How to compare two variables? There must be the error because in serial monitor I see if I click on Button from Mode 1 that varMode1 == 1 and the same also with the Button centralOut. But I never get the varLedOutput == 1. It remains usually 0. Tomorrow I will copy my original sketch here. :slight_smile:
Thx. in the meantime

I checked your past posts and you are using the wrong character in code formatting…

Do not use the tilde character, use the backtick character… same key, different character :stuck_out_tongue_winking_eye: And don’t forget the cpp at the beginning.

Blynk - FTFC