RGB LED interfering with my alarm :/

Hi - I have a WeMos D1 R1 here with a little generic siren thing - I dunno what it's called so I'll just post a picture of it:

Anyway, everything was working fine until I decided to replace the standard LEDs with an RGB type. Now, whenever the color red (green & blue are fine) blinks, the speaker makes a tiny chirp. I tried disconnecting the power to the LED, but the chirping still occurs.

If I remove the jumper powering the speaker, or just the ground out, the chirping stops.

So my only guess is that the analogWrite signal for red (255,0,0) coming from the D5 pin is somehow bleeding over to the D13 pin that my speaker is on...?

I'm really confused here. I saw someone else had this problem but they just ended up switching to a new speaker.

I think the signal may even have an effect on the PIR sensor...not 100% sure on that though, so ignore it.

I would really like to know if there's a workaround here that doesn't involve me just using a new speaker - I'm a little disappointed that the signal seems to be bleeding into the other pins.

This is my first time using RGB LEDs so forgive me if I'm being dumb.

Here's the RGB code I'm using (just an example, I'm using it as an intermittent flash on my actual project, but same setup):

int redPin= D5;
int greenPin = D4;
int bluePin = D3;
void setup() {
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
}
void loop() {
  redLight();
  delay(1000);
  redFlash();
    greenLight();
  delay(1000);
  greenFlash();
    blueLight();
  delay(1000);
  blueFlash();
    whiteLight();
  delay(1000);
  whiteFlash();
    purpleLight();
  delay(1000);
  purpleFlash();
}
void setColor(int redValue, int greenValue, int blueValue) {
  analogWrite(redPin, redValue);
  analogWrite(greenPin, greenValue);
  analogWrite(bluePin, blueValue);
}
void redLight() {
  setColor(255, 0, 0);
  }
void redFlash() {
  setColor(0,0,0);
  delay(50);
  setColor(255, 0, 0);
  delay(50);
  setColor(0,0,0);
  delay(50);
  setColor(255, 0, 0);
  delay(50);
  setColor(0,0,0);
  delay(50);
  setColor(255, 0, 0);
  delay(50);
  setColor(0,0,0);
  delay(50);
  }

  void greenLight() {
  setColor(0, 255, 0);
  }
void greenFlash() {
  setColor(0,0,0);
  delay(50);
  setColor(0, 255, 0);
  delay(50);
  setColor(0,0,0);
  delay(50);
  setColor(0, 255, 0);
  delay(50);
  setColor(0,0,0);
  delay(50);
  setColor(0, 255, 0);
  delay(50);
  setColor(0,0,0);
  delay(50);
  }

  void blueLight() {
  setColor(0, 0, 255);
  }
void blueFlash() {
  setColor(0,0,0);
  delay(50);
  setColor(0, 0, 255);
  delay(50);
  setColor(0,0,0);
  delay(50);
  setColor(0, 0, 255);
  delay(50);
  setColor(0,0,0);
  delay(50);
  setColor(0, 0, 255);
  delay(50);
  setColor(0,0,0);
  delay(50);
  }

  void whiteLight() {
  setColor(255, 255, 255);
  }
void whiteFlash() {
  setColor(0,0,0);
  delay(50);
  setColor(255, 255, 255);
  delay(50);
  setColor(0,0,0);
  delay(50);
  setColor(255, 255, 255);
  delay(50);
  setColor(0,0,0);
  delay(50);
  setColor(255, 255, 255);
  delay(50);
  setColor(0,0,0);
  delay(50);
  }

  void purpleLight() {
  setColor(170, 0, 255);
  }
void purpleFlash() {
  setColor(0,0,0);
  delay(50);
  setColor(170, 0, 255);
  delay(50);
  setColor(0,0,0);
  delay(50);
  setColor(170, 0, 255);
  delay(50);
  setColor(0,0,0);
  delay(50);
  setColor(170, 0, 255);
  delay(50);
  setColor(0,0,0);
  delay(50);
  }

  void LEDOFF() {setColor(0,0,0);}

Any help here would be great - thank you

The D1 R1 is a strange beast. D5 and D13 are two names for the same pin. If you look closely at the printing on the board, pin D5 also says D13, but another pin that says D13 does not also say D5.

The esp8266 does not have enough pins to replace all those that the atmega328 on an Uno had, so some compromises had to be made, and some of the decisions made by the designer of the D1 R1 made were confusing for beginners who believed it was a WiFi enabled Uno clone. I think this is why it never became a popular board, unlike its little brother the R2 Mini.

PaulRB:
The D1 R1 is a strange beast. D5 and D13 are two names for the same pin. If you look closely at the printing on the board, pin D5 also says D13, but another pin that says D13 does not also say D5.

The esp8266 does not have enough pins to replace all those that the atmega328 on an Uno had, so some compromises had to be made, and some of the decisions made by the designer of the D1 R1 made were confusing for beginners who believed it was a WiFi enabled Uno clone. I think this is why it never became a popular board, unlike its little brother the R2 Mini.

Oh wow...I don't understand why they would double the pins like that, is there a purpose? I have a D1 Mini Pro here and the pins seem to me marked clearly, so maybe I'll just switch to that.

Well, the pins got doubled because they tried to maximise the chances of compatibility of the D1 R1 with Uno shields and other circuits and projects originally designed for Uno. But because of the limited number of pins on an esp8266, that compatibility level was always going to be limited. I think they did their best, but it was never going to be satisfactory.

Anyway, all you need to do is switch to using other pins, ones that are not shared. So try moving the speaker to another pin. Switching to the Mini does not get you any more pins than the D1 R2. Just pay more attention to all the markings the PCB.