PWM: analogWrite(255) does not fully turn on the LEDs

Hi,

I would like to dimm a led stripe. AFAIK analogWrite 255 should generate "full-width pulses"? (I mean a static 3.3V signal)

This is how a analogWrite(255) look like on my PWM Pin:
pwm_AdobeExpress

Code looks like this:

void setup() {
  pinMode(D1, OUTPUT);
}

void loop() {
  for(int i=0; i <= 255; i++)
  {
    analogWrite(D1, i);
    delay(5);
  }
}

Any Ideas on how to achieve full brightness?

thanks

Welcome to the forum

Which Arduino board are you using ?

What's the duty cycle of the PWM?

Consider a 50% duty cycle would only be ON 50% of the time and lowers the brightness of the LED.

I am using a NodeMCU v3

What is "D1"?

Correct, but that is not what the code you posted does, is it ?

Nope, the posted code does exactly produce the signal in the gif

D1 defined as GPIO05 on the ESP12E

What do you expect it to do ?
Surely not a constant 3.3V output

Uhm .. I expected it to look like this:

grafik

The puls should be much longer, right? If I want a 100% Pulse width (255) then it should look like a constant line. My TON is around 200us and TOFF is 800us long .. (At a 100% Pulse)

Okay .. I thought that the analogWrite value is between 0 (0%) and 255 (100%) but it actually is 0-1024 ..

Sorry :smiley:

Nope, analogRead is between 0 and 1023, analogWrite is 0 and 255.

HI,
Despite having a port for reading analog variables, the ESP8266 NodeMCU module does not have pins that can be used to supply voltage signals whose modules are part of the intermediate values ​​of the range that goes from 0V to 3.3V. However, it is possible to use digital output ports to simulate analog output ports through the use of PWM, which in turn is a technique through which we can obtain analog results by digital means.

This feature consists of generating a square wave, in which the percentage of time the wave remains at a high logic level is controlled. This percentage is called the Duty Cycle and its alteration causes a change in the average value of the wave, ranging from 0V (0% of Duty Cycle) to 3.3V (100% of Duty Cycle) in the case of the ESP8266 NodeMCU. The Duty Cycle to be defined in the project corresponds to an integer number, which is stored in a 10-bit register. Therefore, its value ranges from 0 (0%) to 1023 (100%).

int pwm;

void setup() 
{ 
  pinMode(D1,OUTPUT);
  Serial.begin(115200);
}

void loop() 
{ 
       analogWrite(D1,pwm);
       Serial.print("the pwm value is : ");
       Serial.println(pwm);
       pwm = pwm +100;
       delay(1500);
       if(pwm>1023)
       {
            pwm = 0;
       }
}

Which version of the ESP8266 core are you using? The default range for analogWrite() was changed in 3.0.0.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.