Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. #include <NewPing.h>
  2.  
  3. #define TRIGGER_PIN 3 // Mesafe sensörünün TRIGGER ayağı
  4. #define ECHO_PIN 4 // Mesafe sensörünün ECHO ayağı
  5. #define MAX_DISTANCE 200 // Maksimum mesafe
  6.  
  7. #define buzzPin 11
  8.  
  9. NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing ile mesafe sensörünü kuruyoruz
  10.  
  11.  
  12. void setup() {
  13. Serial.begin(115200); // Sonuçları monitör 115200 baud da göreceğiz.
  14.  
  15. pinMode(buzzPin, OUTPUT);
  16. pinMode(7, OUTPUT); //led
  17. }
  18.  
  19. void loop() {
  20. delay(100); // Mesafe bilgilerini 50ms (yaklaşık 20 ping/saniye) En kısa 29ms olabilir.
  21. unsigned int uS = sonar.ping(); // Ping gönderip, mesafeyi milimetre cinsinden alıyoruz.
  22. Serial.print("Mesafe: "); // Monitor ekranına mesafeleri yazdıracağız.
  23. Serial.print(uS / US_ROUNDTRIP_CM); // mm'yi >> cm'ye çeviriyoruz.
  24. Serial.println("cm");
  25.  
  26. if((uS / US_ROUNDTRIP_CM)<100) // 100 cm'den yakın cisim tespit edildiğinde, alarm çalışıyor.
  27. {
  28. Serial.println("Cisim algılandı.");
  29. for(int i=0;i<10;i++)
  30. {
  31.  
  32. digitalWrite(buzzPin,HIGH);
  33. digitalWrite(7,HIGH);
  34. delay(100);
  35. digitalWrite(buzzPin, LOW);
  36. digitalWrite(7,LOW);
  37. delay(10);
  38. }
  39. }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement