Introduction: YourDuino: HandBat - Handheld Ultrasonic Radar Using Arduino

HandBat is a handheld Ultrasonic Radar device that sends out pulses of UltraSound and listens for Echos, like a Bat. It is intended for use by vision-impaired people or navigation in the dark.

Handbat is housed in a low-cost ($3.97) Rayovac Floating Lantern case from Walmart.

It is made from 5 parts:

  1. A YourDuino Robo1 Microcomputer (Or similar Arduinos)
  2. An Ultrasonic Sensor
  3. A small Beeper
  4. A Battery Holder for 4 AA batteries
  5. "Rainbow" cable (Cablemaker) strips

These parts are widely available on Ebay, Sparkfun.com, Adafruit.com, YourDuino.com etc.
A kit with the needed parts is available HERE:

Questions?? terry@yourduino.com

Step 1: How HandBat Works

The completed HandBat (above) contains the YourDuino/Arduino microcomputer and battery holder inside the lantern case, the UltraSonic Sensor mounted on the front lens, and the beeper on the outside of the case.

Here is a good Educational article we have written about Ultrasonics and EchoLocation: Understanding the Science Behind the Ultrasonic Distance Sensor (click this link)

In use, the HandBat is held by the user and pointed in front of them and around to find out how close objects are. The maximum range is 2 meters (about 6 feet). The user listens to the beeper which tells how close objects are with different tones and rates of beep.

  • 2 meters to 1 meter the tone is lower and the beep rate is slower and increases towards 1 meter.
  • At 1 meter the tone changes higher and slower, then faster towards 25 cm, when it changes to a high pitch
  • From 25 cm down to 2 cm the beeps get faster and faster and small distances can be sensed.

Note: A Kit of parts to build the Handbat (Not including the $4 Walmart Lantern!) is available HERE.

Step 2: What HandBat Is Made Of: Mechanical

Above are all the parts of the HandBat before being assembled into the case:

The YourDuino Robo1 and the battery case are wired to opposite sides of a 3 by 4 inch piece of strong cardboard or foamcore.

The Ultrasonic Sensor is glued to the front lens and the beeper is glued to the case and connected through two drilled holes.

Step 3: What HandBat Is Made Of: Electrical

Above is the schematic diagram of the HandBat.

The Ultrasonic Sensor is connected:

  • Vcc to +5V
  • Gnd to Gnd
  • Trig (Sends a ultrasound pulse) to YourDuino pin 6
  • Echo (Get the return pulse) to YourDuino pin 11
  • Beeper to Yourduino pins 9 and 10

The battery is connected through the switch on the original lantern and to YourDuino pins (5V) and (GND)

Step 4: Visual View of Connections:

Here (above) is how those connections are made, using strips from the Cablemaker cable.

We used a strip of 4 (Brown-Red-Orange-Yellow) often abbreviated to two letters: BR-RD-OR-YL which are colors 1-2-3-4 in the standard color code.

We used a two wire WH-BK strip for the beeper.

We used two wires (RD and BK) for power.

You may want to actually assemble the working system on the desktop to make sure it works before taking it apart again and building it into the Lantern case.

Step 5: Software:

The software (link below) does these actions:

  • Import NewPing library for Ultrasonic Sensor and ToneAC library for Beeper
  • Start NewPing and the Serial Monitor (optional: see distances)
  • Send ping, get echo time in microseconds (uS), calculate distance in cm.
  • Decide what tone frequency and repetition time to use, drive the beeper
  • If out of range, click the beeper once a second

You can read the Arduino Software Sketch to see the details of how this is done, and you can modify this as you wish.

Step 6: ​Construction Details:

Above you can see all the parts of HandBat before the cover is screwed on. Next, we will show you step-by-step how to construct it.

Step 7: ​Construction Details: Make a Base for the Arduino and the Battery Case

Make a base for the Arduino and the Battery Case:

  • Find a piece of heavy corrugated cardboard (we folded two layers) or FoamCore. Cut a piece 3 by 4 inches (7.6cm by 10cm) .
  • Center the Battery case on one side, with the wires facing 'forward' (towards the short edge). Mark through the 4 holes with a small pencil. Use a small nail or awl to punch hole through the cardboard at those points.
  • Center the Arduino/Yourduino on the other side of the cardboard with the USB connector facing the same edge as the battery case wires. With the USB connector to the left, mark through 2 holes: upper right and lower left. Punch those 2 holes.
  • Cut two pieces of thin (#20 or 22) wire approximately 8 inches (20cm) long.
  • Thread one wire it up though the center-most holes of the battery case marks. Thread the other wire the opposite direction through the cardboard where the Arduino holes are located. It should end up looking like the photo to the far right.
  • Now place the battery case down over its wires, through the center-most holes, with the battery case wires in their original position. Bend the wires over 180 degrees and push them down through the outer-most holes, Pull the wires tight and twist the ends of the wire tightly against the cardboard, cut off the remaining wire ends at about 1 inch (2cm) length, and flatten the wire out against the cardboard. That should look like the photo to the right, with the battery case on the opposite side.
  • Place the Arduino/YourDuino down over the remaining wires and carefully twist them to hold it in place. The assembly should look like the first photo above.

Step 8: Battery Connections:

The photo above shows the battery case, two RD-BK wires (one end cut and stripped) and a 2-pin male-male strip (This comes with the "Cablemaker" ribbon cable). You should twist the black leads together and tape them. The red leads will be connected to the switch in the lantern case.

Step 9: ​Mounting and Connecting the Ultrasonic Sensor:

There are couple of choices for mounting the sensor.

First, push hard and pop the clear lens out of the black ring on the plastic lantern case.The clear material is hard to drill without cracking it.

We drilled and then enlarged two holes with a round file until the sensor could be put in from the inside. We 'glued' it in place with "Adhesive Caulk", but you can use RTV sealant or Hot glue.

Another easier approach is to drill a single hole of about 1/4 Inch (6mm) or so in the clear lens, put the 4 wires through the hole, and glue the sensor on the outside of the lens. You might also use double-stick foam tape.

Step 10: Connection Table:

See "Visual view of connections" and the schematic diagram in the previous steps.

Above is a list of connections.

Step 11: ​Switch and Beeper Connections:

Two connections are made to the on-off switch that is part of the lantern case

  1. The RD wire from the battery case and
  2. the other RD wire made from one wire of the 'rainbow' cable

The photo above shows these wires soldered to the switch contacts. But you can also strip about 1 inch (2cm) from each wire, carefully wind the wire multiple times around the contact and tape it in place.

The Beeper has two pins that are 0.2 inches apart. Drill two holes that are big enough for the cable ends to go all the way through.

Attach the beeper and push the cable ends part way through the case.We 'glued' it in place with "Adhesive Caulk", but you can use RTV sealant or Hot glue.

Step 12: ​USING HANDBAT:

After you load the software sketch (see next step) with your USB cable, remove the cable and install the batteries. You can't tell which way the on-off switch is to start, but you will see a PWR LED light up on the Arduino/YourDuino when the battery power is connected to Gnd and Vin (Right next to each other: Be careful and get this right or damage could happen!).

After power is supplied the Arduino board will reset itself and make a short beep. Then you will hear beeps depending on the distance of objects in front of the Ultrasonic Sensor:

  • 2 meters to 1 meter : lower tone beeps, getting faster and faster until 1 M
  • 1 meter to 25 cm: Middle tone beeps, getting faster and faster until 25 cm
  • 25cm to about 2 cm: Higher tone beeps, getting faster and faster

NOTE: The most recent software sketch will put out a different sound (Short Clicks) when the ultrasonic sensor sees "Out Of Range" or "No Echo Received".

It will take some practice before you can navigate carefully in the dark. Also notice how different objects reflect differently. A solid flat wall will work great, but an overstuffed chair may not reflect until you are very close. Your cat or dog are also somewhat absorbent. Point the HandBat straight down at the floor to hear the sound of "about 1/2 meter distance".

Step 13: ​Software Sketch: (Copy and Paste Into Arduino IDE) [Updated 1AM 4/20/14]

You can get the Arduino Software Sketch for HandBat below.

IMPORTANT NOTE: You will need to download and install two libraries used in this sketch:

  1. Library From Tim Eckel for Ultrasonic Sensor - https://code.google.com/p/arduino-new-ping/
  2. Library From Tim Eckel for non-conflicting tones - https://code.google.com/p/arduino-tone-ac/

If you are not familiar with installing Arduino libraries, please see How to Install Libraries

Software Sketch: Copy and Paste into Arduino IDE

/* 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
                         //  <a href="https://code.google.com/p/arduino-new-ping/"> https://code.google.com/p/arduino-new-ping/ </a>
#include <toneAC.h>      // Library From Tim Eckel for non-conflicting tones
                         // <a href="https://code.google.com/p/arduino-tone-ac/"> https://code.google.com/p/arduino-new-ping/ </a>

/*-----( 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 )***********