FluxBench.AIShared project · read-only

Ultrasonic Parking Sensor · guided v1

ESP32 DevKit (WROOM-32)·Arduino C++·Updated Sep 19, 2026·by FluxBenchIncludes Lab + Schematic

Simulate → Debug → Save: a virtual ESP32 parking project with an ECHO divider, optional repeatable software checks and a saved guide. No controller needed; hardware testing is deferred.

Parking v1 · template verification · hardware pending
  • Compile-tested · 2026-09-19 · ESP32 Arduino toolchain, merged firmware produced.
  • Simulation-tested · 2026-09-19 · distance boundaries, LEDs, beeps, wiring faults and recovery.
  • Hardware: not tested on a physical board.

Evidence covers the reference template only. Edits require retesting. Lab uses a teaching interpreter and sensor model; it does not reproduce all ESP32 behavior. No fabrication-ready PCB is included.

sketch.ino
// FluxBench guided parking sensor v1 — ESP32 DevKit v1, 30-pin
// HC-SR04: VCC=5V, GND=GND, TRIG=GPIO5.
// ECHO -> 2.2k resistor -> GPIO18 -> 3.3k resistor -> GND.
// The divider reduces a nominal 5V echo to 3.0V. Never wire ECHO directly.
// LEDs: GPIO25/26/27 -> anode; cathode -> 330 ohms -> GND.
// Use a small passive piezo on GPIO4, not a powered speaker or buzzer module.
// Educational demo, not a vehicle safety system. Hardware not yet verified.
const int TRIG_PIN = 5;
const int ECHO_PIN = 18;
const int GREEN_PIN = 25;
const int YELLOW_PIN = 26;
const int RED_PIN = 27;
const int BUZZER_PIN = 4;

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

void loop() {
  digitalWrite(TRIG_PIN, LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH);
  delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  unsigned long echoUs = pulseIn(ECHO_PIN, HIGH, 30000);
  if (echoUs == 0) {
    // A missing response must not be mistaken for a clear parking space.
    digitalWrite(GREEN_PIN, LOW);
    digitalWrite(YELLOW_PIN, LOW);
    digitalWrite(RED_PIN, HIGH);
    noTone(BUZZER_PIN);
    Serial.println("SENSOR FAULT: no echo; check power and wiring");
    delay(250);
    digitalWrite(RED_PIN, LOW);
    delay(250);
    return;
  }
  float cm = echoUs / 58.0;
  Serial.print("distance_cm:");
  Serial.print(cm);
  digitalWrite(GREEN_PIN, cm > 15);
  digitalWrite(YELLOW_PIN, cm <= 100 && cm > 15);
  digitalWrite(RED_PIN, cm <= 40);
  if (cm > 100) {
    Serial.println(" CLEAR");
    noTone(BUZZER_PIN);
    delay(150);
  } else if (cm > 40) {
    Serial.println(" APPROACHING");
    tone(BUZZER_PIN, 880);
    delay(100);
    noTone(BUZZER_PIN);
    delay(300);
  } else if (cm > 15) {
    Serial.println(" CLOSE");
    tone(BUZZER_PIN, 880);
    delay(60);
    noTone(BUZZER_PIN);
    delay(60);
  } else {
    Serial.println(" STOP");
    tone(BUZZER_PIN, 880);
    delay(100);
  }
}

Built with FluxBench.AI — the AI workbench for embedded projects.

Ultrasonic Parking Sensor · guided v1 · FluxBench.AI