Skip to main content
Added language specifier to code formatting and made key words bold.
Source Link

Not sure if this belongs more in an electronics SE, but I'll give this a try. I'm trying to use an ESP32-C3ESP32-C3 and an NPN transistor (2n55512N5551) to pwmPWM drive an LED (values below). I'm trying a simple fade, however the ledLED is not fading, but rather going in quite discreet steps.

I'm using analogWrite (snipped below), but I'm fairly sure the code is correct. It could very well be an issue with my soldering, but thought I'd ask here in case I'm missing something obvious?

I measured the ledLED at 100mA with a 2.7V drop, so I put it in serieseries with a 22ohm resistor. Diagram below:

schematic

simulate this circuit – Schematic created using CircuitLab

#include <Arduino.h>

unsigned long fadeStartTime;

void setup() {
    Serial.begin(115200);
    while(!Serial); // Wait for serial to be available
    Serial.println("Starting");
    setCpuFrequencyMhz(80);
    LOG_INFO(MODULE_NAME, "Finished setup.");
}

void loop() {
    unsigned long progress = millis() - fadeStartTime;
    long brightness;
    if (progress <= 3000) brightness = map(progress, 0, 3000, 0, 255);
    else if (progress <= 6000) brightness = map(6000 - progress, 0, 3000, 0, 255);
    else fadeStartTime = millis(); // restart fade again
    analogWrite(STEMS_DATA_PIN, brightness * brightness / 255);
}
    #include <Arduino.h>

    unsigned long fadeStartTime;

    void setup() {
        Serial.begin(115200);
        while(!Serial); // Wait for serial to be available
        Serial.println("Starting");
        setCpuFrequencyMhz(80);
        LOG_INFO(MODULE_NAME, "Finished setup.");
    }

    void loop() {
        unsigned long progress = millis() - fadeStartTime;
        long brightness;
        if (progress <= 3000) brightness = map(progress, 0, 3000, 0, 255);
        else if (progress <= 6000) brightness = map(6000 - progress, 0, 3000, 0, 255);
        else fadeStartTime = millis(); // restart fade again
        analogWrite(STEMS_DATA_PIN, brightness * brightness / 255);
    }

Not sure if this belongs more in an electronics SE, but I'll give this a try. I'm trying to use an ESP32-C3 and an NPN transistor (2n5551) to pwm drive an LED (values below). I'm trying a simple fade, however the led is not fading, but rather going in quite discreet steps.

I'm using analogWrite (snipped below), but I'm fairly sure the code is correct. It could very well be an issue with my soldering, but thought I'd ask here in case I'm missing something obvious?

I measured the led at 100mA with a 2.7V drop, so I put it in serie with a 22ohm resistor. Diagram below:

schematic

simulate this circuit – Schematic created using CircuitLab

#include <Arduino.h>

unsigned long fadeStartTime;

void setup() {
    Serial.begin(115200);
    while(!Serial); // Wait for serial to be available
    Serial.println("Starting");
    setCpuFrequencyMhz(80);
    LOG_INFO(MODULE_NAME, "Finished setup.");
}

void loop() {
    unsigned long progress = millis() - fadeStartTime;
    long brightness;
    if (progress <= 3000) brightness = map(progress, 0, 3000, 0, 255);
    else if (progress <= 6000) brightness = map(6000 - progress, 0, 3000, 0, 255);
    else fadeStartTime = millis(); // restart fade again
    analogWrite(STEMS_DATA_PIN, brightness * brightness / 255);
}

Not sure if this belongs more in an electronics SE, but I'll give this a try. I'm trying to use an ESP32-C3 and an NPN transistor (2N5551) to PWM drive an LED (values below). I'm trying a simple fade, however the LED is not fading, but rather going in quite discreet steps.

I'm using analogWrite (snipped below), but I'm fairly sure the code is correct. It could very well be an issue with my soldering, but thought I'd ask here in case I'm missing something obvious?

I measured the LED at 100mA with a 2.7V drop, so I put it in series with a 22ohm resistor. Diagram below:

schematic

simulate this circuit – Schematic created using CircuitLab

    #include <Arduino.h>

    unsigned long fadeStartTime;

    void setup() {
        Serial.begin(115200);
        while(!Serial); // Wait for serial to be available
        Serial.println("Starting");
        setCpuFrequencyMhz(80);
        LOG_INFO(MODULE_NAME, "Finished setup.");
    }

    void loop() {
        unsigned long progress = millis() - fadeStartTime;
        long brightness;
        if (progress <= 3000) brightness = map(progress, 0, 3000, 0, 255);
        else if (progress <= 6000) brightness = map(6000 - progress, 0, 3000, 0, 255);
        else fadeStartTime = millis(); // restart fade again
        analogWrite(STEMS_DATA_PIN, brightness * brightness / 255);
    }
added 363 characters in body
Source Link
Lorenzo
  • 149
  • 8

Not sure if this belongs more in an electronics SE, but I'll give this a try. I'm trying to use an ESP32-C3 and an NPN transistor (2n5551) to pwm drive an LED (values below). I'm trying a simple fade, however the led is not fading, but rather going in quite discreet steps.

I'm using analogWrite (snipped below), but I'm fairly sure the code is correct. It could very well be an issue with my soldering, but thought I'd ask here in case I'm missing something obvious?

I measured the led at 100mA with a 2.7V drop, so I put it in serie with a 22ohm resistor. Diagram below:

schematic

simulate this circuit – Schematic created using CircuitLab

#include <Arduino.h>

unsigned long fadeStartTime;

void setup() {
    Serial.begin(115200);
    while(!Serial); // Wait for serial to be available
    Serial.println("Starting");
    setCpuFrequencyMhz(80);
    LOG_INFO(MODULE_NAME, "Finished setup.");
}

void loop() {
    unsigned long progress = millis() - fadeStartTime;
    long brightness;
    if (progress <= 3000) brightness = map(progress, 0, 3000, 0, 255);
    else if (progress <= 6000) brightness = map(6000 - progress, 0, 3000, 0, 255);
    else fadeStartTime = millis(); // restart fade again
    analogWrite(DATA_PINSTEMS_DATA_PIN, brightness * brightness / 255);
}

Not sure if this belongs more in an electronics SE, but I'll give this a try. I'm trying to use an ESP32-C3 and an NPN transistor (2n5551) to pwm drive an LED (values below). I'm trying a simple fade, however the led is not fading, but rather going in quite discreet steps.

I'm using analogWrite (snipped below), but I'm fairly sure the code is correct. It could very well be an issue with my soldering, but thought I'd ask here in case I'm missing something obvious?

I measured the led at 100mA with a 2.7V drop, so I put it in serie with a 22ohm resistor. Diagram below:

schematic

simulate this circuit – Schematic created using CircuitLab

unsigned long progress = millis() - fadeStartTime;
long brightness;
if (progress <= 3000) brightness = map(progress, 0, 3000, 0, 255);
else if (progress <= 6000) brightness = map(6000 - progress, 0, 3000, 0, 255);
else fadeStartTime = millis(); // restart fade again
analogWrite(DATA_PIN, brightness * brightness / 255);

Not sure if this belongs more in an electronics SE, but I'll give this a try. I'm trying to use an ESP32-C3 and an NPN transistor (2n5551) to pwm drive an LED (values below). I'm trying a simple fade, however the led is not fading, but rather going in quite discreet steps.

I'm using analogWrite (snipped below), but I'm fairly sure the code is correct. It could very well be an issue with my soldering, but thought I'd ask here in case I'm missing something obvious?

I measured the led at 100mA with a 2.7V drop, so I put it in serie with a 22ohm resistor. Diagram below:

schematic

simulate this circuit – Schematic created using CircuitLab

#include <Arduino.h>

unsigned long fadeStartTime;

void setup() {
    Serial.begin(115200);
    while(!Serial); // Wait for serial to be available
    Serial.println("Starting");
    setCpuFrequencyMhz(80);
    LOG_INFO(MODULE_NAME, "Finished setup.");
}

void loop() {
    unsigned long progress = millis() - fadeStartTime;
    long brightness;
    if (progress <= 3000) brightness = map(progress, 0, 3000, 0, 255);
    else if (progress <= 6000) brightness = map(6000 - progress, 0, 3000, 0, 255);
    else fadeStartTime = millis(); // restart fade again
    analogWrite(STEMS_DATA_PIN, brightness * brightness / 255);
}
Source Link
Lorenzo
  • 149
  • 8

ESP32 LED PWM fade not working?

Not sure if this belongs more in an electronics SE, but I'll give this a try. I'm trying to use an ESP32-C3 and an NPN transistor (2n5551) to pwm drive an LED (values below). I'm trying a simple fade, however the led is not fading, but rather going in quite discreet steps.

I'm using analogWrite (snipped below), but I'm fairly sure the code is correct. It could very well be an issue with my soldering, but thought I'd ask here in case I'm missing something obvious?

I measured the led at 100mA with a 2.7V drop, so I put it in serie with a 22ohm resistor. Diagram below:

schematic

simulate this circuit – Schematic created using CircuitLab

unsigned long progress = millis() - fadeStartTime;
long brightness;
if (progress <= 3000) brightness = map(progress, 0, 3000, 0, 255);
else if (progress <= 6000) brightness = map(6000 - progress, 0, 3000, 0, 255);
else fadeStartTime = millis(); // restart fade again
analogWrite(DATA_PIN, brightness * brightness / 255);