Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define echoPin 12
- #define trigPin 1
- #define BLYNK_TEMPLATE_ID ""
- #define BLYNK_TEMPLATE_NAME ""
- #define BLYNK_AUTH_TOKEN ""
- #define BLYNK_PRINT Serial
- #include <WiFi.h>
- #include <WiFiClient.h>
- #include <BlynkSimpleEsp32.h>
- BlynkTimer timer;
- char auth[] = BLYNK_AUTH_TOKEN;
- char ssid[] = "Samsung Galaxy S20";
- char pass[] = "123456789!";
- long duration;
- int distance;
- int binLevel = 0;
- int tiltSenzor = 13;
- int tilt = digitalRead(tiltSenzor);
- void ultrazvuk()
- {
- digitalWrite(trigPin, HIGH);
- delayMicroseconds(10);
- digitalWrite(trigPin, LOW);
- delayMicroseconds(2);
- duration = pulseIn(echoPin, HIGH);
- distance = duration * 0.034 / 2;
- binLevel = map(distance, 21, 0, 0, 100); // ADJUST BIN HEIGHT HERE
- Blynk.virtualWrite(V0, distance);
- Blynk.virtualWrite(V1, binLevel);
- }
- void setup() {
- //Serial.begin(115200);
- pinMode(trigPin, OUTPUT);
- pinMode(echoPin, INPUT);
- pinMode(tiltSenzor, INPUT);
- Blynk.begin(auth, ssid, pass);
- delay(2000);
- timer.setInterval(30 * 60 * 10000L, ultrazvuk);
- }
- void loop() {
- Blynk.run();
- timer.run();
- if(tilt != digitalRead(tiltSenzor)){
- tilt = digitalRead(tiltSenzor);
- delay(60000L);
- ultrazvuk();
- }
- //Serial.println(String(distance) + " cm");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement