Arduino Uno R3.
/// @brief Measure distance.
/// @return Distance.
int dokhoangcach()
{
int kc;
long tg;
digitalWrite(TRIG, LOW);
delayMicroseconds(2);
digitalWrite(TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG, LOW);
tg = pulseIn(ECHO, HIGH, 3600000);
kc = int(tg / 2 / 29.412);
return kc;
}