1 HC-SR04 (ultrasonic sensor) for a guidance system :smiley-roll-sweat:

Hi to all!

I have a project that uses an ultrasonic sensor(HC-SR04) as its input and an Arduino UNO board. Datasheet: https://elecfreaks.com/estore/download/EF03085-HC-SR04_Ultrasonic_Module_User_Guide.pdf
This project is a walking stick/cane for the blind/visually impaired.

My question is, if a SINGLE STATIONARY ultrasonic sensor is enough to be able to detect obstacles ,approximately 1 meter away,
along its path for the user to be able to turn left or right in time and avoid the object? The location of the sensor is right about shin level.

Any tips on maximizing ultrasonic sensors HC-SR04 in particular..

Thank you so much for your responses!

-student on a budget

Hi ponsojj,

I have done something like this with the HC-SR04. Looks like this:

The project page is HERE: http://arduino-info.wikispaces.com/Project-HandBat

It's simple:

See the page for info on libraries etc.

Code looks like this:

/* YourDuino Project Example: BatHand
 - Hand-held SONAR Ranger for blind user / dark navigation
 - Does Ultrasonic Ranging, Outputs tones for distance
 - SEE the comments after "//" on each line below
 - PIN CONNECTIONS:
   - Ultrasonic HC-S04 Type Sensor:
     - Trigger pin 6
     - Echo    pin 11
   -  Piezo type Beeper:
    - 10  (For bipolar louder signal)
    - 9
   - Pin 13 LED (Built into Arduino/Yourduino board)
 - V1.04 03-29-14   Tone settings
   Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include <NewPing.h>     // Library From Tim Eckel for Ultrasonic Sensor
                         // https://code.google.com/p/arduino-new-ping/
#include <toneAC.h>      // Library From Tim Eckel for non-conflicting tones
                         // https://code.google.com/p/arduino-tone-ac/
/*-----( Declare Constants and Pin Numbers )-----*/
#define TRIGGER_PIN  6   // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
//NOTE: Beeper uses pins 9,10 (Set within toneAC library)
#define Pin13LED     13  // Built-in LED on Arduino/YourDuino board
#define MAX_DISTANCE 300 // Maximum distance we want to ping for (in centimeters).

/*-----( Declare objects )-----*/
NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

/*-----( Declare Variables )-----*/
unsigned int uS;      // Measured echo time in MicroSeconds
unsigned int DistCM;  // Measured distance in CM

void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(115200);  // Open serial monitor at 115200 baud to see ping results.
  BeepQuality(1800,250); // Welcome beep
}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  delay(50);                      // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
  uS     = sonar.ping(); // Send ping, get ping time in microseconds (uS).
  DistCM = uS / US_ROUNDTRIP_CM; // Calculate distance in CM
  Serial.print("Ping: ");
  Serial.print(DistCM); // print Distance in CM (0 = outside set distance range)
  Serial.println("cm");

//-----( Calculate Tone frequency and length depending on distance )--------  
  if ( (DistCM >    0) && (DistCM < 25 )  )     BeepQuality(2000,(DistCM * 10)); 
  if ( (DistCM >=  25) && (DistCM < 100)  )     BeepQuality(1800,(DistCM * 4 )); 
  if ( (DistCM >= 100) && (DistCM < 200)  )     BeepQuality(1700,(DistCM     ));   
  if ( (DistCM >= 200) || (DistCM  == 0)  )     BeepQuality(1900,(20         ));   // Chirp when out of range

}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/

void BeepQuality(int Freq, int Duration)
  {
  digitalWrite(Pin13LED, HIGH);  // Turn on lED
  toneAC(Freq);                  // Start the beep at the desired frequency
  delay(Duration);               // Listen to the beep for desired time
  toneAC();                      // Stop beep 
  if (Freq == 1900) delay(1000); // Distinguish Out Of Range
    digitalWrite(Pin13LED, LOW); // Stop lED
  }

//*********( THE END )***********

ponsojj:
My question is, if a SINGLE STATIONARY ultrasonic sensor is enough to be able to detect obstacles ,approximately 1 meter away,

Yes: the range is about 3 meters. Whenever there's an object in it's "view" (about 30° cone iirc) it'll react.

along its path for the user to be able to turn left or right in time and avoid the object? The location of the sensor is right about shin level.

You won't be able to tell if the object is right in front, a bit to the left, or a bit to the right. Just whether it's "in view".