ULTRASONIC SENSOR

HC-SR04

To get TURL-X to see we use an ultrasonic sensor called the HC-SR04.
The HC-SR04 is a sensor that measures distance to objects without touching them — like a tiny radar.
The HC-SR04 is basically a mini bat “eye”:
  • It sends out a quick, silent ‘squeak’ (ultrasonic sound wave — way too high-pitched for humans or dogs to hear).
  • The sound bounces off whatever is in front (a wall, your hand, a box, etc.) like an echo.
  • The sensor listens for that echo coming back.
  • It times how long the sound took to go there and back.
  • Since sound travels at a known speed (about 343 meters per second in normal air), the Arduino can do quick math:
    Distance = (time for round trip × speed of sound) ÷ 2 (Divide by 2 because the sound went to the object and back.)

So if the echo comes back super fast → object is close.
If it takes longer → object is farther away.
The sensor can measure from about 2 cm (almost touching) up to 400 cm (about 4 meters), with pretty good accuracy (±3 mm).

The HC-SR04 has four pins:

VCC → This is the power pin. You connect it to the Arduino’s 5V pin. It gives the sensor the electricity it needs to work.
GND (Ground) → This is the return path for the electricity. Everything that gets power through VCC has to come back through GND to complete the circle. Without it, no power flows — it’s like the other half of the plug.
Trig (Trigger) → This is the ‘go!’ button. The Arduino sends a quick HIGH signal (like a short poke) to the Trig pin for about 10 microseconds. That tells the sensor: ‘Shoot your ultrasonic sound wave right now!’ So Trig is how the Arduino says ‘Send the sound out!’
Echo → This is the ‘I’m back!’ signal. After the sound wave bounces off something and returns, the sensor sets the Echo pin HIGH while the sound is traveling out and back, then sets it LOW when the echo arrives. The Arduino measures how long Echo stayed HIGH (in microseconds), and that’s what it uses to calculate the distance. So Echo tells the Arduino: ‘The sound just came back — here’s how long the trip took!’