31
Ears Kit PART NO. 2211709 You Will Need Soldering iron and solder Arduino UNO R3 DIP Edition 10 Conductor Gray Flat Ribbon Servo motor LASCO 1/2-in Dia PVC Sch 40 Cap Lowe’s 5/16 in. Zinc-Plated Steel Flat Washers Package Lowe’s #6 Nickel-Plated Steel Finishing Washers (10-Pack) Lowe’s GE Silicone II 2.8-oz. Kitchen and Bath Clear Caulk Lowe's

Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

Ears Kit PART NO. 2211709

You Will Need

Soldering iron and solder Arduino UNO R3 DIP Edition 10 Conductor Gray Flat Ribbon Servo motor LASCO 1/2-in Dia PVC Sch 40 Cap – Lowe’s 5/16 in. Zinc-Plated Steel Flat Washers Package – Lowe’s #6 Nickel-Plated Steel Finishing Washers (10-Pack) – Lowe’s GE Silicone II 2.8-oz. Kitchen and Bath Clear Caulk – Lowe's

Page 2: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

2

Kit Includes:

Part No. Qty. Description

33216 1 TL074CN DIP-14 Op-Amp

36185 10 1N4744A 15V 1W Zener Diode

93809 10 470uF16V Radial Capacitor

112432 10 Red Socket Shorting Block

151116 10 0.1 uF 25V Ceramic Disc Capacitor

208240 2 1000 uH Axial Choke

216240 1 Battery Holder

326596 1 TO-220 Heatsink

421489 1 Straight 3 Position Unshrouded Header

108338 1 2 Pin Header

320179 2 2 Pin Microphone Cartridge

198839 10 10uF 16V Radial Capacitor

241454 2 10K Potentiometer

332217 10 33 pF Capacitor

690742 10 330 Ohm Resistor

691104 10 10 Kohm Resistor

691147 10 15 Kohm Resistor

691243 10 39 Kohm Resistor

691622 10 1.5 Mohm Resistor

876125 10 TO-220 7805 IC

1581986 3 PCB Point

1947327 10 .0022 uF Capacitor

2094485 1 2 Position Header

2137756 1 Header

2186347 10 Green Diffused LED

--- 1 PCB

--- 1 Instructions

Page 3: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

Assembly And Test Of The Ears BoardGive Your Project Ears!

Ears is an Arduino shield that can give your project the ability to respond to sound. Maybe it's a robot or toy. Or maybe it's a security system that keeps cameras and lights facing the direction of sound, or just a light that shines on what you are reading when you call for it. It can also serve as a general purpose microphone-preamp system anywhere that might come in handy. Other ideas can be found in the technical document.

It consists of two electret microphones that connect to an easily assembled printed circuit board.

The board contains two microphone preamplifiers with gain adjustments, a connector for a servo and a regulator for the servo. Level is indicated by left and right LEDs which can be mounted on the board or extended to be used as decorations for a toy.

The Ears board can be plugged into an UNO which it can optionally power, or it can be operated independently when using other controllers.

Free test and operating sketches are provided. They determine sound levels and, more importantly, the direction of sound by means of a quadrature-like algorithm which simulates two comparators with trigger set points and two flip-flops.

Page 4: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

2

Assembly and testing follows. The 3.325” by 2.1” board looks like the following in approximate actual size, but a little bit larger line drawings are used in the assembly instructions as they are easier to see. It would be a very good idea to print this document so each step can be highlighted as it is finished:

For those for whom this is the first time to solder, here's a short course on soldering. Place the tip of the iron so it touches the pad and the component wire, then feed in a little solder. When the solder flows, pull the iron up the component wire to make a little cone:

Page 5: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

3

Assembly of the board will begin with installation of the lowest profile devices, starting with the resistors. Polarity is of no concern with resistors, but I prefer to have the colors read from left to right or top down.

Install the 330 ohm (Orange, Orange, Brown) resistors, R19 and R20, solder them in and cut the leads. As with most of the components, spread the wires out a little on the back to hold them in before soldering them to the board. Solder and cut them close to the board:

Page 6: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

4

Install the 10K (Brown, Black, Orange) resistors, R5, R6, R15, R16, R17 and R18, solder them in and cut the leads:

Next install the 15K (Brown, Green, Orange) resistors, R1, R2, R3 and R4, solder them in and cut the leads:

Page 7: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

5

Then the 39K (Orange, White, Orange) resistors, R7, R8, R11 and R12, solder them in and cut the leads:

And, finally, the 1.5 Meg (Brown, Green, Green) resistors, R9, R10, R13 and R14, solder them in and cut the leads:

Page 8: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

6

Now install the two chokes L1 and L2. There are no polarity concerns for them. Solder them in and cut the leads:

Page 9: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

7

Next is the TL074. Pins on ICs are often spread out and need to be rolled on the table to straighten them (after discharging static by touching ground):

Insert the IC, then slightly bend out two pins that are diagonal of each other to hold it in, then solder all of the pins. Pin 1 should be bottom left. There is no need to cut the pins. Take care not to bridge any of the pins with solder. If that happens, remove the bridge with a solder pump or you can sometimes just melt the bridge and tap the board on the table to knock off the solder:

Page 10: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

8The small capacitors will be installed next. Note that the numbering is often coded. A .1uF cap will often be labeled .1 or 104, and .0022uF might be labeled 2200 (and look like little beads). The .1uF caps are shown in orange below, the .0022uF caps are shown in blue and the 33pf caps are green. As with the resistors, insert them, spread the leads a little to hold them in, solder and cut the leads. You can also install the zener, Z1 while you're at it, which is shown next to the 7805 in violet or purple or something like that (this is a 70-year-old, primary-colors-only male talking). Make sure the stripe is down:

Now install the trimmers. The control surfaces should face the outside of the board:

Page 11: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

9Next, install the headers. Bend the end pins out a little to hold them in, then solder one of them. Be sure the headers are snug up against the board and straight before soldering the other pins. DO NOT CUT:

Now install the LEDs. The long wire goes to the + hole for an LED. Extension wires can be added to the LEDs so they can be used as decorations for a device such as a toy. If you do, use tape or heat shrink to insulate the connections to the LEDs. They will change brightness with the sound level:

Page 12: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

10

Install the 7805 5 volt regulator. The metal tab should face outside the board. Add a heatsink if it gets too warm in operation. You might need to bend its tab over if you plan to plug another shield into the Ears board:

Install the two-pin power jumper header, which allows powering an UNO or compatible unit off of the Ears board. It's a two-position header just below R6. Install the supplied jumper to power an UNO from Ears. Temporarily install the jumper to keep from burning your fingers by pushing it onto the header with the header on the table:

Page 13: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

11Install the three-conductor servo connector just above the 7805 regulator:

Next install the electrolytic capacitors, starting with C1 and C2, both 470uF electrolytic capacitors, both of which have + to the right. C4 and C5 are both 10uF capacitors. Again, be careful of the polarities. The + side of C4 goes to the right, and its negative to the left. The + side of C5 goes up and its negative down. Solder and cut the leads of all four:

Page 14: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

12Now install the power terminal block with the wire inlets toward the outside of the board:

And the test points go here:

And that's it. Hope your board looks something like this!

Page 15: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

13

Solder small, flexible, stranded wires to each of the mikes. A pair of wires pealed off of a ribbon cable works very well. A telephone extension wire also works, but it's a little stiff. The small, flexible wire from a lapel mike would probably be best since it's shielded. Carefully solder the wires to the two connections on the back of the mike. You might need to remove the pins first in order to keep the wires close to the mike if you use the modifications on the following pages:

Note which terminal is ground. It's the one that, if studied carefully, will be found to connect to the case. I tied a knot at the end of the ground wire at various points in the assembly to keep track. All you really need to do is connect the wires, although the following modifications will significantly help with noise reduction and directional characteristics. The modifications will add a small amount of additional weight though, so you might want to do without them if you are concerned about weight and a possible slight increase in power consumption, and don't need less noise and better directional characteristics.

Page 16: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

14

Cut off a small piece of tape, punch a little hole in it and run the wires through the hole to provide insulation.

Now get a piece of aluminum foil, punch a hole in it, then thread the wires through it and encase the capsule in the foil to provide some shielding (don't cover the front).

Next, drill a 1/8th inch hole in the back of a ½ inch PVC cap. Cover the inside bottom of the cap with some cotton from the drugstore, then thread the wires through the hole and then pull the capsule inside:

Page 17: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

15Now carefully stuff the space around the capsule with cotton. Use small pieces and arrange them so the cotton tends to center the capsule:

The cotton helps prevent sound from getting to the mike from other than the front, the only place we want it to be sensitive.

Now attach a 5/16th inch washer to the front with some cyanoacrylate adhesive (“Super Glue”):

Page 19: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

17

Whether the modifications above or used or not, the mike wires can now be soldered to the board after they have been routed as required by your application. Note that the mikes need to be next to each other for some of the testing:

Page 20: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

18

And the servo plugs in like this. Just make sure ground is plugged in where shown, and the others should be correct (but check the datasheet to make sure):

Page 21: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

19

The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect it to power to test before plugging it into an Arduino. Be careful about polarities, even though the 15 volt zener, Z1, helps protect the circuit. Blown traces can be fixed, but it's a hassle:

If you have a voltmeter, before plugging the board into an UNO, connect the meter's ground to GNDTP. With both level controls turned all the way down, you should see about 6 volts on TP1 and TP2. You should see about 3 volts on A0 and A1. You should see about 5 volts on the middle pin of the servo connector.

If you have a scope you should see a clean signal on A0 and A1 when speaking into the mikes with the levels turned about half way up.

Temporarily install the PWR jumper without the UNO. You should see about 12 volts on Vin with the PWR jumper in place. Remove the jumper for now. It's handy to store it plugged into only one side of the header to keep track of it.

Page 22: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

20

To test the circuit, download the Arduino software, which you can get free here. Check it by loading, compiling and running Blink under Basics. Then test and calibrate the system using the EarsTest software you can download here. Copy it (Ctrl AC in Windows) and paste it into the Arduino interface (Ctrl AV in Windows). Then File/Save As... to EarsTest or what ever name you might like.

I've changed the colors on my Arduino interface to pretty much match TextPad, which I like. Put a .c or .cpp extension on the end of a file name to get these colors in TextPad. To get the green colors for comments in the Arduino IDE, change theme.txt (do a search in the Arduino sub directory) to this:

# TEXT - COMMENTSeditor.comment1.style = #008000,plaineditor.comment2.style = #008000,plain

and the blue keywords:

# TEXT - KEYWORDS

# e.g abstract, final, privateeditor.keyword1.style = #0000ff,plain

# e.g. beginShape, point, lineeditor.keyword2.style = #0000ff,plain

# e.g. byte, char, short, coloreditor.keyword3.style = #0000ff,bold

Play with other values to get the colors you like.

Page 23: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

21

You should see the following at the top of the EarsTest program file. Note that I didn't design the very well done servo class:

// EarsTest

// I didn't have to design the servo class, thank goodness// Original Servo code by BARRAGAN <http://barraganstudio.com>// This example code for the servo is in the public domain.#include <Servo.h>

Servo HeadTurnServo;

int LeftLED = 7, RightLED = 8;long StartTime;

void setup(){ Serial.begin(9600); // set up serial remove comment to test HeadTurnServo.attach(9); // attaches the servo on pin 9 to the servo object HeadTurnServo.write(90); // start at 90 degrees - straight ahead pinMode(LeftLED, OUTPUT); pinMode(RightLED, OUTPUT); randomSeed(analogRead(0)); // seed random for random servo and movement routines StartTime = millis();}

Testing instructions are in the comments just below setup() in the program. They are also outlined below. It's simply a matter of enabling some routine calls in loop(). One thing that might prove handy to have is a C# program called USBLogger that you received with your order. It will allow you to log Serial information from the UNO (along with other controllers that send ASCII data over USB) so you can view it to see what effect your changes might have.

If you want to change USBLogger, just download Visual Studio Express 2012 for Windows Desktop free from Microsoft here . Then unzip USBLogger.zip into

My Documents\Visual Studio 2012\Projects

Get into bin\Release if you like and send a shortcut to the desktop for the USBLogger application.Then unzip USBLogger.zip into My Documents\Visual Studio 2012\Projects

Get into bin\Release if you like and send a shortcut to the desktop for the USBLoggerapplication.

Please see Kit Instructions available in the kit for USBLogger software.

Page 24: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

22

You can change the port, the baud rate (which should match the Arduino interface), the number of lines you want to log, the log file and the orientation of the microphones or silence which is used as a title at the top of the log file page, or a Special Title which overrides the name from the list box. You can enter more than enough lines and the program will terminate if it finds ">>> END <<<", so just put Serial.println(">>> END <<<") at the end of your process. When it's through storing the number of lines you entered or finds >>> END <<<, it will call up the log so you can evaluate the data. USBLogger will close if the check box is checked. It's advisable to keep it checked, since leaving it live can interfere with uploading sketches. If it sees >>> ERROR <<< it will try to send start data again. See the ShowArrays routine in EarsTest for an example. USBLogger should work with any project you have that sends ASCII serial data over USB using Serial.print() or similar routines. The technical document also shows how to generate and view data in a spreadsheet format.

The following is a screen shot of the latest version of the little program:

Page 25: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

23

The part of EarsTest around loop() looks like this:

const long LeftPeakToPeakAverageTrim = 4, RightPeakToPeakAverageTrim = 4;const long TimeOut = 7000; // 7 second timeout for silenceconst long MapInput = 1000, MapOutput = 25, ConstrainLimit = 45, DirectionTrendMax = 30000;const long LoudSound = ConstrainLimit / 2;

void loop(){ShowPeakAverages();//ShowFirstCountsAndPeakAverages();//CheckServo();//CheckRandomServo(); // random positions, 0 to 180 degrees//FirstCountsAndPeakControl();//LoadAmplitudeAndTimeData(true);

//ShowMaxMin(); // not used in testing, but might be useful//ShowArrays(true); // this is experimental - true = Using USBLogger//ShowArrays(false); // this is experimental - false = Not Using USBLogger//ShowArrays2(true);//Echo(); // also experimental//FlashLEDs(); // experimental

} // end void loop()

All you you do is unremark a routine in loop() with all others remarked, compile, run and monitor the results to set things up. ShowArrays(), ShowArrays2(), Echo() and FlashLEDs() are still experimental, but play with them if you like. The first two work with byte arrays that have their bits set when peaks are found. There are possibilities of frequency determination, command interpretation and PWM sound production with them.

Page 26: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

24

Start with the mikes next to each other with both level controls turned all the way down.

Unremark ShowPeakAverages() while leaving the others remarked out, and compile.Watch the results by clicking Tools/Serial Monitor or by running USBLogger.

I started with these settings and got the following results (including USBLogger time stamps):

const long LeftPeakToPeakAverageTrim = 4, RightPeakToPeakAverageTrim = 4;

19:37:50.364 LeftPeakToPeakAverage = 3 RightPeakToPeakAverage = 919:37:50.441 LeftPeakToPeakAverage - RightPeakToPeakAverage = -6 AverageOfAverage = 6

19:37:50.691 LeftPeakToPeakAverage = 2 RightPeakToPeakAverage = 919:37:50.769 LeftPeakToPeakAverage - RightPeakToPeakAverage = -7 AverageOfAverage = 5

LeftPeakToPeakAverageTrim and RightPeakToPeakAverageTrim are used to trim to zero LeftPeakToPeakAverage and RightPeakToPeakAverage by subtracting their values entered from LeftPeakToPeakAverage and RightPeakToPeakAverage.The above worked out pretty well, but I tried this

const long LeftPeakToPeakAverageTrim = 7, RightPeakToPeakAverageTrim = 13;

and got this which looks pretty good:

19:48:54.493 LeftPeakToPeakAverage = 1 RightPeakToPeakAverage = -119:48:54.571 LeftPeakToPeakAverage - RightPeakToPeakAverage = 2 AverageOfAverage = 0

19:48:54.824 LeftPeakToPeakAverage = 1 RightPeakToPeakAverage = 219:48:54.902 LeftPeakToPeakAverage - RightPeakToPeakAverage = -1 AverageOfAverage = 1

The above worked out pretty well, so I kept the settings. Look for single digit averages, whether positive or negative. Increase trim values if the left and/or right averages seem too large, or decrease them if they go too negative.

Page 27: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

25

The most important variables are probably LeftFirstCount and RightFirstCount. They are the result of an algorithm in LoadAmplitudeAndTimeData() which determines from which side a sound is coming. See the routine for a description of the algorithm. If the difference of left and right, FirstCountDif, is positive, the sound is assumed to be from the left. If it's negative the sound is considered to be from the right.

With silence, there is 0 movment indicated because FirstCountDif is zero, as can be see by remarking ShowPeakAverages(), unremarking ShowFirstCountsAndPeakAverages(), compiling and running in a quiet room. Only two of fifty samples (250 lines) are copied below from the USBLogger log file:

19:59:30.25 LeftPeakToPeakAverage = 40 RightPeakToPeakAverage = 42 AverageOfAverage = 4119:59:30.87 LeftFirstCount = 0 RightFirstCount = 0 FirstCountDif = 019:59:30.128 AverageOfAverage *= FirstCountDif = 019:59:30.210 map(AverageOfAverage, -1 * MapInput, MapInput, -1 * MapOutput, MapOutput) = 019:59:30.283 constrain(AverageOfAverage, -1 * ConstrainLimit, ConstrainLimit) = 0

19:59:30.562 LeftPeakToPeakAverage = 41 RightPeakToPeakAverage = 29 AverageOfAverage = 3519:59:30.623 LeftFirstCount = 0 RightFirstCount = 0 FirstCountDif = 019:59:30.664 AverageOfAverage *= FirstCountDif = 019:59:30.745 map(AverageOfAverage, -1 * MapInput, MapInput, -1 * MapOutput, MapOutput) = 019:59:30.816 constrain(AverageOfAverage, -1 * ConstrainLimit, ConstrainLimit) = 0

Now remark ShowFirstCountsAndPeakAverages() and unremark LoadAmplitudeAndTimeData(), compile, then get some sound going that seems to be at a reasonable level. Adjust the LEDs so each just begins to light with both of the mikes pointing toward the sound source.

Page 28: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

26

Now remark LoadAmplitudeAndTimeData() again, unremark ShowFirstCountsAndPeakAverages(), then compile.Notice that numbers go positive with sound from the left (me humming):

20:5:0.849 LeftPeakToPeakAverage = 600 RightPeakToPeakAverage = 542 AverageOfAverage = 57120:5:0.910 LeftFirstCount = 57 RightFirstCount = 0 FirstCountDif = 5720:5:0.955 AverageOfAverage *= FirstCountDif = 3254720:5:1.41 map(AverageOfAverage, -1 * MapInput, MapInput, -1 * MapOutput, MapOutput) = 81320:5:1.115 constrain(AverageOfAverage, -1 * ConstrainLimit, ConstrainLimit) = 45

20:5:1.399 LeftPeakToPeakAverage = 629 RightPeakToPeakAverage = 508 AverageOfAverage = 56820:5:1.459 LeftFirstCount = 51 RightFirstCount = 0 FirstCountDif = 5120:5:1.504 AverageOfAverage *= FirstCountDif = 2896820:5:1.586 map(AverageOfAverage, -1 * MapInput, MapInput, -1 * MapOutput, MapOutput) = 72420:5:1.660 constrain(AverageOfAverage, -1 * ConstrainLimit, ConstrainLimit) = 45

And numbers go negative with sound from the right (TV):

20:8:6.34 LeftPeakToPeakAverage = 544 RightPeakToPeakAverage = 554 AverageOfAverage = 54920:8:6.95 LeftFirstCount = 1 RightFirstCount = 23 FirstCountDif = -2220:8:6.140 AverageOfAverage *= FirstCountDif = -1207820:8:6.226 map(AverageOfAverage, -1 * MapInput, MapInput, -1 * MapOutput, MapOutput) = -30120:8:6.300 constrain(AverageOfAverage, -1 * ConstrainLimit, ConstrainLimit) = -45

20:8:6.585 LeftPeakToPeakAverage = 209 RightPeakToPeakAverage = 235 AverageOfAverage = 22220:8:6.645 LeftFirstCount = 0 RightFirstCount = 0 FirstCountDif = 020:8:6.686 AverageOfAverage *= FirstCountDif = 020:8:6.768 map(AverageOfAverage, -1 * MapInput, MapInput, -1 * MapOutput, MapOutput) = 020:8:6.842 constrain(AverageOfAverage, -1 * ConstrainLimit, ConstrainLimit) = 0

Page 29: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

27

Now remark ShowFirstCountsAndPeakAverages, unremark CheckServo,compile and run. This will run the servo 0 to 180 degrees,then back to 0 with a 10ms delay between each degree step.

CheckRandomServo() moves the servo randomly. The servo and 5 volt regulator can get pretty warm using this routine, so it would be a good idea not to let them run too long.

Unremark FirstCountsAndPeakControl() and compile. You should see the servo move toward a sound when the mikes are facing away from each other with a barrier between them, such as a wash cloth folded over the wires. It works much better with the mike modifications described above. Make slow, careful adjustments to the level controls to cause the servo to move as little as possible when the mikes are perpendicular to the sound source.

Silence for TimeOut milliseconds (7000 in this case = 7 seconds) should cause the servo to return to 90 degrees. Change the value of TimeOut if you like. It can be up to 2147483647, which will give you almost 25 days.

FirstCountsAndPeakControl() also randomly calls some routines, none of which are currently active except for ShakeHead(). They are all designed with a toy in mind. Currently, they are:

ShakeHead(); // only thing running nowBark(); // add sound and possibly servoScratch(); // add a foot and/or leg servoPant(); // add sound and possibly servoWagTail(); // add a tail servoWhimper(); // add sound and possibly servoPawGround(); // add a leg servo

The additional servos can be powered from the 5 volt regulator, although care should be taken not to overheat it. Use a heatsink if needed.

Page 30: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

28FirstCountsAndPeakControl() randomly calls the above routines if it moves the servo. Something like the following is what you might see using USBLogger or the built-int serial interface:20:15:2.792 LeftPeakToPeakAverage = 86 RightPeakToPeakAverage = 63 AverageOfAverage = 7420:15:2.853 LeftFirstCount = 0 RightFirstCount = 0 FirstCountDif = 020:15:2.894 AverageOfAverage *= FirstCountDif = 020:15:2.976 map(AverageOfAverage, -1 * MapInput, MapInput, -1 * MapOutput, MapOutput) = 020:15:3.49 constrain(AverageOfAverage, -1 * ConstrainLimit, ConstrainLimit) = 020:15:3.70 RunningAverage = 020:15:3.99 HeadTurnServo.read() = 9020:15:3.127 Elapsed Time seconds = 4

20:15:3.405 LeftPeakToPeakAverage = 807 RightPeakToPeakAverage = 704 AverageOfAverage = 75520:15:3.468 LeftFirstCount = 27 RightFirstCount = 0 FirstCountDif = 2720:15:3.512 AverageOfAverage *= FirstCountDif = 2038520:15:3.599 map(AverageOfAverage, -1 * MapInput, MapInput, -1 * MapOutput, MapOutput) = 50920:15:3.671 constrain(AverageOfAverage, -1 * ConstrainLimit, ConstrainLimit) = 4520:15:3.696 RunningAverage = 2220:15:3.894 ShakeHead20:15:5.199 Bark20:15:5.211 PawGround20:15:5.224 FlashLEDs20:15:5.252 HeadTurnServo.read() = 11220:15:5.281 Elapsed Time seconds = 6

But if there is no movement:20:18:19.885 LeftPeakToPeakAverage = 57 RightPeakToPeakAverage = 48 AverageOfAverage = 5220:18:19.946 LeftFirstCount = 0 RightFirstCount = 0 FirstCountDif = 020:18:19.987 AverageOfAverage *= FirstCountDif = 020:18:20.69 map(AverageOfAverage, -1 * MapInput, MapInput, -1 * MapOutput, MapOutput) = 020:18:20.142 constrain(AverageOfAverage, -1 * ConstrainLimit, ConstrainLimit) = 020:18:20.163 RunningAverage = 020:18:20.191 HeadTurnServo.read() = 18020:18:20.220 Elapsed Time seconds = 0

20:18:20.499 LeftPeakToPeakAverage = 60 RightPeakToPeakAverage = 55 AverageOfAverage = 5720:18:20.556 LeftFirstCount = 0 RightFirstCount = 0 FirstCountDif = 020:18:20.597 AverageOfAverage *= FirstCountDif = 020:18:20.683 map(AverageOfAverage, -1 * MapInput, MapInput, -1 * MapOutput, MapOutput) = 020:18:20.753 constrain(AverageOfAverage, -1 * ConstrainLimit, ConstrainLimit) = 020:18:20.777 RunningAverage = 020:18:20.806 HeadTurnServo.read() = 18020:18:20.830 Elapsed Time seconds = 1

Page 31: Ears Kit PART NO. 2211709 - Jameco Electronics · The following shows how to connect power. DC is required and 12 volts is suggested, either using batteries or a wall wart. Connect

29 then, after 7 seconds,

20:18:26.7 LeftPeakToPeakAverage = 54 RightPeakToPeakAverage = 47 AverageOfAverage = 5020:18:26.65 LeftFirstCount = 0 RightFirstCount = 0 FirstCountDif = 020:18:26.106 AverageOfAverage *= FirstCountDif = 020:18:26.192 map(AverageOfAverage, -1 * MapInput, MapInput, -1 * MapOutput, MapOutput) = 020:18:26.261 constrain(AverageOfAverage, -1 * ConstrainLimit, ConstrainLimit) = 020:18:26.282 RunningAverage = 020:18:26.311 HeadTurnServo.read() = 18020:18:26.339 Elapsed Time seconds = 6

20:18:26.618 LeftPeakToPeakAverage = 186 RightPeakToPeakAverage = 48 AverageOfAverage = 11720:18:26.679 LeftFirstCount = 0 RightFirstCount = 0 FirstCountDif = 020:18:26.720 AverageOfAverage *= FirstCountDif = 020:18:26.802 map(AverageOfAverage, -1 * MapInput, MapInput, -1 * MapOutput, MapOutput) = 020:18:26.876 constrain(AverageOfAverage, -1 * ConstrainLimit, ConstrainLimit) = 020:18:26.896 RunningAverage = 020:18:26.970 Elapsed Time seconds with silence = 7, so moving back to 90 degrees

FirstCountsAndPeakControl() without the printing is what is used in Ears,the operational program.

All you need to do after testing is to copy the values you determinedfor LeftPeakToPeakAverageTrim and RightPeakToPeakAverageTrim into the operational program (Ears). You might also want to play with the map, constrain and timeout parameters (MapInput, MapOutput, ConstrainLimit, TimeOut) along with the simulated comparator trigger values.

Download Ears here . The challenge now, if you want to make a toy, is to make it bark (meow?), wag its tail, pant, scratch, etc. Head shaking already works, and I have some ideas on PWM barking. Maybe someone would like a robot to follow when they call or a light to shine where they want it when they make a sound, or incorporate command recognition. You can find technical information and more ideas here . Any more?

Let me know,Joe [email protected]