I am using an Arduino Mega 2560. I am trying to change the brightness of an LED with the analogWrite function, but it does not seem to be working. Whenever the value for the analogWrite function is below 128, the LED is completely off, and my multi-reader shows 0v. When the value for analogWrite is greater than 128, the LED turns on and the multi-reader shows around 3v, but it does not increase when the value for analogWrite increases. Currently, there is nothing else connected to the Arduino except for the LED.
Here is the code that I used to test this:
const int ledPin = A15 ; // pin that LED is connected to
void setup()
{
pinMode(ledPin,OUTPUT) ; //set the ledPin as the output
Serial.begin(9600);
}
void loop()
{
//voltage begins at around 0v and LED is off.
analogWrite(ledPin, 25);
Serial.println("25");
delay(1000);
analogWrite(ledPin, 100);
Serial.println("100");
delay(1000);
// at this point, the LED turns on and voltage is around 3v
analogWrite(ledPin, 150);
Serial.println("150");
delay(1000);
analogWrite(ledPin, 200);
Serial.println("200");
delay(1000);
analogWrite(ledPin, 255);
Serial.println("255");
delay(1000);
// voltage remains at around 3v and LED does not change brightness.
}
Am I doing something wrong or is there something wrong with my Arduino?