Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

You can begin learning robotics without buying a board or sensor: build and test a simple Arduino parking sensor in Wokwi, a browser-based electronics simulator. Start with an HC-SR04 distance reading, then add LEDs and a buzzer to show when a virtual object is far, approaching, or close. AI can help explain or revise the sketch, but the simulator—not an AI answer—is where you check whether each change behaves as intended.

What you need to start robotics without hardware

Wokwi describes itself as an online electronics simulator and says it is free for personal use. Its supported hardware includes the Arduino Uno and HC-SR04 ultrasonic sensor, so you can assemble this project in a browser without first purchasing parts. See Wokwi’s documentation and its supported hardware list.

Create a new Arduino Uno project in Wokwi and add an HC-SR04 component. If you prefer to begin with a working reference, open Wokwi’s HC-SR04 parking sensor example. The core lesson is deliberately small: read distance, print it, and then decide how the project should respond.

How the HC-SR04 measures distance

The sensor estimates distance by sending an ultrasonic pulse and timing how long its echo takes to return. The Arduino briefly raises TRIG to start a measurement, then measures the duration of the high pulse on ECHO. Wokwi’s reference specifies a trigger pulse of at least 10 microseconds and converts the measured pulse duration to centimeters by dividing by 58. Its documented simulated distance range is 2–400 cm. See the Wokwi HC-SR04 reference.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
ELEGOO 37-in-1 Sensor Modules Kit with Tutorial Compatible with Arduino
  • Build a 37-Module Sensor Lab: Add motion, distance, light, sound, temperature, touch, display and control functions to compatible UNO, MEGA, Nano, ESP-32 or STM32 projects for prototyping, classroom experiments and maker builds
  • Explore Input Sensors and Motion: Experiment with GY-521 motion sensing, PIR detection, ultrasonic ranging, temperature and humidity, DS18B20, flame, Hall, touch, light, sound, tilt, tracking and obstacle-avoidance modules
  • Add Displays, Timing and Control: Use the LCD1602, DS1307 real-time clock, joystick, rotary encoder, relay, buzzers, RGB LEDs and infrared modules to build clocks, alarms, counters, status displays and automated projects
  • Follow Guided Projects Materials: Use digital tutorial materials, datasheets, wiring diagrams and example code for compatible UNO R3, MEGA 2560 and Nano boards, then adjust thresholds, timing and logic to create custom experiments
  • Module-Only Expansion Kit: Controller board, USB cable, breadboard and jumper wires are not included; use 6.5–9 V DC only with the included power module, verify pin requirements before wiring and keep the laser emitter away from eyes

Wire the virtual sensor and optional outputs

Add the parts in Wokwi’s diagram editor and connect them as follows. The LEDs and buzzer are optional; first get the sensor reading working on its own.

Part Pin Connect to
HC-SR04 VCC Arduino Uno 5V
HC-SR04 TRIG Arduino Uno digital pin 9
HC-SR04 ECHO Arduino Uno digital pin 10
HC-SR04 GND Arduino Uno GND
LEDs, optional Anode (+) Digital pins 4, 5, and 6, each through a current-limiting resistor
LEDs, optional Cathode (−) GND
Piezo buzzer, optional Positive (+) Arduino Uno digital pin 3
Piezo buzzer, optional Negative (−) GND

The sensor’s VCC, TRIG, ECHO, and GND roles are documented in the HC-SR04 reference. The output pin choices are settings for this example; keep the wiring and sketch assignments matched if you choose different pins.

Rank #2
Sale
ELEGOO Mega 2560 R3 Project The Most Complete Starter Kit with Tutorial
  • 35+ Guided Electronics Projects: Progress from LEDs and buttons to RFID access, real-time clocks, motion and distance sensing, environmental monitoring, motor control and interactive displays for STEM learning, coding clubs and maker projects
  • More I/O and Memory for Larger Builds: The MEGA 2560 R3 provides 54 digital I/O pins, including 15 PWM outputs, 16 analog inputs, 4 hardware serial ports and 256 KB flash for projects that combine more sensors, controls and displays
  • 200+ Components for Prototyping: Includes LCD1602, RC522 RFID, RTC, DHT11, HC-SR501 PIR, ultrasonic and water-level sensors, GY-521, MAX7219, keypad, joystick, rotary encoder, relay, SG90 servo, stepper motor, DC motor, breadboard and more
  • Learn, Modify and Create: Follow 35+ guided lessons with example code, then adjust sensor thresholds, timing, display text, motor behavior and control logic to turn structured exercises into access systems, monitors, alarms and interactive projects
  • Organized for Repeatable Learning: Pre-soldered modules, a solderless breadboard, storage case and small-parts box reduce setup time and keep sensors, LEDs, ICs, wires and other components easy to find between projects

Read and print distance with a minimal sketch

Paste this into the Arduino editor. It sends the trigger pulse, measures ECHO with pulseIn, converts the duration to centimeters, and prints the result to the serial monitor.

const int trigPin = 9;
const int echoPin = 10;

void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  unsigned long duration = pulseIn(echoPin, HIGH);
  float distanceCm = duration / 58.0;

  Serial.print("Distance: ");
  Serial.print(distanceCm);
  Serial.println(" cm");
  delay(200);
}

The 10-microsecond trigger pulse and centimeters conversion follow Wokwi’s sensor reference. In this first version, pulseIn has no explicit timeout argument. If you later add timeout handling, test the no-echo case as well as ordinary distances so your program does not treat a missing echo as a valid reading.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
HiLetgo 37 Sensor Assortment Kit for Arduino & Raspberry Pi - 37 in 1 Robot Project Starter Kit
  • 37 Sensors kit
  • 37 Sensors Assortment Kit for Arduino MCU Education
  • Touch sensor moduleHeartbeat detection module
  • Infrared sensor receiver module

Test the sensor by changing virtual distance

  1. Start the simulation in Wokwi.
  2. Open the HC-SR04 component controls and move its distance slider.
  3. Watch the serial monitor as you try a far reading, a reading within your chosen warning band, and a close reading.
  4. Change the slider again after any code edit; confirm the output changes in the direction you expect.

The simulator’s distance control makes it possible to test several input cases without moving a physical obstacle. It verifies how your sketch responds to simulated readings; it does not establish real-world sensor accuracy.

Add distance bands, LEDs, and a buzzer

Once serial readings work, use three deliberately chosen bands to make the response visible and audible. In this example, more than 50 cm is “far,” 20–50 cm is “warning,” and less than 20 cm is “near.” These are convenient project settings, not universal parking limits or safety advice.

Rank #4
Sale
SunFounder Universal Maker Sensor Kit Compatible with Arduino Mega 2560/Uno R3/R4 Minima/WiFi Nano, Raspberry Pi 5/4B/3B+/Zero 2 W/, Pico W, ESP32, C++, Python, MicroPython, Beginners & Engineers
  • Wide Compatibility**: Supports Arduino series (R4 WiFi/Minima/R3/Mega 2560), and Raspberry Pi 5/4/3B+/3B/Zero, Raspberry Pi Pico W, ESP32, accommodating a broad range of development platforms. Contains 169 projects
  • Diverse Components**: Over 25 sensors, actuators, and display modules for a variety of projects. It's perfect for environmental monitoring, smart home projects, robotics, and game controllers
  • Step-by-Step Tutorials**: Comes with comprehensive guides for Arduino, Raspberry Pi, Pico w, ESP32 for each component, including courses in C/C++ and Python/MicroPython programming languages, ideal for both beginners and advanced users to start quickly
  • Projects for All Levels**: Offers projects that help users grow from novices to experts in electronics and programming, fostering innovation and creativity
  • Dedicated Support: Benefit from our ongoing assistance, including a community forum and timely technical help for a seamless learning experience

Replace the first sketch with this version, then wire the optional outputs using the table above. A green LED indicates far, yellow indicates warning, and red indicates near. The buzzer is silent when far and beeps more frequently as the simulated object gets closer.

const int trigPin = 9;
const int echoPin = 10;
const int greenPin = 4;
const int yellowPin = 5;
const int redPin = 6;
const int buzzerPin = 3;

void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
  pinMode(redPin, OUTPUT);
  pinMode(buzzerPin, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  unsigned long duration = pulseIn(echoPin, HIGH);
  float distanceCm = duration / 58.0;

  Serial.print("Distance: ");
  Serial.print(distanceCm);
  Serial.println(" cm");

  digitalWrite(greenPin, LOW);
  digitalWrite(yellowPin, LOW);
  digitalWrite(redPin, LOW);
  noTone(buzzerPin);

  if (distanceCm > 50) {
    digitalWrite(greenPin, HIGH);
    delay(200);
  } else if (distanceCm >= 20) {
    digitalWrite(yellowPin, HIGH);
    tone(buzzerPin, 1000);
    delay(300);
    noTone(buzzerPin);
    delay(300);
  } else {
    digitalWrite(redPin, HIGH);
    tone(buzzerPin, 1000);
    delay(100);
    noTone(buzzerPin);
    delay(100);
  }
}

Move the slider through distances above 50 cm, between 20 and 50 cm, and below 20 cm. Confirm that the LED changes at each boundary and that the beep interval shortens in the near band. Wokwi’s community parking sensor example also changes RGB LED and speaker behavior across distance ranges, but its thresholds are an illustrative design rather than a standard: Parking Sensor With HC-SR04.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Horizon Uno Electronics Starter Kit with Video Lessons – Arduino-Compatible Board, Sensors, LEDs, Servos & More – Learn Electronics & Coding for Beginners
  • All-in-One Electronics & Coding Starter Kit: Learn the fundamentals of electronics, coding, and circuit design with the Horizon Uno board (Arduino-compatible), LEDs, sensors, and specialty components — everything you need to start building.
  • Includes Step-by-Step Video Lessons: Gain lifetime access to a full online video course created by robotics engineers. Each lesson walks you through real-world projects, coding examples, and clear explanations designed for beginners. Each kit comes with a unique access code to access on our course website. The course includes lectures, labs, projects and problem sets.
  • High-Quality Components for Reliable Learning: Each kit includes premium parts for accurate circuit performance — from durable resistors and sensors to jumper wires and LEDs — ensuring a frustration-free learning experience.
  • Perfect for Students, Educators & Hobbyists: Ideal for classrooms, STEM programs, and self-learners. The Horizon Uno Kit makes it easy for beginners to grasp the fundamentals of electricity, coding logic, and microcontroller programming.
  • Learn, Build & Innovate with Horizon Robotics Lab: Backed by an experienced team of engineers and educators, Horizon Robotics Lab is dedicated to making robotics and electronics education accessible, inspiring learners to build cool projects and bring ideas to life.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use AI as a tutor, then verify the code

An AI assistant can help you understand a sketch or propose a focused edit. It is not a substitute for checking the result: ask for an explanation, preserve your known-working version, and run the revised code through multiple slider positions.

  • “Explain this pulseIn code line by line.”
  • “Add three named distance bands without changing my pin assignments.”
  • “Review this sketch for an ECHO timeout case and explain your proposed change.”

For each suggestion, compare the code with your wiring, run the simulation, and test far, warning, and near readings. If you add a third-party Arduino library, check that it works with Wokwi; its Arduino Libraries guide explains how to use libraries in projects.

What simulation can—and cannot—tell you

A successful simulation shows that the sketch runs in the simulated circuit and responds to the virtual distance control. It does not prove that a physical sensor will give the same readings, that wiring is safe, or that a vehicle installation is reliable. A 2024 paper by Auliani and co-authors describes a simulated Arduino Uno and HC-SR04 parking sensor, but a simulation is not a real-hardware accuracy test: Simulasi Sensor Parkir Berbasis Mikrokontroler Arduino Uno dengan Sensor HC-SR04 Menggunakan Website Wokwi, published online November 29, 2024.

When you are ready to extend the lesson at a desk, optional parts include an HC-SR04 sensor, an Arduino Uno-compatible board, a breadboard, jumper wires, LEDs with resistors, and a buzzer. A physical build requires separate checks of wiring, electrical limits, sensor placement, and noisy readings; none is needed to complete the browser-based exercise.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.