Fire 20 pings at different targets - flat, soft, round, thin, tilted - and count how many echoes come back. Find out what the sensor finds hard to see.
| Part | How many |
|---|---|
| Wiring from Lesson 1 (the other parts can stay) | |
| Flat card, cushion or jumper, bottle, pencil (yours) |
Sound bounces off a flat surface at the same angle it arrives, like a ball off a wall. A card facing the sensor sends the echo straight back; a tilted card sends it off to the side.
Soft materials absorb much of the sound, so the echo is weak. Thin or round objects reflect only a little sound back towards the sensor.
Each trial fires 20 pings, 50 ms apart, then prints: trial, echoes back, missed %, average, min and max. You then have 5 seconds to change the target.
This is why real distance sensors are never the only safety check: they can miss things that are really there.
Every item below is in the kit. Not in the box: Test objects: a flat card, a cushion or jumper, a bottle and a pencil (yours).
All 9 parts in one box, with this project and 8 more to build from them.
One of each part. Packs (resistor assortment, jumper wires) already hold more than a single build needs. a flat card, a bottle, a pencil (yours): included in the kit, ask us for it loose. Delivery is AED 20, free on orders AED 100+.
Unplug USB before you change any wire. Pin names are the labels printed on the board.
| Part / pin | Connect to | Note |
|---|---|---|
| No changes | Sensor as in Lesson 1 | TRIG pin 9 · ECHO pin 10 |
One thing at a time. Tick nothing off until it matches the diagram.
Written for the board in the kit. Copy it into the Arduino IDE; change the pin numbers if you wire it differently.
/*
DIY KIT - Arduino Ultrasonic Distance & Parking Learning Kit
Lesson 6 of 9: Angles & Surfaces
WIRING: the sensor from Lesson 1 (TRIG pin 9, ECHO pin 10).
HOW TO USE IT
Every 5 seconds the UNO fires 20 pings at the target and prints one row:
trial, echoes_back, missed_percent, average_cm, min_cm, max_cm
Between rows, change the target: flat card, card tilted, a cushion or
jumper, a bottle, a pencil. Keep it at the same distance (about 30 cm).
Open the Serial Monitor at 9600 baud.
*/
const int TRIG_PIN = 9;
const int ECHO_PIN = 10;
const int PINGS = 20; // pings per trial
const unsigned long GAP_MS = 5000; // time to change the target
const unsigned long ECHO_TIMEOUT_US = 30000;
const int MIN_CM = 2;
const int MAX_CM = 400;
int trial = 0;
long readOnceCm() {
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
unsigned long us = pulseIn(ECHO_PIN, HIGH, ECHO_TIMEOUT_US);
if (us == 0) return 0;
long cm = us / 58;
if (cm < MIN_CM || cm > MAX_CM) return 0;
return cm;
}
void setup() {
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
Serial.begin(9600);
Serial.println("Lesson 6: Angles & Surfaces");
Serial.println("trial,echoes_back,missed_percent,average_cm,min_cm,max_cm");
}
void loop() {
int back = 0;
long total = 0;
long lowest = 9999;
long highest = 0;
for (int i = 0; i < PINGS; i++) {
long cm = readOnceCm();
if (cm > 0) {
back = back + 1;
total = total + cm;
if (cm < lowest) lowest = cm;
if (cm > highest) highest = cm;
}
delay(50);
}
trial = trial + 1;
int missedPercent = (PINGS - back) * 100 / PINGS;
Serial.print(trial); Serial.print(",");
Serial.print(back); Serial.print(",");
Serial.print(missedPercent); Serial.print(",");
if (back > 0) {
long average = total / back;
Serial.print(average); Serial.print(",");
Serial.print(lowest); Serial.print(",");
Serial.println(highest);
} else {
Serial.println("NA,NA,NA");
}
Serial.println("Change the target now - next trial in 5 seconds.");
delay(GAP_MS);
}
| In the code | What it does |
|---|---|
| const int PINGS = 20; | How many pings make one trial. |
| back = back + 1; | Counts the pings that came back. |
| (PINGS - back) * 100 / PINGS | The share of pings that were missed, as a percentage. |
| delay(GAP_MS); | A 5-second pause for you to change the target. |
| Problem | What to check |
|---|---|
| Every target gives 20 echoes | Try a steeper tilt (60°) or move the target further away (50 cm). Hard surfaces like a bottle may still reflect well. |
| Every target gives 0 echoes | Unplug USB. Check VCC to the + rail, GND to the − rail, TRIG to pin 9 and ECHO to pin 10 - by the labels on the sensor, not their position. Point it at a big flat object 20-50 cm away. |
| Nothing or strange symbols in the Serial Monitor | Set the speed in the corner of the Serial Monitor to 9600 baud. Close the Serial Plotter if it is open. |
Tilt the card in steps of 15° (0°, 15°, 30°, 45°, 60°). At what angle do the echoes start to go missing?
The sound bounces off at an angle and misses the sensor's receiver.
Soft material absorbs the sound, so the echo is weak.
Only the target changes; the distance and the sensor stay the same.
Most problems are one wire in the wrong hole. Check these first:
Open the troubleshooting table for this step →
Hi DIY KIT, I'm stuck on the Arduino Ultrasonic Distance & Parking Learning Kit. Lesson: __ Step number: __ What should happen: __ What happens instead: __ Error message (copied exactly): __ I'll attach a photo of my wiring.
Wire the HC-SR04 and read distances in the Serial Monitor. Compare them with a ruler to see how accurate the sensor really is. Do Start here first.
Find the sensor's limits: too close, too far and off to the side. The LEDs and running counts show good readings, "too close" and "no echo".
Type the ruler distance, get 10 readings back: average, error, minimum, maximum and spread. Paste the rows into a spreadsheet and find your sensor's accuracy.
We use cookies that the shop needs to work — signing in, your cart, form security. We also measure how the shop is used so we can stock the right parts and fix what is broken. Choose “Only essential” and we will not load Google Analytics or the Meta pixel, and will not record your visit. Read more.