Best Way to Fade an LED?

Hey All,
I'm doing a horrible job at fading an LED attached to a pwm pin on an esp8266 board. I've looked for solutions but found very little on the subject.

What I have here works but it seems like an awful solution. Are there better ways to do this?

[
    {
        "id": "b98134e55eb560af",
        "type": "inject",
        "z": "0ee37658510a1e94",
        "name": "Fade OFF",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "x": 140,
        "y": 560,
        "wires": [
            [
                "23a6b7f9682fed6c",
                "796f978f7d88a1f4",
                "371479573b2af806",
                "254567e033325769",
                "7fe62719cf750a83",
                "fd5f03d746cd6c8f",
                "c0a919c727a9fcf0"
            ]
        ]
    },
    {
        "id": "c0a919c727a9fcf0",
        "type": "trigger",
        "z": "0ee37658510a1e94",
        "name": "immediately 255",
        "op1": "",
        "op2": "255",
        "op1type": "num",
        "op2type": "num",
        "duration": "1",
        "extend": false,
        "overrideDelay": false,
        "units": "ms",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 420,
        "y": 400,
        "wires": [
            [
                "6b376b09c4e1a228",
                "de5e9c5871fafa67",
                "c69e992ade791a3c"
            ]
        ]
    },
    {
        "id": "fd5f03d746cd6c8f",
        "type": "trigger",
        "z": "0ee37658510a1e94",
        "name": "trigger in 10s, send 75",
        "op1": "255",
        "op2": "75",
        "op1type": "num",
        "op2type": "num",
        "duration": "10",
        "extend": false,
        "overrideDelay": false,
        "units": "s",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 440,
        "y": 440,
        "wires": [
            [
                "6b376b09c4e1a228",
                "de5e9c5871fafa67",
                "c69e992ade791a3c"
            ]
        ]
    },
    {
        "id": "371479573b2af806",
        "type": "trigger",
        "z": "0ee37658510a1e94",
        "name": "trigger in 20 s, send 20",
        "op1": "255",
        "op2": "20",
        "op1type": "num",
        "op2type": "num",
        "duration": "20",
        "extend": false,
        "overrideDelay": false,
        "units": "s",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 440,
        "y": 480,
        "wires": [
            [
                "6b376b09c4e1a228",
                "de5e9c5871fafa67",
                "c69e992ade791a3c"
            ]
        ]
    },
    {
        "id": "7fe62719cf750a83",
        "type": "trigger",
        "z": "0ee37658510a1e94",
        "name": "trigger in 25 s, send 17",
        "op1": "255",
        "op2": "17",
        "op1type": "num",
        "op2type": "num",
        "duration": "25",
        "extend": false,
        "overrideDelay": false,
        "units": "s",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 440,
        "y": 520,
        "wires": [
            [
                "6b376b09c4e1a228",
                "de5e9c5871fafa67",
                "c69e992ade791a3c"
            ]
        ]
    },
    {
        "id": "23a6b7f9682fed6c",
        "type": "trigger",
        "z": "0ee37658510a1e94",
        "name": "trigger in 30 s, send15",
        "op1": "255",
        "op2": "15",
        "op1type": "num",
        "op2type": "num",
        "duration": "30",
        "extend": false,
        "overrideDelay": false,
        "units": "s",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 440,
        "y": 560,
        "wires": [
            [
                "6b376b09c4e1a228",
                "de5e9c5871fafa67",
                "c69e992ade791a3c"
            ]
        ]
    },
    {
        "id": "796f978f7d88a1f4",
        "type": "trigger",
        "z": "0ee37658510a1e94",
        "name": "trigger in 40 s, send 13",
        "op1": "255",
        "op2": "13",
        "op1type": "num",
        "op2type": "num",
        "duration": "40",
        "extend": false,
        "overrideDelay": false,
        "units": "s",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 440,
        "y": 600,
        "wires": [
            [
                "6b376b09c4e1a228",
                "de5e9c5871fafa67",
                "c69e992ade791a3c"
            ]
        ]
    },
    {
        "id": "254567e033325769",
        "type": "trigger",
        "z": "0ee37658510a1e94",
        "name": "trigger in 50 s, send 10",
        "op1": "255",
        "op2": "10",
        "op1type": "num",
        "op2type": "num",
        "duration": "50",
        "extend": false,
        "overrideDelay": false,
        "units": "s",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 440,
        "y": 640,
        "wires": [
            [
                "6b376b09c4e1a228",
                "de5e9c5871fafa67",
                "c69e992ade791a3c"
            ]
        ]
    },
    {
        "id": "e9a3172b86e6b17f",
        "type": "trigger",
        "z": "0ee37658510a1e94",
        "name": "trigger in 1min 0",
        "op1": "255",
        "op2": "0",
        "op1type": "num",
        "op2type": "num",
        "duration": "1",
        "extend": false,
        "overrideDelay": false,
        "units": "min",
        "reset": "",
        "bytopic": "all",
        "topic": "topic",
        "outputs": 1,
        "x": 420,
        "y": 680,
        "wires": [
            [
                "de5e9c5871fafa67",
                "6b376b09c4e1a228",
                "c69e992ade791a3c"
            ]
        ]
    },
    {
        "id": "c69e992ade791a3c",
        "type": "debug",
        "z": "0ee37658510a1e94",
        "name": "debug 172",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 1110,
        "y": 520,
        "wires": []
    }
]

Hi @richiep you need to check flow you shared (JSON), it has extra quotes at the end.

I think it's better if you put the PWM logic inside the ESP82266 and only send a trigger from Node-RED.

If the hardware where you are running node red is a raspberry you could take a look at this option: PWM Control of LED

You could just flash the esp8266 with tasmota firmware, then you can just send MQTT values to the dimmer topic, or even just setup the fade parameters on the ESP so it fades up or down when you switch it on and off.

https://tasmota.github.io/docs/#/Home

1 Like

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