#define TRIG_PIN 9  // Trig pinning raqami
#define ECHO_PIN 10 // Echo pinning raqami

void setup() {
  Serial.begin(9600); // Konsolga chiqishni boshlash
  
  pinMode(TRIG_PIN, OUTPUT); // Trig pinini chiqish sifatida sozlash
  pinMode(ECHO_PIN, INPUT);  // Echo pinini kiritish sifatida sozlash
}
int duration=0;
void loop() {
  long distance;  // Masofani saqlash uchun long tipida o'zgaruvchi
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  
  digitalWrite(TRIG_PIN, HIGH); // Trig pinini 10 mikrosoniya (us)gacha yuqori hisoblab, keyin pastga qaytarish
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  
  duration = pulseIn(ECHO_PIN, HIGH); // Echo pinida ulanilgan signalning davomati
  distance = (duration * 0.0343) / 2; // Ultratovush datchigi tomonidan yetkazilgan signalning yo'qotish va qaytib kelish vaqtiga bog'liq masofa (cm)

  Serial.print("Masofa: ");
  Serial.print(distance);
  Serial.println(" sm");

  delay(1000); // To'xtash
}