Sharjah, UAE GST
Home/ Projects/ Lesson 6: Angles & Surfaces
Lesson 6 of 9 Sensing Beginner ◎ 40 min

Lesson 6: Angles & Surfaces

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.

Arduino Ultrasonic Distance & Parking Learning Kit
One of 9 projects in the Arduino Ultrasonic Distance & Parking Learning Kit — the parts below are from that kit.

Before you start

Time
40 min
Do these first
On your own
You can do this lesson on your own.

Exact parts

PartHow many
Wiring from Lesson 1 (the other parts can stay)
Flat card, cushion or jumper, bottle, pencil (yours)

Not in the box

  • Test objects: a flat card, a cushion or jumper, a bottle and a pencil (yours)

What you build and learn

  • How echoes reflect like light in a mirror
  • Why soft, small and tilted targets are hard to detect
  • Running a fair test: change one thing at a time
  • Recording results in a table

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.

New words

Reflection
Sound bouncing off a surface. A flat surface sends it straight back if it faces the sensor.
Absorb
Soak up. Soft materials like cushions absorb sound instead of reflecting it.
Fair test
An experiment where you change only one thing, so you know what caused the difference.

What this project uses

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).

Build this with

Arduino Ultrasonic Distance & Parking Learning Kit

All 9 parts in one box, with this project and 8 more to build from them.

AED 85.00 See the kit
Need only these parts? Order them loose · from AED 78.30
Used in this project tick what you still need
Also needed untick if you already have them
Selected parts AED 78.30

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+.

Connections

Unplug USB before you change any wire. Pin names are the labels printed on the board.

Lesson 6: Angles & Surfaces - connection diagram with labelled pins
Connection diagram, drawn from this lesson's pin plan - not a photo of a tested build. Tap to open it full size. The table below says the same thing in words.
Part / pinConnect toNote
No changesSensor as in Lesson 1TRIG pin 9 · ECHO pin 10

Step by step

One thing at a time. Tick nothing off until it matches the diagram.

  1. Upload the Lesson 6 code. No wiring changes are needed.
  2. Open the Serial Monitor at 9600 baud.
  3. Put the flat card 30 cm away, square to the sensor. Wait for a row.
  4. After "Change the target now", swap to the next target at the same 30 cm: card tilted about 45°, cushion, bottle, pencil.Watch out: Keep the distance the same: change only the target.
  5. Copy the rows into a table or spreadsheet and compare the missed %.

Sketch for this project

Written for the board in the kit. Copy it into the Arduino IDE; change the pin numbers if you wire it differently.

lesson6_angle_surface.ino arduino
/*
  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);
}
ℹCompiler-checked for Arduino UNO (0 warnings) and run in the kit simulator. Pins match the lesson diagram. Not yet bench-tested on the shipped parts.

Upload it

  1. Click Copy (or Download .ino and open the file).
  2. In the Arduino IDE choose File → New Sketch, select everything in it and paste.
  3. Check the bottom of the window says Arduino Uno and your port (Start here, step 5).
  4. Click Upload (the → arrow) and wait for Done uploading.

How the code works

In the codeWhat it does
const int PINGS = 20;How many pings make one trial.
back = back + 1;Counts the pings that came back.
(PINGS - back) * 100 / PINGSThe share of pings that were missed, as a percentage.
delay(GAP_MS);A 5-second pause for you to change the target.

Change it and see

Change: Change GAP_MS from 5000 to 10000.What happens: You get 10 seconds to change the target.
Change: Change PINGS from 20 to 50.What happens: Each trial takes longer, and the percentages are more reliable.

What you should see or hear

  • Flat card: 20 echoes back, 0% missed, steady average.
  • Tilted card, cushion or pencil: fewer echoes and a bigger gap between min and max.
  • A row ending in NA,NA,NA means no echo came back at all.

If it doesn't work

ProblemWhat to check
Every target gives 20 echoesTry 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 echoesUnplug 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 MonitorSet the speed in the corner of the Serial Monitor to 9600 baud. Close the Serial Plotter if it is open.

Small experiment

Tilt the card in steps of 15° (0°, 15°, 30°, 45°, 60°). At what angle do the echoes start to go missing?

Check what you learned

Why does a tilted card return fewer echoes?

The sound bounces off at an angle and misses the sensor's receiver.

Why is a cushion hard to detect?

Soft material absorbs the sound, so the echo is weak.

What makes this a fair test?

Only the target changes; the distance and the sensor stay the same.

▶In the simulator: The simulator cannot model angles or soft materials: every ping returns. This lesson needs the real sensor.

Next

  • Lesson 7 smooths out noisy readings with two kinds of filter.

Stuck?

Most problems are one wire in the wrong hole. Check these first:

  1. Unplug, then compare every wire with the lesson's diagram and table. One pin off is the most common problem.
  2. Sensor: are VCC, TRIG, ECHO and GND wired by their labels, with TRIG on 9 and ECHO on 10?
  3. LEDs: is the long leg on the resistor side?
  4. Is the − rail connected to a UNO GND pin, and the + rail to 5V?
  5. Serial Monitor: is it set to 9600 baud (and "New Line" when you type commands)?
  6. Upload problems: is Tools → Board set to Arduino Uno and Tools → Port to your UNO? (Start here, step 5.)
Still stuck? Ask us on WhatsApp. Send this message with a photo of your wiring - it tells us exactly where you are.
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.
Message us on WhatsApp

More from this kit

All projects →

Bot
ECHO
Online — usually replies instantly
Catalog assistant: verify final stock/price on the product page before checkout.