Thursday, December 29, 2022

ESP8266 PWM LED Control - AnalogWrite 255 Low Output

Problem:

While working on a project to create light panels rendering LED values via DMX over ARTNET, I found that the LEDs would only ever get so bright, falling quite short of their max capacity brightness. Testing the pin output with a DMM, I found that the output was about .8v. To my understanding, there is going to be a slight drop over the transistor, but not this much. I am using a Darlington TIP120 

Test Code:


#define LEDS D4
 
int brightness = 255;
int fadeSpeed = 10;

void setup() {
    pinMode(LEDS, OUTPUT);
}
void TurnOn(){
    for (int i = 0; i <= brightness; i++){
        analogWrite(LEDS, i);
        delay(fadeSpeed);
    }
}

void TurnOff(){
    for (int i = brightness; i >= 0; i--){
        analogWrite(LEDS, i);
        delay(fadeSpeed);
    }
}

void loop(){
    TurnOn();
    delay(4000);
    TurnOff();
    delay(4000);
}




Solution:

The manufacturer of the board had changed the max value from 1023 to 255 in new versions, my board was is not a newer board but I assumed it was. 


Reference

https://arduino-esp8266.readthedocs.io/en/latest/reference.html#analog-output

No comments: