# My ATTiny84 circuit works fine until I connect a piezo buzzer

I've got a mini-game coded with an ATTiny84, a shifter, 7 LEDs and two buttons, plus accompanying resistors. It works great! Until I connect a passive piezo buzzer, that is. Then the timings go off, code gets "stuck", it's really strange.

The amazing thing is I don't even need to USE the buzzer -- just having it in the circuit kills the system. The moment I unplug it from ground everything works.

I'm powering the whole thing up with 3 AAAs as per recommendations elsewhere. No voltage regulators or capacitors... could that be the problem? Or is it an ATTiny84 thing? Anyone know what's going on?

(I had the buzzer working fine before when I was using an ATMega128 and the Arduino UNO's power source.)

Am I missing something like this? Using a microcomputer in the drive circuit of a piezo buzzer

• Can you add a schematic of your setup? – Gorloth Apr 17 '17 at 16:00
• What are you attaching the buzzer to? Can you draw a schematic? If you click "edit" then there is a button on the toolbar which lets you add schematics to your post. – Jack B Apr 17 '17 at 16:01
• Add a $10\mu F$ capacitor across the buzzer also don't forget about capacitors across the VDD and GND pin – G36 Apr 17 '17 at 17:00
• Have you accidentally enabled the ICP interrupt on Timer 1? That might account for weird behaviour if the input capture event is enabled but has not ISR defined. Your buzzer is connected to the ICP pin is what made me think of that. – Tom Carpenter Apr 17 '17 at 18:45
• Do not add a capacitor across the buzzer! It will only make things worse, and prevent a passive buzzer from working properly. – Bruce Abbott Apr 20 '17 at 2:45

No voltage regulators or capacitors... could that be the problem?

Yes. With an unregulated power supply and no bypass capacitors the supply voltage will change whenever the current changes. CMOS logic gates draw brief spikes of high current when they change states, which interacts with power supply inductance and resistance to cause glitches that are likely to make the MCU misoperate.

But why does it work OK without the buzzer connected? Probably because there is just enough stray capacitance in the chips and wiring to keep them working. But peizo buzzers have a relatively large capacitance which must be charged when voltage is applied to them, causing a massive current surge. The tiny amount of stray capacitance in your circuit is not nearly enough to hold the supply voltage stable while the piezo element charges, so Vcc sags and causes the MCU to freeze or do other weird stuff. Even when the buzzer is 'off' there may still be transitions when the I/O port is initialized or accessed, which produce pulses too short to hear but long enough to glitch the MCU.

The power supply pins of any digital logic IC should always be bypassed with a capacitor, even it seems to work fine without it. MCUs are full of sequential logic which often fails spectacularly if even a single glitch gets through, so having a stable noise-free power supply is essential.

You should install a 100nF ceramic capacitor directly across the supply pins of both the ATtiny84 and 74HC595, and a larger 'bulk' electrolytic capacitor >=10uF to handle longer current surges.

• Worked like a charm, thanks Bruce! Adding the 10uF already fixed the system. I'll add the 100nFs for safety as well. Changing my schematic already so I can order a PCB...! :) All the best. – Pedro Apr 25 '17 at 13:40
• Oh, quick question -- am I better off using a voltage regulator? Does it matter? I have a couple of regulators now. Or should I just use the capacitors as you describe? – Pedro Apr 25 '17 at 13:40
• For what you are doing a voltage regulator isn't necessary. A regulator is recommended for protection against power supply spikes (particularly when driving a motor or relay), for better frequency stability, and for lower noise when using the ADC. – Bruce Abbott Apr 26 '17 at 0:01