0PricingLogin
Arduino & IoT Academy · Lesson

pulseIn to Time the Echo

Measure the echo pulse and convert to cm.

Fire the Pulse

To take a reading you first send a clean trigger pulse. The HC-SR04 expects a short HIGH on Trig to start a new measurement.

Start From Clean

Set Trig LOW for a couple of microseconds first. This clears any leftover state so your trigger pulse is crisp and reliable.

digitalWrite(trigPin, LOW);
delayMicroseconds(2);

All lessons in this course

  1. How Ultrasonic Ranging Works
  2. Trigger & Echo Wiring
  3. pulseIn to Time the Echo
  4. Build a Proximity Alarm
← Back to Arduino & IoT Academy