Last active
September 19, 2019 07:32
-
-
Save RobolinkTeknoloji/46810253133f1faa75475b0ddf5f2e5c to your computer and use it in GitHub Desktop.
HC-SR04 ile Park Sensörü Yapımı
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define trig_Pin 8 | |
#define echo_Pin 9 | |
#define buzzer_Pin 10 | |
long mesafe = 0; | |
long sure = 0; | |
int gosterge = 0; | |
void setup() { | |
for (int i = 2; i< 7; i++) | |
{ | |
pinMode(i, OUTPUT); | |
} | |
pinMode(trig_Pin, OUTPUT); | |
pinMode(echo_Pin, INPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
buzzer_uyari(mesafe_olc() * 8); | |
gosterge = mesafe_olc() / 10 + 1; | |
for (int i = 7; i > gosterge; i--) | |
{ | |
digitalWrite(i, HIGH); | |
} | |
for (int i = gosterge; i >= 2; i--) | |
{ | |
digitalWrite(i, LOW); | |
} | |
} | |
int mesafe_olc() { | |
digitalWrite(trig_Pin, HIGH); | |
delayMicroseconds(1000); | |
digitalWrite(trig_Pin, LOW); | |
sure = pulseIn(echo_Pin, HIGH); | |
mesafe = (sure / 29.1) / 2; | |
if (mesafe > 50) | |
mesafe = 50; | |
Serial.print("Olculen Mesafe = "); | |
Serial.print(mesafe); | |
Serial.println(" cm "); | |
return mesafe; | |
} | |
void buzzer_uyari(int bekle) | |
{ | |
tone(buzzer_Pin, 500); | |
delay(bekle); | |
noTone(buzzer_Pin); | |
delay(bekle); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment