IR Distance Sensor interfering with Piezo buzzer


I’m working on an Alarm Clock in which I’m using a IR Distance Sensor ( ) and and normal Piezo buzzer.
Everything is fine as long as the Piezo hasn’t made any sounds. After he has made sound and stops, there is a constant noise coming from it (not very loud but hearable and very annoying, it’s like a very fast beeping).
It doesn’t matter if I produce the sound with the standard tone() function or with the Tone library. The noise even occurs when i just do “analogWrite(51, 0);” in setup and nothing else.
The strange thing now is that if I unplug the Distance Sensor, the noise immediately stops and starts again when I plug it back in. It just has to be powered, no reading of the signal has to be done, so I think the only possibility is that the the sensor interferes with the piezo in some way.
I’m using an Arduino Mega and Win 7 64-Bit.
I hope someone knows why this noise occurs and how I can fix it.

We'd need to see the code running on the Arduino, and a wiring diagram.

Ok, the code is just this:

void setup() {
  tone(51, 440, 1000);

void loop() {

The Piezo is connected to Digital Pin 51 and on the other end to ground. The Distance Sensor is connected to +5V and ground (the signal out is not connected, because the noise occurs even when only those two are connected) The noise stops when disconnecting the Distance Sensor from +5V and/or ground.

EDIT: I just connected the Piezo to a different ground pin than the Distance Sensor and the noise is gone or at least so quiet that i can't hear it anymore. If anyone has an idea why that happened, I'd be glad to hear it.