//developed by swastik chakraborty
//Include the library files
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#define BLYNK_AUTH_TOKEN "" // enter your auth token
int lastState = 0;
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = ""; // Enter your Wifi Username
char pass[] = ""; // wifi password
BlynkTimer timer;
int InPin = 5; // the pin where out of IR is connected (d1)
int sensorValue = 0; // value read from the sensor
int steps = 0;
void setup() {
pinMode(InPin, INPUT);
Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
Serial.begin(9600);
timer.setInterval(100L, ultrasonic);
}
void infrared() {
// read the analog in value:
int currentState = digitalRead(InPin);
Serial.println(currentState);
delay(5);
if(lastState==1 && currentState==0)
{
steps = steps + 1;
int distance = steps*1.15; //average distance in metres.
Blynk.virtualWrite(V0, steps);
Serial.println(steps);
Blynk.virtualWrite(V1, distance);
}
else
{
steps = steps;
int distance = steps*1.15;
Serial.println(steps);
Blynk.virtualWrite(V0, steps);
Blynk.virtualWrite(V1, distance);
}
lastState = currentState;
}
void loop() {
Blynk.run();//Run the Blynk library
timer.run();//Run the Blynk timer
}
Comments