Build obstacle-warning glasses that help blind people avoid things at head height

A white cane finds obstacles on the ground, but not a branch, an open cupboard door or a sign at head height. Build glasses with an ultrasonic sensor on each side and a buzzer at each ear: the closer something...
  • Level:Advanced
  • Duration: 3 h
  • Ages 12+
  • Platform: Arduino

Tools for this lesson

Helpful for this build. Open a tool to see tips and more projects that use it.

Build obstacle-warning glasses that help blind people avoid things at head height – EEMENTOR STEM™ lesson

People who are blind or have low vision often walk with a white cane. It is brilliant at finding steps, kerbs and things on the ground, but it can't find what is at head height: a low branch, an open cupboard door, a sign, a shop awning. In this capstone you build obstacle-warning glasses that look out at exactly that height. An ultrasonic sensor on each side of the glasses measures the distance to whatever is in front of you, and a small buzzer at each ear beeps faster the closer it gets: the left buzzer for the left side, the right buzzer for the right side. So you don't just hear that something is there, you hear where. A button switches between a short range for indoors and a longer one for outside. The glasses themselves come out of a 3D printer, with housings for the sensors above the eyes and pockets for the buzzers on the arms, and the UNO runs from the kit's 9 V battery in your pocket or on a belt.

What you'll learn

  • How an ultrasonic sensor measures distance with echoes, and why two sensors must take turns
  • How a median filter throws away single wrong readings
  • How to beep two buzzers at different speeds at the same time with millis(), without delay()
  • How to turn a distance into a beep speed with map()
  • How assistive technology is designed: what a device should and shouldn't do, and why testing with real users matters

What you need

  • UNO R3 board and USB cable (UNO R3 Starter Kit)
  • 2 HC-SR04 ultrasonic sensors (one from the UNO R3 Starter Kit, one from the 45-in-1 Sensor Kit). With only one sensor, set TWO_SENSORS = false and use the left side.
  • Active buzzer (UNO R3 Starter Kit) and active buzzer module (45-in-1 Sensor Kit)
  • Push button (UNO R3 Starter Kit)
  • 9 V battery and battery snap (UNO R3 Starter Kit)
  • Long jumper wires or a strip of ribbon cable with at least 13 wires (about 60 cm, from the glasses to the UNO), and a few cable ties
  • The printed parts from the 3D printing box below (glasses front and two arms), or the cardboard version described there
  • A small box or pouch for the UNO and the breadboard, to wear on a belt or a lanyard
  • Breadboard and jumper wires (UNO R3 Starter Kit)

Safety: this is a learning project, not a medical device. Never use it instead of a white cane or a guide dog, and never use it near roads, stairs or water. Test it slowly, indoors, with a friend watching, and with your eyes open first. Ultrasound reflects badly off soft things (curtains, clothes, plants) and very thin things (poles, wires), so the glasses can miss them. This design has not been tested with blind users: don't give it to anyone to rely on. The buzzers are loud: point them away from the ear opening, never into it, and put a piece of tape over the hole if they are too loud.

Wiring

Breadboard wiring diagram: Build obstacle-warning glasses that help blind people avoid things at head height
Breadboard view. Check each connection against the wiring table below.

Build it step by step

Plug in all the parts first, then add the wires in this order. In each picture the new wires are bright and the ones from earlier steps are faded. Click a picture to see it larger.

Step 1 of 6: Power rails: 5V and GND from the UNO
Step 1. Power rails: 5V and GND from the UNO
Step 2 of 6: Left sensor: Trig → pin 9, Echo → pin 10, VCC and GND to the rails
Step 2. Left sensor: Trig → pin 9, Echo → pin 10, VCC and GND to the rails
Step 3 of 6: Right sensor: Trig → pin 11, Echo → pin 12, VCC and GND to the rails
Step 3. Right sensor: Trig → pin 11, Echo → pin 12, VCC and GND to the rails
Step 4 of 6: Active buzzer (left ear): + → pin 7, − → − rail
Step 4. Active buzzer (left ear): + → pin 7, − → − rail
Step 5 of 6: Active buzzer module (right ear): S → pin 6, + and − to the rails
Step 5. Active buzzer module (right ear): S → pin 6, + and − to the rails
Step 6 of 6: Range button: pin 2 and the − rail
Step 6. Range button: pin 2 and the − rail
From To
Both sensors VCC 5V
Both sensors GND GND
Left sensor Trig, Echo UNO pins 9, 10
Right sensor Trig, Echo UNO pins 11, 12
Active buzzer + (longer leg) UNO pin 7
Active buzzer − GND
Active buzzer module S (signal) UNO pin 6
Active buzzer module + and − 5V and GND (if your module has no + pin, leave it out)
Push button One leg to UNO pin 2, the other to GND
9 V battery snap: red, black UNO VIN, GND (when you go mobile; unplug the USB cable then). Double-check: red to VIN. A battery connected the wrong way round can destroy the UNO.

Sensor modules from different makers can label and order their pins differently. Always follow the labels printed on your module.

Build and test everything on the breadboard first, with the sensors standing on the table. When it works, put the sensors into the printed glasses and connect them with long wires: four wires per sensor (VCC, Trig, Echo, GND). Twist or tape each sensor's four wires together, and run them along the arms of the glasses and down behind your ear to the box on your belt. The two buzzers go into the round pockets on the arms, sound hole outwards, away from the ear opening: two long wires for the bare buzzer (+ and −) and three for the module (S, + and −). That makes 13 wires from the glasses to the box. Tape the battery snap when it isn't connected, so the 9 V battery can't short out in a pocket. Fix every wire with cable ties through the slots in the arms, so nothing pulls on the pins when you turn your head.

FREE

Build this circuit in EEMENTOR Lab

Wire it yourself in your browser before you touch a real wire. No sign-up, nothing to install.

The UNO and the parts for this lesson laid out in EEMENTOR Lab, ready to wireBuild it yourself
  1. The UNO and this lesson’s parts are already placed. Wire them using the wiring table above. Pins with no wire show red.
  2. Missing a part? Add it from the parts list on the left.
  3. Press Run, then try the inputs: click, hold or slide them under Selected.
  4. Then try this lesson’s sketch: paste it into the Code tab and press Compile & Run.

EEMENTOR Lab is free and in beta. Results are a guide; a real build can differ slightly. About the Lab

The sketch

// Obstacle glasses: an ultrasonic sensor on each side of the glasses, a buzzer at each ear.
// The closer an obstacle, the faster that side beeps. Very close: a steady tone.
const int TRIG[2] = {9, 11};          // left, right
const int ECHO[2] = {10, 12};
const int BUZZER[2] = {7, 6};         // left: active buzzer, right: active buzzer module
const int BUTTON = 2;                 // switches between indoor and outdoor range
const bool TWO_SENSORS = true;        // false if you only have one sensor (use the left one)
const int RANGE[2] = {80, 150};       // warning distance in cm: indoors, outdoors
const int TOO_CLOSE = 25;             // closer than this: a steady tone
const int BEEP_MS = 40;               // how long each beep is

int range = 1;                        // start with the outdoor range
int history[2][3] = {{999, 999, 999}, {999, 999, 999}};   // the last 3 readings of each side
int dist[2] = {999, 999};             // the smoothed distance of each side
unsigned long nextBeep[2] = {0, 0}, beepOff[2] = {0, 0}, beepStart[2] = {0, 0};
unsigned long lastPrint = 0, lastMeasure = 0, lastChange = 0;
int side = 0;                         // which sensor measures next
bool lastButton = HIGH;

long measure(int s) {                 // one reading in cm, 999 = nothing in range
  digitalWrite(TRIG[s], LOW);
  delayMicroseconds(2);
  digitalWrite(TRIG[s], HIGH);        // a 10 µs pulse makes the sensor send 8 cycles of 40 kHz sound
  delayMicroseconds(10);
  digitalWrite(TRIG[s], LOW);
  long t = pulseIn(ECHO[s], HIGH, 25000);   // wait at most 25 ms (about 4 m)
  if (t == 0) return 999;
  return t / 58;                      // sound needs about 58 µs per cm there and back
}

int median3(int a, int b, int c) {    // the middle one of three: ignores one wild reading
  if (a > b) { int t = a; a = b; b = t; }
  if (b > c) { int t = b; b = c; c = t; }
  if (a > b) { int t = a; a = b; b = t; }
  return b;
}

void beepAll(int times) {
  for (int i = 0; i < times; i++) {
    digitalWrite(BUZZER[0], HIGH);
    digitalWrite(BUZZER[1], HIGH);
    delay(80);
    digitalWrite(BUZZER[0], LOW);
    digitalWrite(BUZZER[1], LOW);
    delay(120);
  }
}

void setup() {
  for (int s = 0; s < 2; s++) {
    pinMode(TRIG[s], OUTPUT);
    pinMode(ECHO[s], INPUT);
    pinMode(BUZZER[s], OUTPUT);
  }
  pinMode(BUTTON, INPUT_PULLUP);
  Serial.begin(9600);
  beepAll(2);                         // two beeps: outdoor range, ready
  Serial.println("Obstacle glasses ready (outdoor range, 150 cm)");
}

void loop() {
  unsigned long now = millis();

  // ---- measure one side every 50 ms, taking turns, so one sensor rarely hears the other's echo ----
  if (now - lastMeasure >= 50) {
    lastMeasure = now;
    if (side == 0 || TWO_SENSORS) {
      history[side][0] = history[side][1];
      history[side][1] = history[side][2];
      history[side][2] = measure(side);
      dist[side] = median3(history[side][0], history[side][1], history[side][2]);
    }
    side = (side + 1) % 2;
  }

  // ---- beep each side on its own: faster when closer ----
  for (int s = 0; s < 2; s++) {
    int d = dist[s];
    if (d >= RANGE[range]) {                     // nothing near: quiet
      digitalWrite(BUZZER[s], LOW);
      continue;
    }
    if (d < TOO_CLOSE) {                         // very close: steady tone
      digitalWrite(BUZZER[s], HIGH);
      continue;
    }
    int gap = map(d, TOO_CLOSE, RANGE[range], 80, 700);   // 25 cm: every 80 ms ... far: every 700 ms
    nextBeep[s] = min(nextBeep[s], beepStart[s] + BEEP_MS + gap);   // coming closer: the next beep comes sooner
    if (now >= nextBeep[s]) {
      digitalWrite(BUZZER[s], HIGH);
      beepStart[s] = now;
      beepOff[s] = now + BEEP_MS;
      nextBeep[s] = now + BEEP_MS + gap;
    }
    if (now >= beepOff[s]) digitalWrite(BUZZER[s], LOW);
  }

  // ---- the button switches the range: 1 beep = indoors, 2 beeps = outdoors ----
  bool button = digitalRead(BUTTON);
  if (button != lastButton && now - lastChange > 50) {   // ignore the bouncing of the contacts
    lastChange = now;
    lastButton = button;
    if (button == LOW) {
    range = 1 - range;
    digitalWrite(BUZZER[0], LOW);
    digitalWrite(BUZZER[1], LOW);
    delay(150);
    beepAll(range + 1);
    Serial.print(range ? "Outdoor" : "Indoor");
    Serial.print(" range: ");
    Serial.print(RANGE[range]);
    Serial.println(" cm");
    }
  }

  // ---- show both distances 3 times a second ----
  if (now - lastPrint >= 300) {
    lastPrint = now;
    Serial.print("Left: ");
    if (dist[0] >= 999) Serial.print("--"); else { Serial.print(dist[0]); Serial.print(" cm"); }
    Serial.print("   Right: ");
    if (!TWO_SENSORS) Serial.println("off");
    else if (dist[1] >= 999) Serial.println("--");
    else { Serial.print(dist[1]); Serial.println(" cm"); }
  }
}

Try it

  1. Upload the sketch with the sensors on the table, pointing towards open space at least 2 m away. Both buzzers beep twice: ready, outdoor range.
  2. Open the Serial Monitor at 9600 baud. It shows both distances three times a second, for example Left: 112 cm Right: --. "--" means nothing within about 4 m.
  3. Move your hand slowly towards the left sensor: the left buzzer starts beeping at 150 cm and beeps faster and faster. Closer than 25 cm it gives a steady tone. Try the right sensor: only the right buzzer reacts.
  4. Press the button: one beep means the indoor range (80 cm), two beeps the outdoor range (150 cm). Indoors the shorter range stops the glasses from beeping at every wall.
  5. Put the sensors into the printed glasses, put them on and switch to the 9 V battery. Walk slowly towards an open door or a big piece of cardboard held at head height, eyes open: you should hear it coming, and hear on which side it is.
  6. Ask a friend to hold a big piece of cardboard at head height to your left or right and move it slowly. With your eyes closed and your friend guiding you, can you tell where it is just from the sound?

What you should see

Serial Monitor at 9600 baud showing the left distance falling from 160 to 20 cm, the range button lines, and a top view of a person with a white cane walking towards an open door while the left buzzer beeps faster and the right stays quiet.

How it works

How the glasses measure: a 10 µs Trig pulse and a 3480 µs echo giving 60 cm, the two sensors taking turns every 50 ms with a median of 61, 220, 59 giving 61 cm, and a graph of beep gap from 80 ms at 25 cm to 700 ms at 150 cm.

An ultrasonic sensor works like a bat. When the UNO sends a 10 µs pulse to Trig, the sensor sends out a short burst of sound at 40 kHz, far too high for us to hear. Then it sets Echo high until the echo comes back from an obstacle. pulseIn() measures how long Echo stays high. Sound travels about 343 metres a second, so it needs about 29 µs per centimetre, and 58 µs per centimetre there and back: the distance in cm is the time divided by 58. If nothing answers within 25 ms (about 4 m), the sketch counts it as "nothing in range".

Two sensors that send at the same moment would hear each other's sound and report nonsense. So they take turns: every 50 ms one of them measures, then the other. Each side keeps its last three readings and uses the median, the middle one. A single wild reading, from an echo that bounced off the floor for example, is simply ignored, while a real obstacle shows up in all three readings within about a third of a second.

The beeping uses millis() instead of delay(), so the two buzzers can beep at different speeds at the same time and the sensors keep measuring in between. For each side, map() turns the distance into a gap between beeps: 25 cm gives a beep about every 120 ms (40 ms beep, 80 ms gap), the edge of the range only about every 740 ms. As you come closer, the next beep is brought forward straight away, so the beeping speeds up without waiting for a slow beep to finish. Hearing the speed change is easier than hearing a pitch change, and each ear only hears its own side, so your brain can work out the direction by itself. Real electronic travel aids for blind people use the same tricks: ultrasound or laser, sound or vibration, and often a choice of ranges. They are tested with blind users for months, because what seems clever on the bench can be tiring or confusing on a busy street. The ultrasonic walking aid is the hand-held, one-sensor version of this idea.

Try this next

  • Use vibration instead of sound, so the ears stay free for traffic and voices: the 3–6 V motor from the kit with a little off-centre weight on its shaft, driven through a transistor as in the motor speed lesson.
  • Add a third sensor in the middle, pointing slightly down, to warn about steps going down, and give it its own sound.
  • Use the passive buzzer instead of the active one and change the pitch with the distance as well as the speed. Which is easier to understand?
  • Ask someone who is blind or visually impaired what they would want from such glasses, and change the ranges, sounds or button to match. Designing with users is what makes assistive technology work.
  • Add a battery warning: measure the 9 V battery with a voltage divider, as in the battery tester, and give a special beep pattern when it gets low.

Troubleshooting

  • A side always shows "--": check that sensor's Trig and Echo wires (pins 9 and 10 for the left, 11 and 12 for the right) and its VCC and GND. Long wires can come loose: test each one.
  • A buzzer beeps all the time, even with nothing in front: the sensor sees the floor, your cheek or the glasses' frame. Tilt the glasses up a little on your nose or use the indoor range, and make sure nothing (hair, a cap) is in front of the transducers.
  • The distances jump around: soft or slanted surfaces reflect sound badly. Hard flat surfaces such as walls and doors work best. Also check that the two sensors aren't pointing at each other.
  • The buzzer module beeps all the time and goes quiet when it should beep: some active buzzer modules sound when the signal is LOW instead of HIGH. Swap HIGH and LOW for that buzzer in the sketch, or use a second bare active buzzer.
  • False beeps every time a buzzer sounds: the long wires pick up the buzzer's current bursts. Put a 100 µF capacitor across each sensor's VCC and GND at the glasses end (stripe to GND).
  • The button does nothing: the button must sit across the middle gap of the breadboard, one leg to pin 2 and the other to GND.
  • It stops working on the battery: the 9 V battery is empty (they don't last long with two sensors), or the snap's red wire isn't on VIN. A USB power bank on the UNO's USB socket lasts much longer.
  • A printed part is too tight or too loose: printers differ by a few tenths of a millimetre. Sand or file a tight hole, and fix a loose part with a drop of hot glue or a strip of tape.