- Arduino boards can accurately detect the approach of your hand from several inches away (no parts needed), they can also talk . Demonstration code for each ability and two working projects, Protection Device and TalkClock, are included in DPD.zip.
Take a moment and try the Proximity detection in step 1, you will be amazed.
Step 1: Proximity Detection
With software alone an Arduino can detect the touch of your hand, or even its approach from several inches away.
When the Arduino analog inputs pins are left unconnected they read in some range of values. If a finger is placed on or near the plastic header connected to the analog Inputs that range changes. It is possible to establish a base range and then detect the presence of a 'touch' near the analog Input pins when readings are outside this range.
Run the touchbar sketch and open the serial monitor, return on 9600. While touchbar is warming up and calibrating keep your hands away from the Arduino. After calibration is completed the calibration data, sensitivity setting, and trigger levels are shown. When you touch the plastic header near the analog pins the profile of the touch is displayed. The sensitivity can be adjusted by entering a-z, or detect level 1-9. Try r4 for high sensitivity and detection at a distance. With d2 you may need to pinch the header between your fingers to detect.
1122233 * means ...
Pins one and three have a level 2 signal, and pin two has a level 3 signal. The * indicates the detect level pin count is reached. Audio feedback (not required) is provided on pin PWM 5 ,PWM 4 on a Mega 2560.
Looking at the data you can see touch firmness, pin location, and duration . In combination a variety of gestures can be distinguished, even if the gestures are done without actually touching the Arduino ! If unintended movements are causing false detection, repeat them during calibration so they can be ignored.
Step 2: Speech Generation
It is possible to play an Audio Sample as an Analog Signal on a Digital Output Pin.
Playing 8 bit PCM Audio Samples. The Arduino 16 MHz clock drives a timer counter from 0-255 continuously, an output bit is set (5v) at 0 and cleared (0v) when the timers compare match value is reached. This produces continuous square waves at 62.5 kHz whose duty cycle varies between 0 and 100% in 256 steps set by the 8 bit value in the compare register. This is a pulse train with density control. By changing the compare value in a 15625hz interrupt the 62.5 kHz pulse train gives 4 pulses per datum. You can repeat a sample for continuous sound or play back sequences of samples. The correct sound samples in the correct order will 'talk'. 16 kHz or even 8 kHz 8 bit samples have enough quality to easily recognize different peoples voices.
Run the saynumber sketch. Open the serial monitor, return on 9600. Your Arduino will speak the number you enter.
Some words are spoken by sequences of sounds to save memory, for example 16 'six' 'teen' and 60 'six' 'Tee' and 40 'four' 'Tee' and 14 'four' 'teen' share parts. I used Audacity and exported as 'other uncompressed wav unsigned 8 bit pcm' no Metadata , then used a VBScript to strip the header and change any '0' datums placing a C source array of the sample on the clipboard ready to paste. I have included the script to make it easy to replace the provided samples.
How to connect Earbuds.
The simplest way hear the Arduino talk is to use an old pair of ear buds (BUT DO NOT PUT THEM IN YOUR EARS THEY CAN BE VERY LOUD). Do not use this method to connect to other devices besides Earbuds. In the picture you can see I put naked pins in the Arduino headers to give something to clip to. Connect the tip of the plug to pwm pin 4 on a Mega ( pin 5 on a 328 based Arduino). It could make sense to connect the Arduino ground to the ground of the Earbuds, but it makes more sense (and twice the resistance) to connect the Arduino ground to the center connection of the Earbuds plug. You can also cut off the plug, connect the two grounds together, then connect the other two wires to the Arduino ground and Arduino I/O pin. The ear bud wires are tiny and must be treated carefully when soldering.
The TalkClock picture shows how to connect a small set of powered speakers using a 1.5k resistor. There are several other methods to connect a speaker to an Arduino on Instructables and most will work for these examples .
Step 3: Donut Protection Device
The Arduino is calibrated for proximity detection while placed underneath the glass dish. A voice (or silent) alert based on passive proximity detection has applications from security and automatic lighting to digital "Whoopee Cushions".The DPD sketch reports any activity on the serial port and warns the intruder away when the detection level is reached if sound is connected. I used Audacity and exported as 'other uncompressed wav unsigned 8 bit pcm' no Metadata , then used a VBScript to strip the header and change any '0' datums placing a C source array of the sample on the clipboard ready to paste. I have included the script to make it easy to replace the sound samples.
Step 4: Talking Clock With Invisible Button
By knowing how many samples you have played (or could have played) you can keep track of elapsed time. TalkClock will 'Speak' the time . The 'Invisible Button' is used to set the time using voice prompts. Using short and long touches different functions are selected. The clock will speak the time each minute and tone every 30 seconds.
Run the TalkClock sketch and Open the serial monitor.
Wait for calibration to complete.
- Short Touch the plastic near the Analog Pins to hear the time.
- Keep touching longer to set the time. When you hear 'set time' stop touching, the current hour is spoken.
- Short Touch to change the hour. Long Touch and you will hear 'set' and the current minute is spoken.
- Short Touch to change the minute. Long Touch and you will hear 'set' . When you touch again the clock will restart.
With the 328 version the words 'Set' and 'Time' are not spoken, a tone is used instead.