I'm trying to implement a variable frequency buzzer using a PWM pin, and it works well other than occasionally resetting my arduino. Here's the circuit: The speaker is 8 ohm and hooked to the pin connector in the diagram. The transistor bases go to pin 13. This also has the nice side effect that I can hear my program uploading. My code causing the problem is this:
I borrowed an oscilloscope, and saw that the 5v line has some pretty big spikes above and below 5v which I suspect is causing my resets.
What's the best way to fix this? I decoupling capacitor between +5 and gnd?