Find out where the sensor fails: too close, too far, too soft or at an angle. The LEDs and the Serial Monitor count each kind of reading.
| Part | How many |
|---|---|
| Wiring from Lesson 3 - nothing new | |
| A book, a cushion or jumper, and a pencil (yours) |
Nothing extra - just the kit and your computer.
Very close up, the echo comes back before the sensor has finished sending, so the reading is wrong or missing. That is the blind zone.
No echo can mean the object is too far, too soft (fabric absorbs sound), too small, or tilted so the echo flies off to the side. It does NOT mean nothing is there.
In this lesson only, the LEDs mean something different: green = a good reading, yellow = too close (under 3 cm), red = no echo.
Three variables count each kind of reading. Type r and press Enter to set them back to 0 before each test.
Every item is in the kit — nothing extra to buy.
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. red/yellow/green LEDs, Serial Monitor, the wiring from Lesson 3: 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 | Same as Lesson 3 | LEDs 5, 6, 7 · buzzer 8 (kept silent) · TRIG 9 · ECHO 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 4 of 9: Blind Zone & No Echo
WIRING: the sensor and LEDs from Lessons 1-3 (pins 5, 6, 7, 9, 10).
The buzzer can stay connected - this sketch keeps it silent.
IN THIS LESSON THE LEDs MEAN SOMETHING DIFFERENT:
Green = a good reading
Yellow = too close (under 3 cm) - the sensor's "blind zone"
Red = no echo came back (too far, too soft, or angled away)
The Serial Monitor (9600 baud) counts each kind of reading.
Type r and press Enter to set the counts back to 0.
*/
const int RED_LED = 5;
const int YELLOW_LED = 6;
const int GREEN_LED = 7;
const int BUZZER_PIN = 8;
const int TRIG_PIN = 9;
const int ECHO_PIN = 10;
const int BLIND_CM = 3; // closer than this is the blind zone
const unsigned long ECHO_TIMEOUT_US = 30000; // after 30 ms we call it "no echo"
const int MAX_CM = 400;
int goodCount = 0;
int blindCount = 0;
int noEchoCount = 0;
// Distance in cm, or 0 if no echo came back in time.
long readRawCm() {
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;
return us / 58;
}
void setup() {
pinMode(RED_LED, OUTPUT);
pinMode(YELLOW_LED, OUTPUT);
pinMode(GREEN_LED, OUTPUT);
pinMode(BUZZER_PIN, OUTPUT);
digitalWrite(BUZZER_PIN, LOW); // keep the buzzer quiet in this lesson
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
Serial.begin(9600);
Serial.println("Lesson 4: Blind Zone & No Echo");
}
void loop() {
// Type r + Enter to reset the counts.
while (Serial.available() > 0) {
char c = Serial.read();
if (c == 'r' || c == 'R') {
goodCount = 0;
blindCount = 0;
noEchoCount = 0;
Serial.println("Counts reset");
}
}
long cm = readRawCm();
bool noEcho = (cm == 0 || cm > MAX_CM);
bool blind = (!noEcho && cm < BLIND_CM);
bool good = (!noEcho && !blind);
digitalWrite(RED_LED, noEcho ? HIGH : LOW);
digitalWrite(YELLOW_LED, blind ? HIGH : LOW);
digitalWrite(GREEN_LED, good ? HIGH : LOW);
if (noEcho) noEchoCount++;
else if (blind) blindCount++;
else goodCount++;
Serial.print("cm=");
if (noEcho) Serial.print("none");
else Serial.print(cm);
Serial.print(" good=");
Serial.print(goodCount);
Serial.print(" too_close=");
Serial.print(blindCount);
Serial.print(" no_echo=");
Serial.println(noEchoCount);
delay(200);
}
| In the code | What it does |
|---|---|
| const int BLIND_CM = 3; | Readings closer than 3 cm count as "too close". |
| int goodCount = 0; ... | Three counters. ++ adds one each time. |
| while (Serial.available() > 0) | Reads anything you typed. If it is r, the counts go back to 0. |
| digitalWrite(BUZZER_PIN, LOW); | Keeps the buzzer from Lesson 3 quiet in this lesson. |
| Problem | What to check |
|---|---|
| Always red | 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. |
| Typing r does nothing | Click in the box at the top of the Serial Monitor, type r, then press Enter. Check the speed is 9600 baud. |
| Yellow never lights | Many sensors give no echo rather than a small number when very close, so red is also a correct result. |
| The buzzer sounds | Upload the Lesson 4 code again - it keeps pin 8 LOW. |
Make a table: book, cushion, pencil, tilted book, empty room. For each, write good / too close / no echo after 10 seconds. Which target is hardest for the sensor?
No. The object may be too far, too soft, too thin or tilted away.
The echo comes back before the sensor has finished sending: that is the blind zone.
Green good reading, yellow too close, red no echo.
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.
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.
Why does the sensor sometimes miss things right in front of it? Fire 20 pings at flat, soft, round, thin and tilted targets and count how many echoes come back.
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.