tone() messes with other pins

Hi all,
While experimenting with my Arduino today I ran into some weird behavior and narrowed it down to the tone() function.

Because I'm not sure if I'm doing something wrong, or because it's a bug, I'm not yet posting this to the issue list.

Hopefully someone has a suggestion how to fix this; in my code or in the Tone.cpp.

Connected to my Arduino:

  • Pin 2: 7495 clock pin
  • Pin 3: 7495 data pin
  • Pin 4: Piezo speaker

The 7495 is a 4-bit shift register, without output enable/latch.
The output of the 7495 changes on every going down edge of the clock signal.

When I'm using the tone function, my shift register seems to get clock signals sometimes, even though I'm not sending these from my code.

Any suggestions how to have these two cooperate?

int outputClockPin = 2;
int outputDataPin = 3;
int peizoSpeakerPin = 4;

void setup() {
  pinMode(outputClockPin, OUTPUT);
  pinMode(outputDataPin, OUTPUT);
  pinMode(peizoSpeakerPin, OUTPUT);

unsigned long nextBeep = 0;
unsigned long nextCount = 0;
byte count = 0;

void loop() {
  if(millis() >= nextBeep) {
    // Non blocking sound
    tone(peizoSpeakerPin, 3000, 200);
    nextBeep = millis() + 400;
  if(millis() >= nextCount) {
    nextCount = millis() + 500;
    // Blocking output to 7495
    shiftOut(outputDataPin, outputClockPin, LSBFIRST, count);

How does it behave if you disconnect the piezo from pin 4?

Disconnecting the piezo did actually improve the behavior. Without it connected the shift registers act normal again.

I have now added a pull down resistor to the clock signal and it works, even with the piezo attached.

So I guess it’s not a bug in the tone function, but rather in my circuit.

My understanding is that a piezo acts like a capacitor. If it really does act like a capacitor, I assume it could introduce unwanted voltage spikes into the circuit.

I really don't understand circuits very well but I do know how to post a link! Grumpy Mike may have something on his website that will help...