Devices & Components
Infrared Module (Generic)
NodeMCU ESP8266 Breakout Board
Software & Tools
Blynk
Arduino IDE
Project description
Code
Code
arduino
1//Include the library files 2#define BLYNK_PRINT Serial 3#include <ESP8266WiFi.h> 4#include <BlynkSimpleEsp8266.h> 5#define BLYNK_AUTH_TOKEN "" // enter your auth token 6int lastState = 0; 7 8char auth[] = BLYNK_AUTH_TOKEN; 9char ssid[] = ""; // Enter your Wifi Username 10char pass[] = ""; // wifi password 11BlynkTimer timer; 12int InPin = 5; // the pin where out of IR is connected (d1) 13int sensorValue = 0; // value read from the sensor 14int steps = 0; 15void setup() { 16 pinMode(InPin, INPUT); 17 Blynk.begin(auth, ssid, pass, "blynk.cloud", 80); 18 Serial.begin(9600); 19 timer.setInterval(100L, ultrasonic); 20} 21 22void ultrasonic() { 23 // read the analog in value: 24int currentState = digitalRead(InPin); 25 Serial.println(currentState); 26 delay(5); 27 if(lastState==1 && currentState==0) 28 { 29 steps = steps + 1; 30 int distance = steps*1.15; //average distance in metres. 31 32 Blynk.virtualWrite(V0, steps); 33 34Serial.println(steps); 35 Blynk.virtualWrite(V1, distance); 36 } 37 else 38 { 39 steps = steps; 40 int distance = steps*1.15; 41 42Serial.println(steps); 43 Blynk.virtualWrite(V0, steps); 44 Blynk.virtualWrite(V1, distance); 45 } 46 lastState = currentState; 47} 48 49void loop() { 50 Blynk.run();//Run the Blynk library 51 timer.run();//Run the Blynk timer 52}
Downloadable files
wiring
wiring

Comments
Only logged in users can leave comments