Submit

19 / 20

Ultrasonic radar

Sweep a distance sensor and plot a detected target by angle.

Run this experiment →
ESP32 teaching illustration with module, GPIO headers and lesson components

Why it’s here

Place a target at an angle and watch the sweep discover it.

How it works

Sweep a distance sensor and plot a detected target by angle. No. It is an ultrasonic scanner. Servo angle and echo distance provide a polar coordinate. This guided model targets the original ESP32 and Arduino-ESP32 3.x; radio, acoustics, loads and mechanics are simplified.

Try it

  1. Open this experiment
  2. Place a target at an angle and watch the sweep discover it.

Connections

  • GPIO 5 / 19 — TRIG / ECHO
  • GPIO 18 — Scanning servo

Example sketch

#include <ESP32Servo.h>
Servo scanner; int angle=0, direction=1;

void setup() {
  Serial.begin(115200);
  pinMode(5, OUTPUT); pinMode(19, INPUT);
  scanner.setPeriodHertz(50); scanner.attach(18, 500, 2400);
}

void loop() {
  scanner.write(angle); delay(30);
  digitalWrite(5, LOW); delayMicroseconds(2);
  digitalWrite(5, HIGH); delayMicroseconds(10);
  digitalWrite(5, LOW);
  unsigned long echo = pulseIn(19, HIGH, 30000);
  float cm = echo ? echo / 58.0f : -1;
  Serial.printf("%d,%.1f\n", angle, cm);
  angle += direction;
  if (angle >= 180 || angle <= 0) direction = -direction;
}

Check your understanding

Is this radio radar?

Show the answer

No. It is an ultrasonic scanner. Servo angle and echo distance provide a polar coordinate.

Sources

Arduino-ESP32 ↗ · GPIO reference ↗

MAKE A THOUGHTFUL CHOICE

Your shortlist, side by side.

Pricing models are indicative. Check each official website for current plans and limits.