Built-in project · ESP8266 NodeMCU V1.0

NodeMCU fade

An LED breathing on an ESP8266, which has no PWM hardware at all: the core moves the pin itself, and the range is 0 to 1023. The whole build, a NodeMCU ESP8266 and 2 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

Runs in your browser. Free, and no account needed.

NodeMCU fade · ESP8266 NodeMCU V1.0live0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · ESP8266 NodeMCU V1.0
// Fade: an LED on D1 breathing, on the software PWM.
//
// There is no PWM hardware on an ESP8266: analogWrite moves the pin from a
// timer handler. Two things follow. The range is 0 to 1023, not 0 to 255, and
// the core wakes twice a period to do the work, so a fading LED costs
// something here where on an ESP32 it costs nothing.

const int kLed = D1;

void setup()
{
    pinMode(kLed, OUTPUT);
    analogWriteFreq(1000);
}

void loop()
{
    for (int duty = 0; duty <= 1023; duty += 8) {
        analogWrite(kLed, duty);
        delay(4);
    }
    for (int duty = 1023; duty >= 0; duty -= 8) {
        analogWrite(kLed, duty);
        delay(4);
    }
}

Parts list

4 parts, plus the jumper wires. Every one is in the editor's parts bin.

How it is wired

3 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • ESP8266 NodeMCU V1.0 pin D1; Resistor, 220 Ω pin 1
  • Ground: ESP8266 NodeMCU V1.0 pin GND; LED, yellow pin C
  • Resistor, 220 Ω pin 2; LED, yellow pin A

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.