As an Amazon Associate we earn from qualifying purchases.
A white cane tells you what is directly in front of your feet, but it cannot warn you about something at chest or head height until you are almost touching it. This project adds ultrasonic distance sensors and an Arduino-style microcontroller to a walking stick. The stick measures the space ahead and signals how far away an obstacle is, so the user gets a spoken or audible cue instead of finding out by contact.
This page covers how the idea works, what you need, the circuit, the full program, and how to improve it. It is a hobby and learning build. Treat it as an extra aid and never as a replacement for a white cane or a guide.
How the talking stick works
Ultrasonic sensors of the common HC-SR04 type send out a short burst of sound above human hearing and wait for the echo. The time between sending and receiving the echo tells you the distance to the object. The code below uses the usual conversion for these modules: the echo time in microseconds divided by 58 gives the distance in centimetres.
The program reads two sensors:
- Sensor 1 (trigger on pin 4, echo on pin 3) measures the distance ahead and sorts it into seven zones, each 35 cm wide.
- Sensor 2 (trigger on pin 8, echo on pin 7) drives a separate output on pin 12 when its reading is greater than 190 cm.
Each zone switches on its own output pin. Those outputs can light an LED while you test, or trigger a message on a voice playback module so the stick can announce the distance. Each pin is switched LOW to activate, so the module or indicator must be wired to respond to a LOW signal.
What you need
- An Arduino-compatible board with analog pins A0 to A5 (an Uno or Nano works)
- Two ultrasonic distance sensors (HC-SR04 style)
- A voice playback module with a speaker or earphone, or LEDs and resistors for testing
- A battery pack suited to your board
- Jumper wires or a small perfboard, plus a stick or cane to mount everything on
- Tape, clips or a small enclosure to hold the electronics firmly
Circuit
The diagram below shows how the parts are connected. Match the wiring to the pin numbers in the program, or change the pin definitions at the top of the code if you wire it differently.

Pin summary
- Pins 3 and 4: echo and trigger for sensor 1
- Pins 7 and 8: echo and trigger for sensor 2
- A5, A4, A3, A2, A1, A0 and 13: outputs for the seven distance zones of sensor 1, nearest to farthest
- Pin 12: output for sensor 2
Program
Upload this sketch with the Arduino IDE. Open the Serial Monitor at 9600 baud if you want to see the distance readings from sensor 2 while testing.
unsigned int a=0,duration;
unsigned int b=0,duration1;
#define echoPin1 3 // Echo Pin1
#define trigPin1 4// Trigger Pin1
#define echoPin2 7 // Echo Pin2
#define trigPin2 8// Trigger Pin2
void setup()
{
Serial.begin (9600);
usinit();
}
void loop()
{
us2();
uscheck();
}
void usinit(void)
{
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
pinMode(A4, OUTPUT);
pinMode(A5, OUTPUT);
pinMode(12, OUTPUT);
pinMode(13, OUTPUT);
}
void uscheck(void)
{
digitalWrite(trigPin1, LOW);
digitalWrite(trigPin1, HIGH); //sends signal 10 us to excite ultra sonic sensor
delayMicroseconds(10);
digitalWrite(trigPin1, LOW);
duration = pulseIn(echoPin1, HIGH);//reads duration pulse in Microseconds
a = duration/58;
//Serial.println(a);//distance in CM
//delay(50); //Delay 50ms before next reading.
if ((10<a)&&(a<45))
{
digitalWrite(A5,LOW);
delay(500);
//Serial.println("first");
}
else if ((45<a)&&(a<80))
{
digitalWrite(A4,LOW);
// Serial.println("second");
delay(500);
}
else if ((80<a)&&(a<115))
{
digitalWrite(A3,LOW);
// Serial.println("3rd");
delay(500);
}
else if((115<a)&&(a<150))
{
digitalWrite(A2,LOW);
// Serial.println("4th");
delay(500);
}
else if ((150<a)&&(a<185))
{
digitalWrite(A1,LOW);
// Serial.println("5th");
delay(500);
}
else if ((185<a)&&(a<220))
{
digitalWrite(A0,LOW);
// Serial.println("6th");
delay(500);
}
else if ((220<a)&&(a<255))
{
digitalWrite(13,LOW);
//Serial.println("7th");
delay(500);
}
else
{
digitalWrite(13,HIGH);
digitalWrite(A0,HIGH);
digitalWrite(A1,HIGH);
digitalWrite(A2,HIGH);
digitalWrite(A3,HIGH);
digitalWrite(A4,HIGH);
digitalWrite(A5,HIGH);
}
}
void us2(void)
{
digitalWrite(trigPin2, LOW);
digitalWrite(trigPin2, HIGH); //sends signal 10 us to excite ultra sonic sensor
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
duration1 = pulseIn(echoPin2, HIGH);//reads duration pulse in Microseconds
b = duration1/58;
Serial.println(b);//distance in CM
// delay(50); //Delay 50ms before next reading.
if (b>190)
{
digitalWrite(12,LOW);
Serial.println("7th");
delay(500);
}
else
{
digitalWrite(12,HIGH);
}
}
How the code behaves
Distance zones
Sensor 1 readings below 10 cm are ignored. Between 10 cm and 255 cm the code activates one output per 35 cm band: A5 for 10 to 45 cm, A4 for 45 to 80 cm, A3 for 80 to 115 cm, A2 for 115 to 150 cm, A1 for 150 to 185 cm, A0 for 185 to 220 cm and pin 13 for 220 to 255 cm. Anything outside those ranges switches all of these outputs back to HIGH, which means off.
Known limitations
This is a simple sketch, and a few details are worth knowing before you build on it:
- The comparisons use strict less-than and greater-than signs, so a reading of exactly 45, 80, 115 and so on falls through to the final branch and switches everything off for that cycle.
- An output set LOW inside a zone stays LOW until a reading outside every zone arrives. If the voice module or indicator should follow the current distance only, switch the other outputs HIGH before activating a new one.
- The
delay(500)calls make the stick respond about twice a second. That is fine for slow walking but too slow for brisk movement. pulseInwaits for an echo with no custom timeout, so a missing echo can stall the loop for a moment. Adding a timeout as a third argument keeps it responsive.
Tips for building and testing
- Test each sensor on the bench with the Serial Monitor first and confirm the distances match a tape measure.
- Connect LEDs to the output pins and check that the right one lights in each zone before adding the voice module.
- Mount sensor 1 facing forward at a slight upward angle so it picks up obstacles above the cane’s reach as well as those straight ahead.
- Fix every wire and board firmly to the stick. A loose connection while walking is both annoying and unsafe.
- Test with a sighted helper nearby, ideally at slow speed, and ask the intended user what spoken messages and volume feel useful.
Ideas to improve the project
- Replace the long chain of
else ifbranches with a single calculation, such as dividing the distance by 35 to pick the zone. - Add a vibration motor so the stick can also warn silently in noisy places.
- Use a rechargeable battery and a power switch that is easy to find by touch.
- Protect the sensors and electronics from rain with a small enclosure that leaves the sensor faces uncovered.
FAQ
Can this talking stick replace a white cane?
No. It is a prototype that adds distance warnings. A white cane remains the main tool for detecting ground-level hazards, steps and surface changes, and this project should only supplement it.
What does the stick announce?
The program does not generate speech itself. It switches output pins according to distance, and those pins can trigger recorded messages on a voice playback module, light LEDs for testing, or drive a buzzer.
How far can the sensors detect obstacles?
The sketch sorts readings from 10 cm to 255 cm into seven zones. Actual range and accuracy depend on your sensor model, the surface of the obstacle and the angle it is hit at. Soft or angled surfaces can reflect sound poorly.
Do I need an Arduino Uno?
Not necessarily. Any Arduino-compatible board with enough digital and analog pins for two sensors and eight outputs will work, as long as you update the pin numbers in the code to match.