[SOLVED] Control LED brightness with IR remote control

Hi.

I'm new to the world of Arduino and electronics. I'm only getting started and as the first project I would like to control the brightness of an LED using an IR remote control that was included in my starter kit, but I have 2 problems.

I got the remote setup and working, no problem with that. I do receive the input from the remote.

The first problem is that however, when I use the analogWrite() function in my code to control the brightness of the LED, for some reason I get a different value from the remote every single time I press the same button, therefore I have no way to tell if I have pressed the correct button on the remote. If I comment out the analogWrite() code and I do nothing with the leds, I get the same value from the remote each time I press the same button but when I have the code un-commented, I get different values for some reason.

On the above image as you can see I am pressing the same button on the remote but I get a different value each time.

The second problem is that if I'm working with more than 1 LED and I have analogWrite() twice in my code, everything just freeze, after 2 attempts, I get no input from the remote any more.

Using Arduino Uno R3 and the IRremote library.

This is my code:

#include <IRremote.h>

const int ledRedPin = 10; 
const int ledYellowPin = 9;
const int irReceiverPin = 11;

const long plusButton = 16754775;
const long minusButton = 16769055;

IRrecv iRrecever(irReceiverPin);

decode_results iRInput;

int ledRStr;
int ledYStr;

void setup() {

  Serial.begin(9600);

  iRrecever.enableIRIn();

  ledRStr = 0;
  ledYStr = 0;
}

void loop() {

  if (iRrecever.decode(&iRInput)) {
    
    //if plus button is pressed
    if(iRInput.value == plusButton)
    {
      ledRStr += 1;
      ledYStr += 1;
    }

    //if minus buttons is pressed
    if(iRInput.value == minusButton)
    {
      ledRStr -= 1;
      ledYStr -= 1;
    }

    Serial.println("IRInput value: " + String(iRInput.value));
    Serial.println("Led Strength: " + String(ledRStr));

    iRrecever.resume();

    //update leds
    analogWrite(ledRedPin, ledRStr);
    analogWrite(ledYellowPin, ledYStr);
    
  }

  delay(100);
}

Because I am new to Arduino and electronics, I have no idea why is this happening, I'm totally lost.
I was searching the forum and internet for examples of controlling LED brightness with remote but every single example I find is using digitalWrite() to simply turn the LED on and off but this is not what I want, I want to control the brightness.

In case it is a bug in the library I'm using (IRremote), is there any other libs I could use or is there any workaround exist?
I would appreciate any help or explanation why is this not working for me.

Thank you.

Ah, I have solved the problem.
The problem was that I was using the same ground pin for both the LED and the IR receiver.
I have connected them to two different ground and now it works.