# Best Way to Fade an LED?

**URL:** <https://discourse.nodered.org/t/best-way-to-fade-an-led/76370>\
**Category:** General\
**Tags:** function-node\
**Created:** [10 March 2023 02:21 UTC](https://discourse.nodered.org/t/best-way-to-fade-an-led/76370 "2023-03-10T02:21:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![richiep](https://avatars.discourse-cdn.com/v4/letter/r/59ef9b/32.png) [@richiep](https://discourse.nodered.org/u/richiep)\
**Post date:** [10 March 2023 02:21 UTC](https://discourse.nodered.org/t/best-way-to-fade-an-led/76370/1 "2023-03-10T02:21:59Z")

</div>

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?

```auto
[
    {
        "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": []
    }
]

```

---

<div class="post-metadata">

**Author:** ![MecatronicaMADE](https://avatars.discourse-cdn.com/v4/letter/m/ce7236/32.png) [@MecatronicaMADE](https://discourse.nodered.org/u/MecatronicaMADE)\
**Post date:** [10 March 2023 05:57 UTC](https://discourse.nodered.org/t/best-way-to-fade-an-led/76370/2 "2023-03-10T05:57:17Z")

</div>

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](https://flows.nodered.org/flow/deb935cffa0c86ee1a1fa73549a0f9a3)

---

<div class="post-metadata">

**Author:** ![Sean-McG](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sean-mcg/32/54677_2.png) [@Sean-McG](https://discourse.nodered.org/u/Sean-McG)\
**Post date:** [11 March 2023 00:50 UTC](https://discourse.nodered.org/t/best-way-to-fade-an-led/76370/3 "2023-03-11T00:50:55Z")

</div>

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](https://tasmota.github.io/docs/#/Home)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [10 May 2023 00:51 UTC](https://discourse.nodered.org/t/best-way-to-fade-an-led/76370/4 "2023-05-10T00:51:24Z")

</div>

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