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

How to control esp8266 and led with physical and blynk button?


#1

how to control esp8266 and led with physical and blynk app button. im using esp8266 which has only 2 gpio pins GPIO0 and GPIO2. i want to turn on and off from both button. please help me im new to blynk.

this code i found in community can i modify this code to do what i want?

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "xxxxx"; //insert here your token generated by Blynk


int relay1 = 12;
int button1 = 13;
int relayVButton = 0;

boolean relayState = 1;
boolean buttonState = 0;
WidgetLED led1(11); //virtual led 

void setup() {
     Serial.begin(115200); // See the connection status in Serial Monitor
 Blynk.begin(auth, "ssid", "password"); //insert here your SSID and password
while (Blynk.connect() == false) {
 buttonState = digitalRead (button1);
  if (buttonState > 0){
    relayState = !relayState;
      } 
      digitalWrite(relay1, relayState);
    
      delay(500);
  }
  
pinMode(relay1, OUTPUT);
pinMode(button1,INPUT);

}

BLYNK_WRITE(V5)
{
  // Get the state of the VButton
  relayVButton = param.asInt();
  
}


void loop() {
    Blynk.run();
  // put your main code here, to run repeatedly:
  buttonState = digitalRead (button1);
  if (buttonState > 0 || relayVButton > 0){
    relayState = !relayState;
      } 
      digitalWrite(relay1, relayState);
    
      delay(500);


//----------------button virtual led---------------
  byte inp = digitalRead(relay1);
   
  if (inp == HIGH)
  {
   led1.on();
  }
   else
   led1.off();
 }
1 Reply 

#2

We don’t know… can you? :wink:

First, please edit your post and format the code so that it will show properly, as per: Welcome to Blynk

Then, a better question would be like… “I have taken this code and tried this, that or the other, but had XYZ result, any suggestions?” (and show examples). Basically, read the docs, study other arduino learning sites and try to do it yourself first, don’t just ask how.


#3

@Gunner sorry about that. im new to blynk community so dont know much about it. i tried about that code but i was able to control through app but. it dent work with the button… im using esp8266-01 it has only 2 gpio pins… could you please guide me to what i want to make?


#4

The guidance is already here, on this website. The community is here to assist with specific questions and issues, but you are not likely to find someone to guide you, without you showing some progress first.

Go to http://examples.blynk.cc/ and try a bunch of the demo codes, find what works and dig into the code. Also check into the http://docs.blynk.cc/ page for further details. Then when you have a better idea of what to ask help for… we are here. :slight_smile:

PS, thanks for editing your first post :+1: