- Nodemcu - ESP8266
- IR Sensor - MH Sensor Series
- Arduino IDE
- C++
- Blynk Version: 1.0.1
- Android Phone
- Blynk IoT app
I currently have a button widget that is linked to a datastream (IR_Sensor) to VP5.
Button widget → Datastream (IR_Sensor) → IR_Sensor (virtual pin 5).
While in the app, when I press the button widget it clears the tallied number and shows “0”, but when I pass my hand by the sensor again, the count continues at the last number counted.
Here is a link to the video on imgur that shows how its acting: https://imgur.com/a/NS7JxFq
Would anyone know if this is possible, or what am I missing to link everything correctly?
Cheers
#define BLYNK_TEMPLATE_ID "TMPLU751iNIy"
#define BLYNK_DEVICE_NAME "Bottle Counter Final"
#define BLYNK_AUTH_TOKEN "X"
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
char ssid[] = "X";
char pass[] = "X";
//char ssid[] = "X";
//char pass[] = "";
char auth[] = "X";
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SPI.h>
int sensorData = D1;
int counter = 0;
boolean state = true;
int count = 0;
BlynkTimer timer;
void myTimerEvent(){
sensorData = analogRead(D1);
if (sensorData == LOW){
counter++ ;
state = false;
Blynk.virtualWrite(D1, counter);
}
if (sensorData){
state = true;
}
}
void setup(){
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
timer.setInterval( 1000L , myTimerEvent);
}
void loop(){
Blynk.run(); // all the Blynk magic happens here
timer.run(); // BlynkTimer is working...
}