Sie sind auf Seite 1von 9

nrqm: Clap Sensor Construction

Projec ts > Clap S ensor > Construc tion

Building the Clap Sensor


Circuit Diagram
The clap s ens or is a s imple circuit that incorporates a PC microphone, a microcontroller, and an output. The following diagram s hows the logical circuit des ign:

I chos e the ATtiny84 microcontroller for this project becaus e I'm familiar with the AVR architecture and I have acces s to the tools to us e it. I bought the ATtiny84 in its SOIC-14 packaging. If I had it to do again then I'd choos e the ATtiny85, which comes in a SOIC-8 package; it contains all the features I needed but takes up les s s pace. It's not a real problem though. The microphone connects to the circuit through a tip-ring-s leeve (TRS) jack. I chos e the SJ1-3533N jack from CUI Inc. becaus e it looks nice and has a s mall footprint on the circuit board. It breaks out the tip, ring and s leeve conductors on three pins on the bottom. The s leeve conductor is connected to ground, and the ring is connected to V+ through a 2.2 k res is tor (without this res is tor the microphone's output s ignal is cons tant). The tip conductor carries the microphone's output s ignal. The circuit's 10 F capacitor filters the power input. The LED is for vis ual output. The LED's current-limiting res is tor value, in the diagram labeled 1.5 k, depends on the LED. I us ed a low-current LED, s o the res is tance is quite high. The res is tor value for other LEDs can be calculated with this tool, with the s ource voltage value s et to the input voltage (5 V in my circuit) and the diode voltage and current taken from the LED's datas heet. I us ed a 100 res is tor to protect the output. The res is tor s hould probably be higher, but I figure it's fine.

Programming Interface
The s ix-pin connector next to the ATtiny84 in the circuit diagram is for the in-s ys tem programmer (ISP), which is how code is loaded onto the ATtiny84. I us ed Atmel's AVRISP mkII to load code. The following diagram s hows the ISP pinout on the header:

The ISP interface corres ponds to a s erial peripheral interface (SPI) connection; the only difference is that the microcontroller can be put into programming mode while the RESET pin is held low. This is all handled automatically by the AVRISP driver. The Vcc and GND pins have to be connected to external power. Als o, the RESET pin mus t be connected to Vcc through a 10 k pullup res is tor as s hown in the circuit diagram above, to keep RESET high when the proces s or is running. The header's pins are connected to pins on the microcontroller. The microcontroller pins are labeled with their SPI (and RESET) des ignations in the microcontroller's data s heet. For the ATtiny84, the datas heet [PDF] gives the pin des ignations on page 2: Name Vcc GND MISO MOSI SCK RESET SOIC-14 Pin Number 1 14 8 7 9 4 AVR Pin Name Vcc GND PA5 PA6 PA4 PB3

The AVRISP connects with the red s tripe on its ribbon cable at the header's pin 1.

Circuit Board Design


I des igned the circuit board us ing a program called Expres s PCB. It's not the mos t complete des ign program and it us es a proprietary file format that does n't work with other s oftware, but it's very eas y to us e and is well-documented. I des igned the two-layer circuit board below; the red traces are the top copper layer, the green traces are the bottom copper layer, and the yellow is for s ilks creened information (I don't print the s ilks creen layer, but it's s hown below for informational purpos es ).

The large holes fit s tandard 0.1" headers ; they have a 1.91 mm outer diameter and 1.02 mm inner diameter. The s mall holes fit component leads ; they have a 1.42 mm outer diameter and a 0.74 mm inner diameter. The s mall holes on the CPU are jus t through-holes that connect the bottom layer copper to the top. The three res is tor s pots in the bottom-left corner of the board are s ized for 1/4 W res is tors . The three 0.1" pins in the upper-left corner are, from top to bottom, for V+, GND, and the output. The ISP header is oriented with pin 1 at the top-left. This des ign does n't include the ISP port's pullup res is tor. I couldn't figure out how to fit it onto the board. If I was going to make another vers ion of the board I would put a s urface-mount res is tor between the Vcc and RESET pins to the right of the ISP port. I ended up us ing a 1/4 W res is tor s oldered above the board, between the Vcc trace and the through-hole connected to the RESET pin.

Etching the Circuit Board


I us ed ins tructions written by Chris topher Garber to print the two copper layer des igns onto toner trans fer paper. I diverged from the ins tructions by printing to a 1200 dpi PDF file ins tead of 300 dpi; 1200 dpi gave me much better res ults for the final printing. I als o s kipped the colour-related s teps and jus t printed everything to black, and combined the top and bottom layer images into one image for printing. I als o eras ed unconnected pads from the final printable image in Photos hop. Each through-hole has a pad on the top layer and a pad on the bottom layer, but mos t of them only connect to things on one layer. For example, the three left-mos t ISP header through-holes connect to traces on the bottom layer, but are unconnected on the top layer. I eras ed the top layer pads becaus e they're us eles s . In the lower part of the board the bottom-layer ground trace barely fits through two through-

hole pads . By eras ing the us eles s bottom layer through-hole pads , the ris k of s horting the ground trace to the leads that fit through the holes is greatly reduced. I didn't eras e the bottom-left pad for the TRS jack, but I s hould have. (Des ign tip: I als o caught a bug by eras ing ves tigial pads . When I eras ed the LED cathode pads on both the top and bottom layers , I dis covered that I'd forgotten to connect the top layer pad to the ground trace.) Finally I had the circuit ready to print to the toner trans fer paper:

Note that the top layer is revers ed to compens ate for the toner trans fer proces s . I bought materials for etching from a Chines e s hop on eBay, but there are various other s ources for the required products . I bought toner trans fer paper, copperclad PCBs , and copper etchant from Digole Digital Solution's eBay s tore. I mos tly followed their ins tructions , with s upplemental information on cleaning, ironing and etching from Chris topher Garber's page. Mr. Garber us es high-glos s photo paper ins tead of toner trans fer paper, but it s eems way eas ier to us e toner trans fer paper s ince it trans fers only the toner and does n't leave any res idue that needs to be s crubbed off. Here is the copper-clad PCB after being cleaned and printed to:

I als o wrote the N and a line in black Sharpie ink to tes t how well the ink worked as an etch res is t. I bought a double-s ided PCB, but I ended up printing both of the circuit board's layers to the s ame s ide becaus e it s eemed like too much has s le to line up the holes on the layers . I glued the layers together later. But before that I etched the copper in the etchant I bought from Digole:

The Sharpie ink I drew on the PCB ended up getting was hed off by the etchant. Fortunately after it s tarted to run it got was hed all the way off and didn't caus e s treaks in the copper. I think if I had laid the PCB down ins tead of holding it up vertically then the ink would have s tayed put. I was trying to s ave on etchant, but I ended up having to us e extra anyway becaus e it had to etch off both layers . After I was done I mixed in baking s oda to precipitate out the copper ions , diluted the s olution cons iderably, and dumped it down the s ink. I think in the future I would us e a s olution of hydrochloric acid and hydrogen peroxide as an etchant, as recommended in various web s ites , s ince it is eas ier to obtain and more environmentally friendly than whatever Digole was s elling (I think I bought either s odium pers ulphate or ammonium pers ulphate, they don't s pecify which).

I was hed the toner off with acetone and cut the circuit board out with a hacks aw. Then I drilled out the through holes with a drill pres s , us ing a #60 (1.01 mm) bit for the large holes and a #69 (0.74 mm) bit for the s mall holes . Not all of the throughholes were drilled out on both s ides , becaus e I had eras ed s ome of the through-hole pads from the printout and s o they didn't appear in the circuit board. The V+ pin and the CPU through-holes have pads on both s ides , s o thos e through-holes got drilled out all the way through. I glued the two pieces back-to-back, making s ure they were properly aligned by pus hing drill bits through two of the complete through-holes .

After letting the glue cure overnight I trimmed down the PCB's edges us ing a rotary tool, and finis hed drilling all of the through-holes , leaving the final circuit board. The mic jack's pins are very wide and narrow, s o I carved them out with the s mall drill bit.

I ins talled the minimum number of components I needed to load code onto the microcontroller: the power input, filter capacitor, ISP header, pullup res is tor, CPU, LED, and LED res is tor. With this circuit I was able to read the CPU's s erial number us ing the AVRISP mkII, and finally to load a s imple LED-blinking program.

Soldering on the ISP header was very difficult becaus e of the top layer pads : when the header was ins talled on the board, the pads were under the header and it was impos s ible to s older them to the pins . I s olved this for the ISP header by putting a few metal s trands from s tranded-core wire into the holes . The s trands wicked s older from the bottom of the board up to the pads . The s trands are not eas y to ins tall and create a ris k of s hort circuits . I s olved this problem for the power, ground, and s ignal pins by removing the plas tic bas e from the header row and s oldering the pins into the holes one at a time. Later when I ins talled the TRS jack I came up with a better way to do it: drill through-holes next to the top layer pads , s tick a bit of metal (e.g. a clipping from a component lead) through the hole, and s older the top layer pad to the metal. I s oldered the TRS jack connectors to the bits of metal s ticking out of the bottom layer, thereby connecting them to the top layer pads via the through-holes .

Finally I ins talled the remaining components and trimmed the pullup res is tor. After I took the above photo I cleaned off the board and dipped it in polyurethane to protect the traces (this had the s ide-effect of making the board nice and s hiney).

Das könnte Ihnen auch gefallen