4.3 Dog Assembly

/epubstore/R/M-Riley/Programming-your-home//images/electricguarddogwiring.png

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.

Joe asks:
Joe asks:
How Does a PIR Sensor Work?

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.

Programming Your Home
cover.xhtml
f_0000.html
f_0001.html
f_0002.html
f_0003.html
f_0004.html
f_0005.html
f_0006.html
f_0007.html
f_0008.html
f_0009.html
f_0010.html
f_0011.html
f_0012.html
f_0013.html
f_0014.html
f_0015.html
f_0016.html
f_0017.html
f_0018.html
f_0019.html
f_0020.html
f_0021.html
f_0022.html
f_0023.html
f_0024.html
f_0025.html
f_0026.html
f_0027.html
f_0028.html
f_0029.html
f_0030.html
f_0031.html
f_0032.html
f_0033.html
f_0034.html
f_0035.html
f_0036.html
f_0037.html
f_0038.html
f_0039.html
f_0040.html
f_0041.html
f_0042.html
f_0043.html
f_0044.html
f_0045.html
f_0046.html
f_0047.html
f_0048.html
f_0049.html
f_0050.html
f_0051.html
f_0052.html
f_0053.html
f_0054.html
f_0055.html
f_0056.html
f_0057.html
f_0058.html
f_0059.html
f_0060.html
f_0061.html
f_0062.html
f_0063.html
f_0064.html
f_0065.html
f_0066.html
f_0067.html
f_0068.html
f_0069.html
f_0070.html
f_0071.html
f_0072.html
f_0073.html
f_0074.html
f_0075.html
f_0076.html
f_0077.html
f_0078.html
f_0079.html
f_0080.html
f_0081.html
f_0082.html
f_0083.html
f_0084.html
f_0085.html
f_0086.html
f_0087.html
f_0088.html
f_0089.html
f_0090.html
f_0091.html
f_0092.html
f_0093.html
f_0094.html
f_0095.html
f_0096.html
f_0097.html
f_0098.html
f_0099.html
f_0100.html
f_0101.html
f_0102.html
f_0103.html
f_0104.html
f_0105.html
f_0106.html
f_0107.html
f_0108.html
f_0109.html
f_0110.html
f_0111.html
f_0112.html
f_0113.html
f_0114.html
f_0115.html
f_0116.html
f_0117.html
f_0118.html
f_0119.html
f_0120.html
f_0121.html
f_0122.html
f_0123.html
f_0124.html
f_0125.html