DALE logoDALE

EXPERIMENT 05 • BUILD SOMETHING

📡 Ultrasonic Distance Alarm

Distance → Compare → Buzzer/RGB

Build on what you already know and add one more DALE idea to the project.

Intermediate~15 minutes

What You'll Build

A proximity alarm that watches real distance. When an object comes closer than your chosen threshold, DALE activates a buzzer, an RGB warning, or both.

What You'll Need

  • DALE with ESP32-S3
  • HC-SR04 ultrasonic sensor
  • Buzzer
  • RGB LED (optional)
  • Required interface wiring/components for your HC-SR04 setup
  • Jumper wires
HC-SR04 ultrasonic distance sensor
HC-SR04 ultrasonic distance sensor

What You'll Learn

  • How a sensor becomes useful numerical data.
  • How a Compare block turns a Number into TRUE/FALSE.
  • How a threshold creates a real-world decision.
  • How one decision can drive multiple warning outputs.

Wire It

Configure the HC-SR04 module in DALE and use the Trigger/Echo GPIOs assigned to it. Wire the buzzer/RGB to their configured outputs.

HC-SR04 → VCC, GND, TRIG GPIO, ECHO GPIO
Buzzer/RGB → configured DALE output GPIO(s)

Use the safe voltage/interface arrangement specified for your DALE HC-SR04 connection; ESP32-S3 GPIO logic is 3.3 V.

Try the Sensor First

Open DALE's Ultrasonic/Radar tools and move an object toward and away from the sensor. Confirm that the distance changes correctly before adding the alarm.

Sensor → decision → action. This three-part pattern appears everywhere in automation and embedded systems.

Build It in Logic Builder

Add the Ultrasonic block, a Number block containing your alarm distance, a Compare block, and a Buzzer or RGB output. Configure Compare so the alarm becomes TRUE when the measured distance is less than your threshold.

Example: Distance < 20 cm → alarm TRUE. Move an object through the threshold and watch the output change.

What Just Happened?

The ultrasonic module measures distance, but a measurement by itself does not make a decision. Compare gives that number meaning: Is the object close enough to matter? The Boolean result can then control any compatible DALE output.

BUILD IT VISUALLY. SEE THE REAL CODE.

Show Me The Code

Find the generated distance value, your threshold value, and the comparison between them. Then follow the Boolean result to the buzzer/RGB output. The visual blocks and the code should now tell the same story.

Try This Next

Create two distance thresholds: a warning zone and a danger zone. Use different RGB behavior or sound for each. You are beginning to turn one sensor into multiple states.