Project-HandBat
YourDuino PROJECT: HandBat
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 (right).
It is made from 5 parts:
- A YourDuino RoboRED Microcomputer (Or similar Arduinos)
- An Ultrasonic Sensor
- A small Beeper
- A Battery Holder for 4 AA batteries.
- "Rainbow" cable (Cablemaker) strips
How It Works:
The completed HandBat (above) contains the YourDuino 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.
Understanding the Science Behind the Ultrasonic Distance Sensor (click)
If you would like to understand more about how Ultrasonic Ranging works, click the link above.
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.
What HandBat is Made Of:
Mechanical:
On the right 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.
'E'lectrical:
Below 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)
Visual view of Connections:
Here (below) 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.
NOTE: Photos show an earlier version "Robo1" board. Check with the code below for correct connections.
Software:
The software (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 (far below) to see the details of how this is done, and you can modify this as you wish.
Construction Details:
On the right you can see all the parts of HandBat before the cover is screwed on. We will show you step-by-step how to construct it.
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 centermost 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 t wist 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.
- Now place the Arduino/YourDuino down over the remaining wires and carefully twist them to hold it in place. The assembly should look like this: (right):
Battery Connections:
The photo to the right shows the battery case, two RD-BK cables (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.
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.
Final Connections:
NOTE: The connections in the table are right, but the photos show an earlier "Robo1" version board.
See "Visual view of connections" and the schematic diagram above. Here's a list of connections:
COLOR |
FROM |
TO | |
1 |
BR |
Sensor Vcc |
Arduino +5 |
2 |
RD |
Sensor Trig |
Arduino 6 |
3 |
OR |
Sensor Echo |
Arduino 11 |
4 |
YL |
Sensor Gnd |
Arduino Gnd |
WH |
Beeper |
Arduino 9 | |
BK |
Beeper |
Arduino 10 | |
BK |
Battery - |
Arduino Gnd | |
RD |
Battery + |
Case Switch | |
RD |
Case Switch |
Arduino Vin |
Switch and Beeper Connections:
Two connections are made to the on-off switch that is part of the lantern case
- The RD wire from the battery case and
- the other RD wire made from one wire of the 'rainbow' cable
The photo 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.
USING HANDBAT:
After you load the software sketch (below) 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
Software Sketch: (Cut and Paste into Arduino IDE), upload to Arduino/YourDuino board
NOTE: You will need to download and install two libraries used in this sketch:
- Library From Tim Eckel for Ultrasonic Sensor - https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home/
- Library From Tim Eckel for non-conflicting tones - https://bitbucket.org/teckel12/arduino-toneac/wiki/Home
See: How to Install Libraries HERE:
/* 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 )***********
NOTE: Photos here show an earlier version of the Robo1 board. Check the correct connections in the code example.