Build Obstacle-Warning Glasses

Simulate obstacle-warning glasses with ESP32 sensing, alerts, and filtering.

Introduction

30 Second Summary

A warning that arrives too late can be as unhelpful as no warning at all. Any wearable obstacle idea needs to turn distance into feedback that changes quickly enough to notice.

In this project, you will use Claude Code to build a browser-based Wokwi prototype with an ESP32 and HC-SR04 sensor. The finished recording shows warnings reacting to distance while ignoring one false reading.

What You'll Build

You'll move a simulated obstacle closer while its warning shifts from silence to pulsing alerts to a steady danger signal.

By the end of this project, you'll have:

  • A live distance demo where you move the HC-SR04 slider while centimetre readings update in the Serial Monitor.
  • A recorded four-level warning demo with synchronized buzzer and LED feedback that progresses from silence through two pulse rates to a continuous danger alert.
  • A deliberate fault injection test showing a false 20 cm raw reading. A five-reading median filter keeps the warning output stable.
  • Secret Mission: Add a three-centimetre hysteresis margin that stops warning-state chatter around each threshold.

Can I use this as a mobility aid?

This is an educational simulated prototype. It cannot replace a cane, guide dog, orientation and mobility training, or another person.

Before We Start

Before any hands-on work, define the purpose of your educational browser-based ESP32 obstacle-warning simulation. This prototype must never replace a cane, guide dog, orientation and mobility training, or human assistance.

Set Up Claude Code and Wokwi

The safety boundary is set. Your ESP32 idea still needs two tools before any sensor work can begin.

Claude Code will prepare complete file replacements for Wokwi. In this step, you'll set up both tools and prove the ESP32 starter runs in your browser.

In this step, get ready to:
  • Confirm an eligible Claude Code access route.
  • Prepare an authenticated Claude Code session for this project.
  • Launch the Wokwi ESP32 starter simulation.
Choose a Claude Code access route

Claude Code requires an eligible account. The free claude.ai plan does not include Claude Code.

Choosing access can feel weighty because some routes involve a subscription or prepaid credits. The project code never asks you to paste an API key.

Which access routes work?

  • Personal access can come from a Pro, Max, Ultra, Team, or Enterprise account.
  • Console access uses prepaid API credits.
  • Organization-managed access can come through Amazon Bedrock, Google Cloud's Agent Platform, or Microsoft Foundry.
  • Choose one eligible access route from the options above.
  • Confirm you can sign in to the selected account.
Install and prepare Claude Code

Claude Code runs inside a terminal session. Start by opening the terminal available on your operating system.

macOS

  • Press Cmd + Space to open Spotlight search.
  • Type Terminal, then press Enter.

Windows

  • Press Win + X to open the system menu.
  • Select Windows PowerShell or Terminal.
  • Confirm the prompt begins with PS.

The first check determines whether Claude Code is already available. A version or an unavailable command are both valid outcomes at this point.

  • Check for an existing Claude Code installation by running:
claude --version

What does this command do?

The command asks the local claude executable to identify its installed version. Its result tells you which setup path to use.

✔️ I see a version number

Good progress. Claude Code is already installed on your computer.

ⓧ Claude Code is not installed yet

The native installer adds Claude Code to your computer. Use the tab that matches your operating system.

macOS

  • Install Claude Code by running this command in Terminal:
curl -fsSL https://claude.ai/install.sh | bash
What does this installer do?

This command downloads the official native installer from Claude's website. The installer places the Claude Code executable on your computer.

  • Close the current Terminal window after the installer finishes.
  • Repeat the earlier macOS steps to open a new Terminal window.

Windows

  • Install Claude Code by running this command in PowerShell:
irm https://claude.ai/install.ps1 | iex
What does this installer do?

This command downloads the official native installer through PowerShell. The installer places the Claude Code executable on your computer.

  • Close the current PowerShell window after the installer finishes.
  • Repeat the earlier Windows steps to open a new PowerShell window.

Installer not completing?

  • Confirm your computer still has an internet connection.
  • Confirm you used Terminal on macOS or a prompt beginning with PS on Windows.
  • Open a fresh terminal window before retrying the installer.

Still stuck? Help me troubleshoot my Claude Code native installation.

Before you verify the installation, what do you expect the terminal to print now?

  • Verify the Claude Code installation by running:
claude --version

What does this verification prove?

A successful result proves your terminal can find the Claude Code executable. It also confirms the installation can start from a fresh terminal window.

You'll see a version number followed by (Claude Code). That output confirms the local installation is ready.

Still not seeing a version?

  • Close every open terminal window.
  • Open a fresh terminal using the operating-system steps above.
  • Rerun the installer for your operating system if the command remains unavailable.

Need another pair of eyes? Help me find why my terminal cannot run Claude Code after installation.

The local tool now needs an authenticated session. Starting the session opens a browser authentication flow while the terminal waits.

  • Start an interactive Claude Code session by running:
claude

What does this command do?

The claude command starts an interactive session in the current terminal. The first session connects the local installation to your eligible account.

  • Complete browser authentication with the eligible access route you selected.
  • Return to the same terminal session after authentication finishes.

The setup prompt gives Claude Code a precise role for this project. It also keeps all work inside the browser-based simulator.

  • Set the project rules by pasting this exact prompt into Claude Code:
You are my embedded-systems pair programmer for a beginner Wokwi project. Do not edit or inspect local files. In every response, explain the change briefly, then return complete replacement contents for each Wokwi file I request. Reply with: Ready to build the simulator safely.

What does this prompt establish?

  • Claude Code acts as an embedded-systems pair programmer for a beginner project.
  • The session does not inspect or edit local files.
  • Future responses provide complete replacement contents for each requested Wokwi file.

Claude Code should reply with Ready to build the simulator safely. Your coding partner now understands the workflow.

Authentication or prompt not working?

  • Confirm you authenticated with the eligible account selected earlier.
  • Return to the terminal window that started the browser flow.
  • Paste the complete setup prompt again if the reply does not match.

Need help with the session? Help me finish Claude Code authentication and apply the project setup prompt.

Create the Wokwi starter simulation

Wokwi runs the ESP32 simulation in your browser. This keeps the first test independent of physical hardware or a local Arduino compiler.

Wokwi Community costs €0 for unlimited public projects. Anything you place in this project is publicly visible.

  • Switch back to the browser window used during Claude Code authentication.
  • Enter https://wokwi.com/login in the browser address bar.

You'll reach the Wokwi sign-in page. This is the account boundary for your public browser project.

  • Complete one of the sign-in choices shown on the page.

Your Wokwi session is now connected to your account.

  • Enter https://wokwi.com/projects/new/esp32 in the browser address bar.

You'll see the ESP32 starter editor. This signed-in starter is the project you'll build on.

  • Confirm the editor shows a sketch.ino tab.
  • Confirm the editor shows a diagram.json tab.

Those two files hold the starter sketch and simulated circuit. Later steps replace their contents through Claude Code.

  • Arrange the Claude Code terminal beside the Wokwi browser window.

Before you press play, what message do you think the starter sketch sends to the Serial Monitor?

  • Start the starter simulation with the green play button.

You'll see Hello, ESP32! in the Serial Monitor. That message proves the browser simulator can run the starter sketch.

That's the setup hurdle cleared. Claude Code is authenticated while Wokwi is running your first ESP32 output.

Your coding partner and browser simulator are ready. Next up, you'll replace the starter with a live ultrasonic distance reading.

Make Distance Visible

Your Wokwi starter already proves that a browser simulation can run an ESP32 sketch. The next question is whether the circuit can turn a sensor echo into a distance you can see.

Before adding warnings, you need a small working version that proves the wiring works. This version also proves the echo-time calculation produces useful centimetre readings.

In this step, get ready to:
  • Generate complete sensor circuit files with Claude Code.
  • Replace the two files in your existing Wokwi project.
  • Verify live distance readings at three simulated positions.
Generate the sensor files with Claude Code

Claude Code can translate the circuit requirements into complete replacements for diagram.json and sketch.ino. A precise prompt keeps this first version focused on measuring distance.

  • Switch back to the authenticated Claude Code session from the previous step.
  • Send the exact sensor requirements by pasting this prompt:
Create the first working version of my Wokwi ESP32 obstacle-warning prototype. Return complete replacement contents for diagram.json and sketch.ino, with no markdown commentary inside the files. Use Wokwi part board-esp32-devkit-c-v4. Add one wokwi-hc-sr04 with initial distance 200 cm. Connect VCC to 5V, GND to an ESP32 ground pin, TRIG to GPIO 13, and ECHO to GPIO 34. In sketch.ino, use Serial at 115200, send a 10-microsecond trigger pulse, measure ECHO with pulseIn, convert microseconds to centimetres by dividing by 58.0, and print a line beginning Distance: followed by the value and cm. Keep the loop beginner-friendly with a 150 ms delay. Do not add a buzzer, LED, filter, external library, or local file instructions yet.

What Does This Prompt Control?

  • The diagram.json output adds the simulated board. It also adds the sensor wiring.
  • The sketch.ino output sends a trigger pulse. It measures the returning echo with pulseIn.
  • Dividing durationMicros by 58.0 converts the echo duration into centimetres.
  • The exclusions keep the first test focused on one observable result: distance.
  • Wait for Claude Code to return one complete replacement for each Wokwi file.
  • Keep the response visible beside the Wokwi browser window.

You should now have complete contents for both existing Wokwi tabs.

Missing One of the Files?

  • Confirm that you sent the prompt inside the authenticated Claude Code session from earlier.
  • Ask Claude Code to regenerate the response if either file is incomplete.
  • Check that the response contains separate contents for diagram.json and sketch.ino.

Still missing an output? Help me get both complete Wokwi files from Claude Code.

Replace the Wokwi files and run the circuit

The circuit description controls which simulated parts exist. The sketch controls how the board reads the HC-SR04 sensor.

  • Switch back to the Wokwi browser window from earlier.
  • Select diagram.json in the editor.
  • Press Cmd+A (macOS) or Ctrl+A (Windows) to select the existing contents.
  • Paste the complete diagram.json contents from Claude Code.
  • Select sketch.ino in the editor.
  • Press Cmd+A (macOS) or Ctrl+A (Windows) to select the existing contents.
  • Paste the complete sketch.ino contents from Claude Code.

How Does Distance Measurement Work?

The sensor sends an ultrasonic pulse toward the simulated obstacle. The echo duration measures the round trip to the obstacle and back.

The sketch divides that duration by 58.0 to produce centimetres. Each reading gives you visible evidence that the sensor loop works.

Before you start the circuit, what distance do you expect from a sensor that begins at 200 cm?

  • Start the updated simulation by clicking the green play button.

You should see the HC-SR04 connected to the ESP32. You should also see Serial Monitor lines beginning with Distance: and reporting approximately 200 cm.

Simulation Not Showing Distance?

  • Check that each Wokwi file contains only its replacement contents.
  • Remove any surrounding markdown fences that Claude Code may have included.
  • Confirm that diagram.json contains the sensor connections.
  • Confirm that sketch.ino contains readDistanceCm().

Need help with the failed simulation? Help me compare my Wokwi files with the required sensor circuit.

Test live distance changes

The simulator changes the sensor's ultrasonic time of flight when you move its distance slider. The Serial Monitor should follow each new position.

Before you move the slider, what should happen to the displayed reading when the simulated distance is cut in half?

  • Keep the simulation running.
  • Click the HC-SR04 drawing.
  • Move its distance slider to 200 cm.

You should see readings close to 200 cm in the Serial Monitor.

  • Move the distance slider to 100 cm.

You should see the readings change to approximately 100 cm.

  • Move the distance slider to 50 cm.

You should see the readings change to approximately 50 cm. That is your first live sensor loop working from simulated echo to visible distance.

✔️ Awesome, I've got everything!

Your circuit contains the ESP32 and HC-SR04. Your sketch now reports live distances in centimetres.

ⓧ I'd like to double check the full code

Compare your two Wokwi files with these complete references.

{
  "version": 1,
  "author": "NextWork",
  "editor": "wokwi",
  "parts": [
    {
      "type": "board-esp32-devkit-c-v4",
      "id": "esp",
      "top": 0,
      "left": 0,
      "attrs": {}
    },
    {
      "type": "wokwi-hc-sr04",
      "id": "sensor",
      "top": -150,
      "left": -200,
      "attrs": { "distance": "200" }
    }
  ],
  "connections": [
    [ "esp:TX", "$serialMonitor:RX", "", [] ],
    [ "esp:RX", "$serialMonitor:TX", "", [] ],
    [ "esp:5V", "sensor:VCC", "red", [] ],
    [ "esp:GND.2", "sensor:GND", "black", [] ],
    [ "esp:13", "sensor:TRIG", "green", [] ],
    [ "esp:34", "sensor:ECHO", "blue", [] ]
  ],
  "dependencies": {}
}

What Should Match in diagram.json?

This file contains one ESP32 board and one HC-SR04 sensor. Its connections link power, ground, trigger, echo, and the Serial Monitor.

const int TRIG_PIN = 13;
const int ECHO_PIN = 34;

float readDistanceCm() {
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);

  unsigned long durationMicros = pulseIn(ECHO_PIN, HIGH);
  return durationMicros / 58.0;
}

void setup() {
  Serial.begin(115200);
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
}

void loop() {
  float distanceCm = readDistanceCm();
  Serial.print("Distance: ");
  Serial.print(distanceCm);
  Serial.println(" cm");
  delay(150);
}

What Should Match in sketch.ino?

  • The pin constants keep the trigger on GPIO 13. They keep the echo on GPIO 34.
  • The readDistanceCm() function sends the trigger pulse. It returns the calculated distance.
  • The main loop prints each distance. It waits 150 milliseconds before taking the next reading.

Your sensor loop now turns echo time into live distance readings. Next, you'll add warning zones that expose the risk of one bad sample.

Add Warning Zones and Trigger a False Alarm

Your Wokwi sensor loop now proves that the ESP32 can measure obstacle distance. Distance alone cannot warn someone when an object moves closer.

This step turns each raw reading into one of four buzzer states with threshold-based feedback. You will use Claude Code to add deliberate fault injection that exposes how one bad echo can trigger the wrong warning.

In this step, get ready to:
  • Generate a buzzer circuit with four raw warning zones.
  • Trigger a deliberate false danger alert at 200 cm.
  • Test every threshold boundary before restoring the deliberate glitch.
Generate the warning version

A distance threshold maps each reading to a warning level. The deliberate glitch changes every twentieth reading to 20 cm so the raw alert logic faces one extreme sample.

  • Switch back to the authenticated Claude Code session from earlier.
  • Generate complete replacements for both Wokwi files by pasting this exact prompt into Claude Code:
Upgrade the current Wokwi version without adding any smoothing yet. Return complete replacement contents for diagram.json and sketch.ino. Add a wokwi-buzzer with its positive pin on ESP32 GPIO 25 and negative pin on ground. Keep the HC-SR04 on GPIO 13 and GPIO 34. Add four alert levels based on the raw distance: over 150 cm silent, 80 through 150 cm a 120 ms tone followed by 680 ms silence, 40 through under 80 cm a 100 ms tone followed by 200 ms silence, and under 40 cm a repeating 150 ms tone with only a 100 ms loop delay so it sounds continuous. Print the distance and alert name. Add a clearly named boolean INJECT_TEST_GLITCH set to true. Every twentieth reading, replace only the raw value with 20 cm so we can deliberately demonstrate a false alarm. Do not add an LED or filter yet.

What does this prompt create?

  • The updated circuit connects a buzzer to GPIO 25 so each warning state produces audible feedback.
  • The sketch classifies each raw reading as SILENT, SLOW, FAST, or DANGER.
  • The INJECT_TEST_GLITCH switch replaces every twentieth raw reading with 20 cm.
  • The warning logic trusts that injected reading immediately. This creates a repeatable test of the raw-threshold weakness.
Run the deliberate false alarm

Claude Code returns complete replacement contents for the circuit and sketch. Replacing both files keeps the buzzer wiring aligned with the pin used by the alert code.

  • Copy the complete diagram.json output from Claude Code.
  • In the Wokwi editor, select diagram.json.
  • Replace the entire contents of diagram.json with the copied output.
  • Copy the complete sketch.ino output from Claude Code.
  • In the Wokwi editor, select sketch.ino.
  • Replace the entire contents of sketch.ino with the copied output.

Before you start this version, do you think a 200 cm obstacle can still produce a DANGER alert?

  • Start the replacement simulation with the green play button.
  • Keep the HC-SR04 distance slider at 200 cm.
  • Watch the Serial Monitor for about three seconds to see how the twentieth sample is classified.

Most lines show a distance near 200 cm with a SILENT alert. The twentieth line shows 20 cm with a brief DANGER tone even though the slider remains at 200 cm.

You have reproduced a false alarm on demand. The raw threshold logic treats one bad echo as an immediate danger reading.

No false danger alert?

  • Confirm that INJECT_TEST_GLITCH is set to true in sketch.ino.
  • Keep the simulation running long enough for at least twenty readings to reach the Serial Monitor.
  • Confirm that buzzer:2 connects to GPIO 25 and buzzer:1 connects to GND.1 in diagram.json.

Still stuck? Help me debug why the injected false alert does not appear in Wokwi.

Test the warning boundaries

The false alert is intentional. Temporarily disabling fault injection lets you test each normal boundary without a synthetic reading interrupting the sequence.

  • In sketch.ino, find this line:
bool INJECT_TEST_GLITCH = true;

What does this line control?

The true value activates the deliberate 20 cm reading. This guarantees a false sample every twentieth loop.

  • Replace true with false so the line looks like this:
bool INJECT_TEST_GLITCH = false;

Why disable the glitch?

The false value keeps every raw reading tied to the slider. Each boundary test now reflects the simulated obstacle distance.

Before you test the exact boundaries, which warning state do you think owns each boundary value?

  • Start the updated simulation with the green play button.
  • Set the HC-SR04 distance slider to 160 cm.

You should see SILENT in the Serial Monitor. The buzzer stays quiet.

  • Set the HC-SR04 distance slider to 150 cm.

You should see SLOW. The buzzer produces a 120 ms tone followed by 680 ms of silence.

  • Set the HC-SR04 distance slider to 80 cm.

You should still see SLOW with the same slow warning pattern.

  • Set the HC-SR04 distance slider to 79 cm.

You should see FAST. The buzzer produces a 100 ms tone followed by 200 ms of silence.

  • Set the HC-SR04 distance slider to 40 cm.

You should still see FAST with the faster warning pattern.

  • Set the HC-SR04 distance slider to 39 cm.

You should see DANGER with repeating 150 ms tones separated by the 100 ms loop delay. The warning sounds nearly continuous.

The boundary test is complete. Restore the deliberate glitch so the next step begins with the false-alarm behavior still active.

  • In sketch.ino, find the temporary test line:
bool INJECT_TEST_GLITCH = false;

What is the current test state?

The false value allowed an uninterrupted boundary test. Restoring the switch prepares the project to demonstrate the raw-reading failure again.

  • Replace false with true so the line looks like this:
bool INJECT_TEST_GLITCH = true;

Why restore the glitch?

The next step needs the deliberate false sample to remain reproducible. Keeping the switch in the sketch also makes the later improvement measurable.

Before you rerun at 200 cm, do you expect the twentieth sample to follow the slider or the injected value?

  • Start the updated simulation with the green play button.
  • Set the HC-SR04 distance slider to 200 cm.
  • Watch the Serial Monitor for about three seconds.

You should see one Distance: 20 cm | Alert: DANGER reading among the normal 200 cm readings. The brief danger tone confirms that the restored raw-warning version still reproduces the intended failure.

Seeing the wrong warning zone?

  • Confirm that fault injection stays set to false during the six boundary checks.
  • Confirm that the slider reaches the exact values 160 cm, 150 cm, 80 cm, 79 cm, 40 cm, and 39 cm.
  • Confirm that fault injection returns to true before the final 200 cm check.

Need another pair of eyes? Help me check my Wokwi warning thresholds and fault-injection switch.

✔️ Awesome, I've got everything!

Your buzzer circuit now has four raw warning zones. Keep INJECT_TEST_GLITCH set to true for the next step.

ⓧ I'd like to double check the full code

Compare your complete diagram.json with this reference:

{
  "version": 1,
  "author": "NextWork",
  "editor": "wokwi",
  "parts": [
    {
      "type": "board-esp32-devkit-c-v4",
      "id": "esp",
      "top": 0,
      "left": 0,
      "attrs": {}
    },
    {
      "type": "wokwi-hc-sr04",
      "id": "sensor",
      "top": -150,
      "left": -200,
      "attrs": { "distance": "200" }
    },
    {
      "type": "wokwi-buzzer",
      "id": "buzzer",
      "top": -70,
      "left": 250,
      "attrs": { "volume": "0.1" }
    }
  ],
  "connections": [
    [ "esp:TX", "$serialMonitor:RX", "", [] ],
    [ "esp:RX", "$serialMonitor:TX", "", [] ],
    [ "esp:5V", "sensor:VCC", "red", [] ],
    [ "esp:GND.2", "sensor:GND", "black", [] ],
    [ "esp:13", "sensor:TRIG", "green", [] ],
    [ "esp:34", "sensor:ECHO", "blue", [] ],
    [ "esp:25", "buzzer:2", "purple", [] ],
    [ "esp:GND.1", "buzzer:1", "black", [] ]
  ],
  "dependencies": {}
}

What should match?

This circuit keeps the sensor wiring from the previous step. It adds the buzzer between GPIO 25 and GND.1.

Compare your complete sketch.ino with this reference:

const int TRIG_PIN = 13;
const int ECHO_PIN = 34;
const int BUZZER_PIN = 25;

const float SILENT_THRESHOLD_CM = 150.0;
const float SLOW_THRESHOLD_CM = 80.0;
const float DANGER_THRESHOLD_CM = 40.0;

bool INJECT_TEST_GLITCH = true;
unsigned long sampleNumber = 0;

enum AlertLevel {
  SILENT,
  SLOW,
  FAST,
  DANGER
};

float readDistanceCm() {
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);

  unsigned long durationMicros = pulseIn(ECHO_PIN, HIGH);
  return durationMicros / 58.0;
}

float injectTestGlitch(float distanceCm) {
  sampleNumber++;
  if (INJECT_TEST_GLITCH && sampleNumber % 20 == 0) {
    return 20.0;
  }
  return distanceCm;
}

AlertLevel classifyDistance(float distanceCm) {
  if (distanceCm > SILENT_THRESHOLD_CM) return SILENT;
  if (distanceCm >= SLOW_THRESHOLD_CM) return SLOW;
  if (distanceCm >= DANGER_THRESHOLD_CM) return FAST;
  return DANGER;
}

const char *alertName(AlertLevel level) {
  switch (level) {
    case SILENT: return "SILENT";
    case SLOW: return "SLOW";
    case FAST: return "FAST";
    case DANGER: return "DANGER";
  }
  return "UNKNOWN";
}

void applyAlert(AlertLevel level) {
  switch (level) {
    case SILENT:
      noTone(BUZZER_PIN);
      delay(150);
      break;
    case SLOW:
      tone(BUZZER_PIN, 1000, 120);
      delay(120);
      delay(680);
      break;
    case FAST:
      tone(BUZZER_PIN, 1200, 100);
      delay(100);
      delay(200);
      break;
    case DANGER:
      tone(BUZZER_PIN, 1500, 150);
      delay(100);
      break;
  }
}

void setup() {
  Serial.begin(115200);
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
}

void loop() {
  float rawDistanceCm = readDistanceCm();
  rawDistanceCm = injectTestGlitch(rawDistanceCm);
  AlertLevel alert = classifyDistance(rawDistanceCm);

  Serial.print("Distance: ");
  Serial.print(rawDistanceCm);
  Serial.print(" cm | Alert: ");
  Serial.println(alertName(alert));

  applyAlert(alert);
}

What should match?

This sketch reads one raw distance before applying the deliberate glitch. It classifies that raw value immediately and sends the matching pattern to the buzzer.

Your prototype now turns distance into four warning patterns and reproduces one false danger alert. Next up, you will harden the warning loop so a single bad echo cannot control the buzzer.

Filter Out One Bad Echo

Your Wokwi simulation now turns one injected 20 cm reading into a false DANGER alert while the obstacle remains at 200 cm. That result proves raw thresholds react to a bad echo.

A five-reading median filter sorts the latest values before selecting the middle one. You will add that filter with Claude Code so one extreme sample no longer controls the buzzer.

In this step, get ready to:
  • Add a five-reading median filter to the sensor loop.
  • Prove that one injected bad echo cannot trigger the buzzer.
  • Disable future deliberate glitches after the filter passes its test.
Add the five-reading median filter

The filter keeps five recent distances in memory. Sorting those readings makes the middle value resistant to one unusually high or low sample.

  • Return to the authenticated Claude Code session from earlier.
  • Request the complete filtered sketch by pasting this exact prompt:
Fix the demonstrated false alarm with a median filter. Return a complete replacement sketch.ino and leave diagram.json unchanged. Store the latest five raw distances, copy and sort those five values, and use the middle value as smoothedDistanceCm. Initialize all five slots from the first real reading so startup does not contain zeros. Keep INJECT_TEST_GLITCH true for this test. Print each line as Raw: <value> cm | Smoothed: <value> cm | Alert: <name>. Drive all four buzzer warning zones from the smoothed value, never the raw value. Keep the existing pins, boundaries, and beep timing. Use only built-in Arduino functionality and write the sorting logic directly in the sketch.

What Does This Prompt Change?

  • The FILTER_SIZE constant fixes the filter window at five readings.
  • The recentReadings array stores the current sample window.
  • The addReading() function fills every slot from the first reading. This prevents startup zeros from creating a false result.
  • The medianReading() function sorts a copy of the sample window. It returns the value in the middle position.
  • The alert now uses smoothedDistanceCm. The Serial Monitor still exposes rawDistanceCm so you can see the injected fault.
  • Copy the complete replacement for sketch.ino from Claude Code.
  • Switch back to the Wokwi browser window from earlier.
  • Select the sketch.ino file tab.
  • Replace the entire file with Claude Code's output.
  • Leave diagram.json unchanged.
  • Start the updated simulation with the green play button.

The Serial Monitor now prints each raw reading beside its smoothed value. Every line also names the alert selected from the smoothed distance.

Missing the Smoothed Reading?

  • Confirm that you replaced all the contents of sketch.ino with the complete response.
  • Check that the final output section prints labels beginning with Raw: and Smoothed:.
  • Restart the simulation after replacing the sketch.

Still stuck? Help me check why my Wokwi Serial Monitor does not show raw and smoothed distances.

Prove one bad echo is rejected

Four readings near the real distance outweigh one injected extreme value in a five-reading window. The median should therefore stay close to the obstacle's actual position.

  • Click the HC-SR04 drawing in the running simulation.
  • Set its distance slider to 200 cm.

Before you watch the next twenty samples, do you think the injected 20 cm reading will still produce a DANGER alert?

  • Watch the Serial Monitor until one raw reading drops to 20 cm.

You will see Raw: 20 cm while the smoothed value stays near 200 cm. The alert remains SILENT.

You have contained the false alarm. Your warning loop now ignores one extreme echo while the buzzer stays silent.

Disable future deliberate glitches

The injected reading has served its purpose as a repeatable test. You can now disable it while keeping the test feature available inside the sketch.

  • Return to the same Claude Code session.
  • Request the one-line change by pasting this exact follow-up:
The median test passed. Return only the exact line I should use to disable future deliberate glitches while keeping the test feature available in the sketch.

Why Keep the Test Feature?

This prompt preserves the fault-injection code for future checks. It changes only the switch that controls whether the false sample is generated.

  • Copy the single line Claude Code returns.
  • Switch back to sketch.ino in Wokwi.
  • Find the existing line that sets INJECT_TEST_GLITCH to true.
  • Replace that line with Claude Code's returned line:
bool INJECT_TEST_GLITCH = false;

What Does This Line Do?

The false value prevents injectTestGlitch() from replacing every twentieth reading. The function remains available when you want to repeat the test.

Before you restart the simulation, do you expect any raw reading to drop deliberately to 20 cm now?

  • Restart the simulation with the green play button.
  • Watch the Serial Monitor for at least twenty samples.

The raw and smoothed distances stay near 200 cm. The alert remains SILENT with no deliberate 20 cm sample.

Still Seeing Deliberate 20 cm Samples?

  • Confirm that INJECT_TEST_GLITCH is set to false near the top of sketch.ino.
  • Restart the simulation after changing the line.

Need another pair of eyes? Help me find why deliberate 20 cm samples still appear after I disabled fault injection.

✔️ Awesome, I've got everything!

Great. sketch.ino now filters five readings before selecting an alert. The circuit in diagram.json remains unchanged.

ⓧ I'd like to double check the full code

  • Compare your complete sketch.ino with this checkpoint:
const int TRIG_PIN = 13;
const int ECHO_PIN = 34;
const int BUZZER_PIN = 25;

const float SILENT_THRESHOLD_CM = 150.0;
const float SLOW_THRESHOLD_CM = 80.0;
const float DANGER_THRESHOLD_CM = 40.0;
const int FILTER_SIZE = 5;

bool INJECT_TEST_GLITCH = false;
unsigned long sampleNumber = 0;
float recentReadings[FILTER_SIZE];
bool filterInitialized = false;
int nextReadingIndex = 0;

enum AlertLevel { SILENT, SLOW, FAST, DANGER };

float readDistanceCm() {
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  unsigned long durationMicros = pulseIn(ECHO_PIN, HIGH);
  return durationMicros / 58.0;
}

float injectTestGlitch(float distanceCm) {
  sampleNumber++;
  if (INJECT_TEST_GLITCH && sampleNumber % 20 == 0) return 20.0;
  return distanceCm;
}

void addReading(float distanceCm) {
  if (!filterInitialized) {
    for (int i = 0; i < FILTER_SIZE; i++) recentReadings[i] = distanceCm;
    filterInitialized = true;
    return;
  }
  recentReadings[nextReadingIndex] = distanceCm;
  nextReadingIndex = (nextReadingIndex + 1) % FILTER_SIZE;
}

float medianReading() {
  float sorted[FILTER_SIZE];
  for (int i = 0; i < FILTER_SIZE; i++) sorted[i] = recentReadings[i];
  for (int i = 1; i < FILTER_SIZE; i++) {
    float value = sorted[i];
    int position = i - 1;
    while (position >= 0 && sorted[position] > value) {
      sorted[position + 1] = sorted[position];
      position--;
    }
    sorted[position + 1] = value;
  }
  return sorted[FILTER_SIZE / 2];
}

AlertLevel classifyDistance(float distanceCm) {
  if (distanceCm > SILENT_THRESHOLD_CM) return SILENT;
  if (distanceCm >= SLOW_THRESHOLD_CM) return SLOW;
  if (distanceCm >= DANGER_THRESHOLD_CM) return FAST;
  return DANGER;
}

const char *alertName(AlertLevel level) {
  switch (level) {
    case SILENT: return "SILENT";
    case SLOW: return "SLOW";
    case FAST: return "FAST";
    case DANGER: return "DANGER";
  }
  return "UNKNOWN";
}

void applyAlert(AlertLevel level) {
  switch (level) {
    case SILENT: delay(150); break;
    case SLOW: tone(BUZZER_PIN, 1000, 120); delay(120); delay(680); break;
    case FAST: tone(BUZZER_PIN, 1200, 100); delay(100); delay(200); break;
    case DANGER: tone(BUZZER_PIN, 1500, 150); delay(100); break;
  }
}

void setup() {
  Serial.begin(115200);
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
}

void loop() {
  float rawDistanceCm = injectTestGlitch(readDistanceCm());
  addReading(rawDistanceCm);
  float smoothedDistanceCm = medianReading();
  AlertLevel alert = classifyDistance(smoothedDistanceCm);
  Serial.print("Raw: ");
  Serial.print(rawDistanceCm);
  Serial.print(" cm | Smoothed: ");
  Serial.print(smoothedDistanceCm);
  Serial.print(" cm | Alert: ");
  Serial.println(alertName(alert));
  applyAlert(alert);
}

How the Final Flow Works

  • The sketch reads the sensor before passing the raw value through the optional glitch injector.
  • The addReading() function updates the five-value window.
  • The medianReading() function produces smoothedDistanceCm.
  • The alert classification uses the smoothed value before applyAlert() controls the buzzer.

Your sensor loop now rejects one extreme echo without hiding the raw evidence. Next, you will add synchronized LED feedback so every warning state is visible in your recorded demonstration.

Add LED Feedback and Record the Demo

Your five-reading median filter now keeps the Wokwi warning output stable when one bad echo appears. The buzzer communicates each warning level while you are listening.

A silent screen recording cannot always prove what the buzzer did. In this step, you will use Claude Code to add a synchronized LED that keeps every warning visible.

In this step, get ready to:
  • Add a red LED with a 220-ohm resistor to the Wokwi circuit.
  • Synchronize the LED with all four warning levels.
  • Test every threshold before recording the completed demonstration.
Add the synchronized LED

The LED acts as a visible stand-in for vibration. Its timing must match the buzzer so the diagram shows the same warning that a listener hears.

  • Switch back to the authenticated Claude Code terminal from earlier.
  • Request the final circuit and sketch by pasting this exact prompt:
Finish the simulator. Return complete replacement contents for diagram.json and sketch.ino. Add a red wokwi-led as a visible stand-in for vibration. Connect ESP32 GPIO 15 through a wokwi-resistor set to 220 ohms to the LED anode, and connect the LED cathode to ground. Configure GPIO 15 as an output. Keep the five-reading median and set INJECT_TEST_GLITCH to false. Make the LED stay off in SILENT, turn on only during each SLOW or FAST buzzer pulse, and stay steadily on in DANGER. Preserve the sensor and buzzer pins, threshold boundaries, Serial output, and built-in-only implementation.

What does this prompt do?

  • The prompt preserves the sensor pins, buzzer pin, filter, thresholds, and Serial output that already work.
  • It asks for a red LED on GPIO 15 through a 220-ohm resistor.
  • It makes the LED copy the timing of each buzzer state so the warning remains visible in a recording.
  • Copy the complete diagram.json contents returned by Claude Code.
  • Switch back to the saved Wokwi project from earlier.
  • Stop the running simulation using the simulation control above the diagram.
  • Select diagram.json in the Wokwi editor.
  • Replace the entire file with the new diagram.json contents.
  • Start the simulation with the green play button.

You should see a red LED connected through a resistor on the right side of the ESP32. The existing distance readings and buzzer behavior should continue.

  • Copy the complete sketch.ino contents returned by Claude Code.
  • Stop the simulation using the simulation control above the diagram.
  • Select sketch.ino in the Wokwi editor.
  • Replace the entire file with the new sketch.ino contents.
  • Start the simulation with the green play button.
  • Set the HC-SR04 distance slider to 30 cm.

You should see DANGER in the Serial Monitor. The red LED should remain steadily lit while the buzzer produces its near-continuous warning.

✔️ Awesome, I've got everything!

Your circuit now includes the red warning LED with its resistor. Your sketch drives that LED from the same alert state as the buzzer.

ⓧ I'd like to double check the full code

The final diagram.json should match this reference exactly.

{
  "version": 1,
  "author": "NextWork",
  "editor": "wokwi",
  "parts": [
    {
      "type": "board-esp32-devkit-c-v4",
      "id": "esp",
      "top": 0,
      "left": 0,
      "attrs": {}
    },
    {
      "type": "wokwi-hc-sr04",
      "id": "sensor",
      "top": -150,
      "left": -200,
      "attrs": { "distance": "200" }
    },
    {
      "type": "wokwi-buzzer",
      "id": "buzzer",
      "top": -70,
      "left": 250,
      "attrs": { "volume": "0.1" }
    },
    {
      "type": "wokwi-led",
      "id": "warningLed",
      "top": 60,
      "left": 250,
      "attrs": { "color": "red", "label": "Vibration stand-in" }
    },
    {
      "type": "wokwi-resistor",
      "id": "ledResistor",
      "top": 100,
      "left": 180,
      "rotate": 90,
      "attrs": { "value": "220" }
    }
  ],
  "connections": [
    [ "esp:TX", "$serialMonitor:RX", "", [] ],
    [ "esp:RX", "$serialMonitor:TX", "", [] ],
    [ "esp:5V", "sensor:VCC", "red", [] ],
    [ "esp:GND.2", "sensor:GND", "black", [] ],
    [ "esp:13", "sensor:TRIG", "green", [] ],
    [ "esp:34", "sensor:ECHO", "blue", [] ],
    [ "esp:25", "buzzer:2", "purple", [] ],
    [ "esp:GND.1", "buzzer:1", "black", [] ],
    [ "esp:15", "ledResistor:1", "orange", [] ],
    [ "ledResistor:2", "warningLed:A", "orange", [] ],
    [ "warningLed:C", "esp:GND.3", "black", [] ]
  ],
  "dependencies": {}
}

What does this circuit add?

  • The warningLed part provides the visible warning output.
  • The ledResistor part sits between GPIO 15 and the LED anode.
  • The LED cathode connects to GND.3 to complete the circuit.

The final sketch.ino should match this reference exactly.

const int TRIG_PIN = 13;
const int ECHO_PIN = 34;
const int BUZZER_PIN = 25;
const int LED_PIN = 15;

const float SILENT_THRESHOLD_CM = 150.0;
const float SLOW_THRESHOLD_CM = 80.0;
const float DANGER_THRESHOLD_CM = 40.0;
const int FILTER_SIZE = 5;

bool INJECT_TEST_GLITCH = false;
unsigned long sampleNumber = 0;
float recentReadings[FILTER_SIZE];
bool filterInitialized = false;
int nextReadingIndex = 0;

enum AlertLevel {
  SILENT,
  SLOW,
  FAST,
  DANGER
};

float readDistanceCm() {
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);

  unsigned long durationMicros = pulseIn(ECHO_PIN, HIGH);
  return durationMicros / 58.0;
}

float injectTestGlitch(float distanceCm) {
  sampleNumber++;
  if (INJECT_TEST_GLITCH && sampleNumber % 20 == 0) {
    return 20.0;
  }
  return distanceCm;
}

void addReading(float distanceCm) {
  if (!filterInitialized) {
    for (int i = 0; i < FILTER_SIZE; i++) {
      recentReadings[i] = distanceCm;
    }
    filterInitialized = true;
    return;
  }

  recentReadings[nextReadingIndex] = distanceCm;
  nextReadingIndex = (nextReadingIndex + 1) % FILTER_SIZE;
}

float medianReading() {
  float sorted[FILTER_SIZE];
  for (int i = 0; i < FILTER_SIZE; i++) {
    sorted[i] = recentReadings[i];
  }

  for (int i = 1; i < FILTER_SIZE; i++) {
    float value = sorted[i];
    int position = i - 1;
    while (position >= 0 && sorted[position] > value) {
      sorted[position + 1] = sorted[position];
      position--;
    }
    sorted[position + 1] = value;
  }

  return sorted[FILTER_SIZE / 2];
}

AlertLevel classifyDistance(float distanceCm) {
  if (distanceCm > SILENT_THRESHOLD_CM) {
    return SILENT;
  }
  if (distanceCm >= SLOW_THRESHOLD_CM) {
    return SLOW;
  }
  if (distanceCm >= DANGER_THRESHOLD_CM) {
    return FAST;
  }
  return DANGER;
}

const char *alertName(AlertLevel level) {
  switch (level) {
    case SILENT:
      return "SILENT";
    case SLOW:
      return "SLOW";
    case FAST:
      return "FAST";
    case DANGER:
      return "DANGER";
  }
  return "UNKNOWN";
}

void applyAlert(AlertLevel level) {
  switch (level) {
    case SILENT:
      digitalWrite(LED_PIN, LOW);
      delay(150);
      break;

    case SLOW:
      tone(BUZZER_PIN, 1000, 120);
      digitalWrite(LED_PIN, HIGH);
      delay(120);
      digitalWrite(LED_PIN, LOW);
      delay(680);
      break;

    case FAST:
      tone(BUZZER_PIN, 1200, 100);
      digitalWrite(LED_PIN, HIGH);
      delay(100);
      digitalWrite(LED_PIN, LOW);
      delay(200);
      break;

    case DANGER:
      tone(BUZZER_PIN, 1500, 150);
      digitalWrite(LED_PIN, HIGH);
      delay(100);
      break;
  }
}

void setup() {
  Serial.begin(115200);
  pinMode(TRIG_PIN, OUTPUT);
  pinMode(ECHO_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);
}

void loop() {
  float rawDistanceCm = readDistanceCm();
  rawDistanceCm = injectTestGlitch(rawDistanceCm);
  addReading(rawDistanceCm);

  float smoothedDistanceCm = medianReading();
  AlertLevel alert = classifyDistance(smoothedDistanceCm);

  Serial.print("Raw: ");
  Serial.print(rawDistanceCm);
  Serial.print(" cm | Smoothed: ");
  Serial.print(smoothedDistanceCm);
  Serial.print(" cm | Alert: ");
  Serial.println(alertName(alert));

  applyAlert(alert);
}

How does the LED stay synchronized?

  • The LED_PIN constant assigns the LED to GPIO 15.
  • The setup() function configures that pin as an output with the LED initially off.
  • The applyAlert() function changes the LED during the same delays that control the buzzer pattern.

LED missing or simulation failing?

  • Confirm that you replaced the entire contents of both files. A partial replacement can leave old wiring or alert logic behind.
  • Compare warningLed with the full diagram.json reference.
  • Check that LED_PIN is set to 15 in sketch.ino.

Still stuck? Help me compare my final Wokwi LED circuit and sketch with the expected files.

Test every warning boundary

The final test checks values on both sides of the thresholds. Holding each distance briefly gives the median filter time to fill with the new reading.

Before you begin, which alert states do you expect at exactly 150 cm, 80 cm, and 40 cm?

  • Click the HC-SR04 drawing while the simulation is running.
  • Set the distance slider to 160 cm.

Once the smoothed reading settles near 160 cm, you should see SILENT. The LED should remain off with no buzzer warning.

  • Set the distance slider to 150 cm.

Once the filter settles, you should see SLOW. The LED should flash during each slow buzzer pulse.

  • Set the distance slider to 80 cm.

You should still see SLOW after the filter settles. The LED should flash with each slow buzzer pulse.

  • Set the distance slider to 40 cm.

You should see FAST after the filter settles. The LED should flash with the quicker buzzer pattern.

  • Set the distance slider to 30 cm.

You should see DANGER after the filter settles. The LED should remain steadily lit while the buzzer produces its near-continuous warning.

That completes the full threshold test. Every warning state now has matching audible and visible feedback.

Record the demonstration

A recording ties each distance input to its Serial state and LED response. macOS Screenshot, Windows Snipping Tool, or Clipchamp can capture that evidence.

macOS

  • Press Shift + Command + 5 to open Screenshot.
  • Drag the recording area over the Wokwi diagram, distance control, and Serial Monitor.
  • Click Record.

Keep the proof in frame

The recording area needs to show the simulated circuit, distance control, and Serial Monitor together. This lets a viewer connect each slider value to the warning response.

  • Set the distance slider to 160 cm.
  • Set the distance slider to 150 cm.
  • Set the distance slider to 80 cm.
  • Set the distance slider to 40 cm.
  • Set the distance slider to 30 cm.
  • Click Stop in the menu bar.

You can also press Command + Control + Esc to stop the recording.

Windows

Windows 11

  • Press Windows logo key + Shift + R to open a video snip.
  • Select an area containing the Wokwi diagram, distance control, and Serial Monitor.
  • Choose Start.
Keep the proof in frame

The recording area needs to show the simulated circuit, distance control, and Serial Monitor together. This lets a viewer connect each slider value to the warning response.

  • Set the distance slider to 160 cm.
  • Set the distance slider to 150 cm.
  • Set the distance slider to 80 cm.
  • Set the distance slider to 40 cm.
  • Set the distance slider to 30 cm.
  • Choose Stop.
  • Save the completed video.

Windows 10

  • Press the Windows key to open search.
  • Type Clipchamp.
  • Press Enter to open Clipchamp.
  • Select Record & Create.
  • Select Screen or Screen & Camera.
Keep the proof in frame

Capture the Wokwi browser window with the diagram, distance control, and Serial Monitor visible. Allow screen-sharing permission if your browser requests it.

  • Start the screen recording with the recorder control.
  • Set the distance slider to 160 cm.
  • Set the distance slider to 150 cm.
  • Set the distance slider to 80 cm.
  • Set the distance slider to 40 cm.
  • Set the distance slider to 30 cm.
  • Stop the recording with the recorder control.
  • Save the completed video from the recording preview.

Before you replay the clip, do you expect every warning transition to remain understandable if the buzzer audio is missing?

  • Replay the saved recording from beginning to end.

You should see the Serial Monitor move through SILENT, SLOW, FAST, and DANGER as the distance decreases. The LED should provide visible proof if your operating system does not capture the buzzer audio.

You have a replayable demonstration of the complete sensor-feedback loop. The recording shows the input, filtered state, and warning output working together.

Secret mission

Stop Threshold Chatter with Hysteresis

Make the warning state hold steady when filtered readings hover near 150 cm, 80 cm, or 40 cm. You will add a three-centimetre hysteresis margin and prove it with a before-and-after demonstration.

Clean Up Your Resources

Clean Up Your Resources

Your public Wokwi Community project remains at €0. The options below cover keeping it, pausing your active sessions, or removing the saved resources.

Cost warning

Claude Code access may use a subscription or prepaid Console credits. The exact cost depends on the access route you selected.

Removing the local installation does not cancel a subscription. It also does not change your separate Console account.

Resources you used:

  • Saved public Wokwi ESP32 project containing sketch.ino and diagram.json.
  • Local Claude Code installation with an authenticated terminal session.
  • Local screen recording containing the threshold test and hysteresis comparison.

Keep everything running

No action needed. Choose this if you want to keep improving the simulated obstacle-warning glasses.

  • Leave the saved public Wokwi project in your account.
  • Keep Claude Code installed for future projects.
  • Retain the screen recording as your demonstration.

Pause - I'll come back to this later

End the active sessions while keeping the saved project and recording ready for later.

  • Close the Wokwi browser tab from earlier to stop the simulation.
  • Return to the Claude Code terminal from earlier.
  • Exit the interactive session by entering:
/exit

What does this command do?

The /exit command closes the active Claude Code session. The local installation remains available for your next project.

  • Keep the saved public Wokwi project in your account.
  • Keep the local screen recording where you saved it.

Delete - I don't want to use this again

Deleting the saved project and recording is permanent. Make sure you have kept any demonstration you still want before continuing.

  • Close the Wokwi browser tab from earlier to stop the simulation.
  • Open the Wokwi projects dashboard.
  • Select the saved ESP32 obstacle-warning project.
  • Use the project deletion control to remove the saved project.

The public ESP32 project should no longer appear in your Wokwi projects dashboard.

  • Return to the Claude Code terminal from earlier.
  • Exit the authenticated session by entering:
/exit

Why exit first?

The /exit command ends the interactive session before you remove the local installation. Your deleted Wokwi project is unaffected by this terminal action.

The native Claude Code installation uses different local paths on macOS and Windows.

macOS

  • Remove the Claude Code executable and local application data by running:
rm -f ~/.local/bin/claude
rm -rf ~/.local/share/claude
What do these commands remove?

The first command removes the Claude Code executable. The second command removes its local application data.

Windows

  • Remove the Claude Code executable and local application data from PowerShell by running:
Remove-Item -Path "$env:USERPROFILE\.local\bin\claude.exe" -Force
Remove-Item -Path "$env:USERPROFILE\.local\share\claude" -Recurse -Force
What do these commands remove?

The first command removes the Claude Code executable. The second command removes its local application data.

  • Use your computer's file manager to return to the folder where you saved the screen recording.
  • Move the screen recording into your computer's deleted-files area.
  • Permanently remove the recording from that deleted-files area.

The recording should no longer appear in its original folder or your computer's deleted-files area.

Nice Work!

Nice Work!

You did it! Your browser now runs a working obstacle-warning prototype in Wokwi. An ESP32 turns every HC-SR04 distance into synchronized warning feedback.

You've learned how to:

  • Directed Claude Code with precise prompts that produced complete Wokwi replacements for diagram.json plus sketch.ino.
  • Converted ultrasonic time of flight into live centimetre readings. Mapped those readings to four levels of threshold-based feedback.
  • Injected one false 20 cm reading to reproduce a danger alert at a safe distance. Rejected that outlier with a five-reading median filter. Recorded synchronized buzzer-plus-LED feedback across the full threshold test.
  • Completed the optional Secret Mission by adding three-centimetre hysteresis. Proved the alerts remain stable near all three thresholds.

Ready to quiz yourself?