In yesterday’s test, you realised a simple control of an LED using the Blynk app. Today you’ll see that the control works in both directions. The push-button switch behind today’s door really comes in handy for this purpose. With it, you can expand yesterday’s circuit as follows:

Der neue Aufbau mit Tastschalter an D7
The new layout with push-button switch at D7

You can scan the interface for today here:

Der QR-Code von Tag 6
The QR code for Day 6 http://tinyurl.com/z99macn

In the Blynk app, there is a virtual currency labelled Energy. It prevents you from using very extensive projects or many smaller projects in the app at the same time. For you, that means that you may have to delete old projects starting on Day 8. But you can save your adapted project by creating a QR code and saving it somewhere.

As always, you’ll find today’s programme here:

The sketch: A16_P06_Blynk2_Button.ino
/*
Blynk 2: Button
Change ssid, password and token
*/

char ssid[] = "YourSSID";
char password[] = "YourPassword";
char token[] = "YourToken";

//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266_SoftSer.h>
#include <BlynkSimpleShieldEsp8266_SoftSer.h>

#define BUTTON 7

// Set NanoESP Serial object
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(11, 12); // RX, TX

ESP8266 wifi(EspSerial);

void setup()
{
  // Set console baud rate
  Serial.begin(19200);
  EspSerial.begin(19200);

  Blynk.begin(token, wifi, ssid, password);

  pinMode(BUTTON, INPUT_PULLUP);
}

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

boolean currState = false ;

void checkPin()
{
  if (!digitalRead(BUTTON))
  {
    //toggle state
    currState = !currState;
    Blynk.virtualWrite(V0, currState);

    //Wait till button is released
    while (!digitalRead(BUTTON)){  
    }
  }
}

(The former Arduino Create embed is no longer available; the code is taken from the download of all sketches.)

Today, too, the WLAN data and the AUTH TOKEN of the project must be transferred into the programme. Each project has its own token, so you have to have the code re-sent or transfer it into the programme manually. After you start the interface with the Play button, you can again cause the LED on the breadboard to light up by tapping on the button. But you also see a change in the app if you push the button on the breadboard. Thus, the connection is possible in both directions.