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

How to connect a push button with the blynk app and esp8266

#21

I don’t think anyone here is going to write the code for you. You have been given the “tools” to fix the problem yourself.

If you still do not understand, then you need to take some time and do a little research.

Figure out how to solve the problem without BLYNK. Then once you have that part taken care of, try working BLYNK back into the mix.

1 Like

#22

We all started out “new to this” and worked hard to teach ourselves… with guidance from others. You have been provided the guidance a few times, but so far have been unable to follow even the simplest process of formatting your posted code.

We are not here to do your coding for you… Please stop begging and start trying.

2 Likes

#23

I don’t think I could ever have coped with being a teacher, I’d want to whack the students around the head if they didn’t ‘get it’, and apparently that’s not been allowed in schools in the UK for at least the last 60 years (with the possible exception of Catholic schools) :roll_eyes:

Glad I was able to help you without having to resort to using Blynk.violenceVirtual() :slightly_smiling_face:

Pete.

1 Like

#24

@Rick_Maity as others have pointed-out, we don’t teach basic C++ programming here, and it appears that’s what you need to learn.
A few hours of watching Youtube videos, or doing online tutorials, followed by a few more hours of experimentation should get you to the point where you’re ready to start answering your own questions.
The Blynk Sketch Builder thatI linked to earlier is a great resource and one that you should use to help you learn how to structure code so that it works well with Blynk.

When you’ve done your ‘apprenticeship’ in C++ then the questions you ask will be more focussed, and you’ll have a better understanding of the answers that you are given. Until you get to that point it’s difficult to help your to help yourself.

Pete.

1 Like

#25

[quote=“PeteKnight, post:24, topic:37176”]
A few hours of watching Youtube videos
[/quote] Some of us it takes years :woozy_face:

0 Likes

#26

thank you everyone!!!

0 Likes

#27

another last question can we use a two way switch in esp8266 without programming ?

0 Likes

#28

I think you are misunderstanding the way to properly use a microcontroller :wink:

2 Likes

#29
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>         //https://github.com/tzapu/WiFiManager
#include <EEPROM.h>

const int ledPin = 7;
const int btnPin = 8;

BlynkTimer timer;
void checkPhysicalButton();

int ledState = LOW;
int btnState = HIGH;
BLYNK_CONNECTED() {
 Blynk.syncVirtual(V2);
}
BLYNK_WRITE(V2) {
 ledState = param.asInt();
 digitalWrite(ledPin, ledState);
}

void checkPhysicalButton()
{
 if (digitalRead(btnPin) == LOW) {
   // btnState is used to avoid sequential toggles
   if (btnState != LOW) {

     // Toggle LED state
     ledState = !ledState;
     digitalWrite(ledPin, ledState);

     // Update Button Widget
     Blynk.virtualWrite(V2, ledState);
   }
   btnState = LOW;
 } else {
   btnState = HIGH;
 }
}

void setup()
{
 EEPROM.begin(512);
 Serial.begin(9600);
 WiFiManager wifiManager;
 wifiManager.autoConnect("NodeMCU");
 pinMode(ledPin, OUTPUT);
 pinMode(btnPin, INPUT_PULLUP);
 digitalWrite(ledPin, ledState);
 timer.setInterval(100L, checkPhysicalButton);
}

void loop()
{
 Blynk.run();
 timer.run();
}
0 Likes

#30

@PeteKnight will give rise to the same output what i wanted?

0 Likes

#31

@PeteKnight will it work the same way sir ?

0 Likes

#32

I have no idea what it is you’re trying to achieve, so I can’t answer your question.
The easiest way to answer your own question is to try it and see.

Pete.

0 Likes