4.3 Dog Assembly

Figure 8. Wiring diagram for the Electric Guard Dog
Take a look at the schematic in Figure 8, Wiring diagram for the Electric Guard Dog. The graphic shows wiring plugging into the wave shield. The wave shield is stacked on top of the Arduino board. Note that the wave shield uses several of the pins for its own use to interact with the Arduino, which is why not all passthrough pins are available for the sketch. Closely follow the wiring diagram and you should not have a problem.
Attach the positive lead of the PIR to the 3.3v pin on the wave shield. Connect the negative lead to one of the wave shield’s available ground pins. Then attach the control wire (the middle pin/wire on the PIR) to the wave shield’s digital pin 12.
Next, attach the servo’s positive wire to the wave shield’s 5v pin. Connect the negative lead to the wave shield’s other available ground pin. Finally, connect the control wire to the wave shield’s digital pin 11.
For brief testing purposes, you can attach male pins to the wires and plug them directly into the sockets on the wave shield. More reliable connections can be achieved by using either male or female header pins instead. These can be obtained directly from various Arduino board suppliers. If you plan on using the wave shield exclusively for this project, you can solder the wiring permanently to the shield for the most stable electrical connection possible.
There is one more step we should take before writing the sketch. We need to either record and digitize a dog growling and barking in various ways or legally download audio samples from the Internet of snarling, barking dog sounds.
The first option takes more time and requires access to a big dog that can bark, snarl, and growl on command—with a microphone near its toothy yapper, no less! While this requires a bit more extra work, the results produce a more consistent and realistic effect. And because you know the source, playback generates a more meaningful audio cue.

A PIR detects motion by comparing two samples of infrared radiation being emitted by a body warmer than the background environment it is moving against. When either side of the sensor detects a greater value than the other, it sends a signal to the digital out pin that motion has been detected. The IR sensor at the heart of a PIR is typically covered by a dome-shaped lens that helps to condense and focus light so that it is much easier for the sensor to detect infrared variations, and thus, motion.
For a more detailed explanation of the theory behind PIRs, visit Ladyada’s informative web page on the subject.[34]
The second option of searching on the Internet for a variety of angry dog audio samples is more convenient but rarely produces a consistent and believable overall effect. This is especially true when the samples are acquired from a variety of dog breeds. How can a dog have the toothy snarl of a Doberman one minute and the yapping of a miniature poodle the next? Also, downloading audio samples from the Internet has copyright implications that have to be respected. One website that I recommend visiting is the Freesound Project,[35] which features a number of samples available under the Creative Commons Sampling Plus license.
After you have obtained five audio clips using either approach, you need to convert them to a format the wave shield can interpret. Based on the conversion instructions on Ladyada’s website,[36] samples must not exceed a 22KHz 16-bit mono PCM (WAV) format. You want the highest audio quality possible, and there should be plenty of space on the SD card to store them. The audio clips you select for the project should not exceed five seconds in duration so they appear more synchronized with the servo motion when the audio is played back.
You can use an audio editor like Audacity to import
and convert and save your audio clips to the correct format.[37] Make sure they
are compatible by copying the converted files to the wave shield’s
SD card and running the dap_hc.pde
sketch posted on Ladyada’s website.[38] Note that we’re going to make
one change to Ladyada’s wave shield demo sketch. Instead of the
newer wavehc
library it uses, we
are going to use the older AF_Wave
library. That way, we can use Arduino community forum member
avandalen’s MediaPlayer library[39]—it makes working with wave
shield sound files far easier. We will take a closer look at this
library and another Arduino community contributor’s library for
servos when we write the sketch in the next section.