A little curiosity. A whole lot of making.Robotics, CNC & connected ideas
robodatech.
Arduino sample library

Ultrasonic Distance 23

Measure obstacle distance with trigger and echo timing.

Open in compiler →

Source code and build tools are available in the protected platform workspace.

How it works

Measure distance with an ultrasonic trigger/echo module.

  1. Wire TRIG and ECHO to the listed pins.
  2. Send a short trigger pulse.
  3. Measure echo pulse time with pulseIn().
  4. Convert travel time into distance in centimeters.

Connections

PinConnect toNote
D2HC-SR04 TRIGSends a 10 microsecond pulse.
D4HC-SR04 ECHO3.3V boards need level shifting for 5V echo modules.

Good ideas start here.

Free robotics lessons, CNC build notes and product updates. Confirm your email to join. Unsubscribe anytime.