Hi all,
I know this is not a Blynk forum, but I have seen very good and helpful responses to other Blynk related question here, so I thought I´ll give it a shot.
I´m using a Wemos D1 Mini with A TTP223 ( very simple touchsensor) to send a notification over Blynk, when the button was touched.
That works quite well, but it is hardcoded and I would like to realize this over the app itself with sending the state of the sensor (1/0) to a virtual PIN and then use this virtual PIN in Blynk.
This is the working code with the "hardcoded notification"
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "XXX";
char ssid[] = "XXX";
char pass[] = "XXX";
int sensorPin = 16; // Input pin for the Touch Sensor
int sensorValue = 0; // Variable to store the value coming from the touch sensor
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void loop()
{
Blynk.run();
sensorValue = digitalRead(sensorPin);
if (sensorValue == 1) {
Blynk.notify("Touchbutton touched"); //this is the hardcoded part
}
}
Now I would like to write the "sensorValue" into a virtual PIN and tried the following, but it didnt work: ( I marked the changes bold) I´m pretty sure it is obvious for someone whats wrong here.
The "try and error" code below is not throwing any errors, it just doesn't work, when I set a notification with the eventor modul in Blynk with Virtual PIN 1 as trigger
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
BlynkTimer timer;
char auth[] = "XXX";
char ssid[] = "XXX";
char pass[] = "XXX";
int sensorPin = 16; // Input pin for the Touch Sensor
int sensorValue = 0; // Variable to store the value coming from the flame sensor
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
// Setup a function to be called every second
timer.setInterval(1000L, sendTouch);
}
void sendTouch()
{
Serial.println(sensorValue);
Blynk.virtualWrite(V1, sensorValue);
}
that's a lot of communication for something that will just send the same value most of the time...
I would only send it if it has changed, not every second
True,
I re-used the code from a temp sensor, where it makes perfect sense, to receive data every second. But here not so much.
From my research it sounds like I should use something like BLYNK_WRITE
@J-M-L --> Thanks for the example I need to have a look into this and see if I can make it work for me.
@gfvalvo --> correct, it just slipped through while copying it, but it worked with adding the sensor value, as I described before. (Of course with the loop part
So now I´m trying to avoid sending so much data and use the BLYNK_WRITE in a similar like shown here:
Alright, so this is the part which (in my eyes) would be ok for a temperatur sensor (then including other libraries) to read and forward the data to Virtual PIN 1 (which was my main goal here), however I used it with the touchsensor and therefore changed the 1000ms to 100, to make my touchsensor reacts faster:
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
BlynkTimer timer;
char auth[] = "X";
char ssid[] = "X";
char pass[] = "X";
int sensorPin = 16; // Input pin for the Touch Sensor
int sensorValue = 0; // Variable to store the value coming from the touch sensor
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
timer.setInterval(100L, sendTouch); // Setup a function to be called every 100 Millisecond
}
void sendTouch()
{
Serial.println(sensorValue);
sensorValue = digitalRead(sensorPin);
Blynk.virtualWrite(V1, sensorValue);
}
}
void loop()
{
Blynk.run();
timer.run();
}
The issues with sending to many values for nothing ( I just wanna know, when the button has been touched) I tried to resolve with this code, but it is more a very poor try to implement the BLYNK_WRITE in here: Also here, no error, but also no success, the BLYNK app is not receiving any value.
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "X";
char ssid[] = "x";
char pass[] = "x";
int sensorPin = 16; // Input pin for the Touch Sensor
int sensorValue = 0; // Variable to store the value coming from the touch sensor
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
}
void sendTouch()
{
Serial.println(sensorValue);
sensorValue = digitalRead(sensorPin);
}
BLYNK_READ(V1)
{
if(sensorValue== HIGH)
{
Blynk.virtualWrite(1, HIGH);
}
else
{
Blynk.virtualWrite(1, LOW);
}
}
void loop()
{
Blynk.run();
}