Advertisement
Leo1502

Arduino code 01

May 20th, 2023 (edited)
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 1.27 KB | Source Code | 0 0
  1. #define echoPin 12
  2. #define trigPin 1
  3.  
  4. #define BLYNK_TEMPLATE_ID ""
  5. #define BLYNK_TEMPLATE_NAME ""
  6. #define BLYNK_AUTH_TOKEN ""
  7.  
  8. #define BLYNK_PRINT Serial
  9.  
  10. #include <WiFi.h>
  11. #include <WiFiClient.h>
  12. #include <BlynkSimpleEsp32.h>
  13.  
  14. BlynkTimer timer;
  15.  
  16. char auth[] = BLYNK_AUTH_TOKEN;
  17. char ssid[] = "Samsung Galaxy S20";
  18. char pass[] = "123456789!";
  19.  
  20. long duration;
  21. int distance;
  22. int binLevel = 0;
  23. int tiltSenzor = 13;
  24.  
  25. int tilt = digitalRead(tiltSenzor);
  26.  
  27. void ultrazvuk()
  28. {
  29.   digitalWrite(trigPin, HIGH);
  30.   delayMicroseconds(10);
  31.   digitalWrite(trigPin, LOW);
  32.   delayMicroseconds(2);
  33.  
  34.   duration = pulseIn(echoPin, HIGH);
  35.   distance = duration * 0.034 / 2;
  36.  
  37.   binLevel = map(distance, 21, 0, 0, 100); // ADJUST BIN HEIGHT HERE
  38.   Blynk.virtualWrite(V0, distance);
  39.   Blynk.virtualWrite(V1, binLevel);
  40. }
  41.  
  42. void setup() {
  43.   //Serial.begin(115200);
  44.   pinMode(trigPin, OUTPUT);
  45.   pinMode(echoPin, INPUT);
  46.   pinMode(tiltSenzor, INPUT);
  47.   Blynk.begin(auth, ssid, pass);
  48.   delay(2000);
  49.   timer.setInterval(30 * 60 * 10000L, ultrazvuk);
  50. }
  51.  
  52. void loop() {
  53.   Blynk.run();
  54.   timer.run();
  55.  
  56.   if(tilt != digitalRead(tiltSenzor)){
  57.     tilt = digitalRead(tiltSenzor);
  58.     delay(60000L);
  59.     ultrazvuk();
  60.   }
  61.  
  62.   //Serial.println(String(distance) + " cm");
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement