Advertisement
Guest User

Untitled

a guest
Jan 21st, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.60 KB | None | 0 0
  1. #define BLYNK_PRINT Serial
  2.  
  3.  
  4. #include <ESP8266WiFi.h>
  5. #include <BlynkSimpleEsp8266.h>
  6. #define TRIGGERPIN D1
  7. #define ECHOPIN    D2
  8. #define verde   D7
  9. #define azzurra D5
  10. #define rosso D6
  11.  
  12.  
  13. char auth[] = "zox3YpV6f4ZphvoU5lDERX6T6YbZlXXl";
  14.  
  15. // Your WiFi credentials.
  16. // Set password to "" for open networks.
  17. char ssid[] = "luna_notte";
  18. char pass[] = "casaluna";
  19.  
  20. void setup()
  21. {
  22.   // Debug console
  23.   Serial.begin(9600);
  24.   pinMode(verde, OUTPUT);
  25.   pinMode(azzurra, OUTPUT);
  26.   pinMode(rosso, OUTPUT);
  27.   pinMode(TRIGGERPIN, OUTPUT);
  28.   pinMode(ECHOPIN, INPUT);
  29.   Blynk.begin(auth, ssid, pass);
  30.   // You can also specify server:
  31.   //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 8442);
  32.   //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8442);
  33.  
  34.  
  35. }
  36.  
  37. void loop()
  38. {
  39.   long duration, distance;
  40.   digitalWrite(TRIGGERPIN, LOW);  
  41.   delayMicroseconds(3);
  42.  
  43.   digitalWrite(TRIGGERPIN, HIGH);
  44.   delayMicroseconds(12);
  45.  
  46.   digitalWrite(TRIGGERPIN, LOW);
  47.   duration = pulseIn(ECHOPIN, HIGH);
  48.   distance = (duration/2) / 29.1;
  49.   Serial.print(distance);
  50.   Serial.println("Cm");
  51.  
  52.   if (distance<32) //LUCE VERDE
  53.   {
  54.   digitalWrite(verde, 125);
  55.   digitalWrite(azzurra, 0);
  56.   digitalWrite(rosso, 0);
  57.   }
  58.   else //LUCE GIALLA
  59.   if  ((distance<50) and (distance>32)) {
  60.     digitalWrite(azzurra, 0);
  61.     digitalWrite(verde, 125);
  62.     digitalWrite(rosso, 100);
  63.   }
  64.   else
  65.   if (distance>50) //LUCE ROSSA
  66.   {
  67.     digitalWrite(rosso, 125);
  68.     digitalWrite(verde, 0);
  69.     digitalWrite(azzurra, 0);
  70.     }
  71.  
  72.   Blynk.virtualWrite (V0, distance);
  73.   Blynk.run();
  74.  
  75.   delay(3500);
  76.  
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement