Skip to content

Instantly share code, notes, and snippets.

@yemreeke
Created December 20, 2020 16:04
Show Gist options
  • Save yemreeke/940fd711d01b9512379c2202c96ed1b7 to your computer and use it in GitHub Desktop.
Save yemreeke/940fd711d01b9512379c2202c96ed1b7 to your computer and use it in GitHub Desktop.
int echoPin = 6,trigPin = 7; //HC-SR04 Pinleri
int maksimum=100,minumum =3; //3-100 cm Arası Ölçüm
void setup() {
pinMode(trigPin, OUTPUT); //Çıkış Tanımladık
pinMode(echoPin, INPUT); //Giriş Tanımladık
Serial.begin(9600); // Haberleşme Başlattık
}
void loop() {
digitalWrite(trigPin,HIGH); //Enerji Verdik
delayMicroseconds(10);//10 Mikrosaniye Bekledik
digitalWrite(trigPin,LOW); //Enerji Kestik
unsigned long sure = pulseIn(echoPin, HIGH); //Süre Hesapladık
double toplamYol = (double)sure*0.034; //Toplam Yol
int mesafe = toplamYol/2; // Mesafeyi Bulduk
if(mesafe>minumum && mesafe<maksimum){ //Max Min Arasındaysa
Serial.print("Mesafe: "); //Ekrana Yazdırdık
Serial.print(mesafe);
Serial.println("cm");
}
delay(1000); // Diğer Ölçüm İçin 1 Sn Bekledik
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment