PWM behaves incorrect (Arduino Mega)

Hi guys,

I am currently working with an Arduino Mega (ordered from Ebay) and need to use some pins as a PWM output. My project does not always work as intended and I noticed that the PWM is causing that. Therefore I did a test setup that involves two LEDs connected to a PWM pin each, two series resistors and the Mega. Nothing else. The Arduino is powered through USB.

I noticed the following:

PWM [analogWrite()] seems to work for:
-one LED
-both LEDs if they are set to the same value

but does not work when:
-chosing different values for the LEDs
-using digitalWrite() on any pin

Also I noticed, that it does not depend on the chosen pins (I think; didn't try every combination).

Some examples:

void setup(){
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  
  analogWrite(10, 20);
  analogWrite(11, 20);
}

void loop(){
}

//=> LEDs light up dimly, seems to work
void setup(){
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  
  analogWrite(10, 20);
  analogWrite(11, 30);              //changed this value
}

void loop(){
}

//=> LEDs do not light up
void setup(){
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(36, OUTPUT);

  digitalWrite(36, LOW);              //or HIGH
  analogWrite(10, 20);
  analogWrite(11, 20);
}

void loop(){
}

//=>LEDs do not light up

As far as my understanding goes, the LEDs should light up in each case. I hope you can help me and I appreciate any tips :smiley:

What version of Arduino IDE are you using?

I am using the most recent version, 1.8.10.

-using digitalWrite() on any pin

Not all pins support this function, see:

rtek1000:
Not all pins support this function, see:

analogWrite() - Arduino Reference

I am aware of that :smiley:
I bought a new one. It should arrive soon and I hope it works. By now, I think it is just a hardware issue.