Built-in project · ESP32-C3-DevKitM-1

Knight Rider on an ESP32-C3

An ESP32-C3 sweeps a bright dot back and forth along six LEDs, one GPIO each. The whole build, an ESP32-C3 and 12 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.

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

Knight Rider · ESP32-C3-DevKitM-1live0.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 · ESP32-C3-DevKitM-1
// Knight Rider: a dot sweeping back and forth along six LEDs.
//
// One GPIO per lamp, which is the simplest thing that can work and the reason
// it is the first thing anyone builds with more than one LED. GPIO 7, 6, 5 and
// 4 come out next to each other on the DevKitM-1's left header and GPIO 3 and 2
// a little further along, so the array below is the LEDs in the order they sit
// on the breadboard, not in pin order.
//
// The sweep turns round one short of each end, so the two end lamps are lit
// once per pass and the middle ones twice, which is what stops the bounce
// looking like it sticks at the ends.

const int LAMPS[] = {7, 6, 5, 4, 3, 2};
const int COUNT = 6;
const int STEP_MS = 90;

static void show(int lit) {
  for (int i = 0; i < COUNT; i++) {
    digitalWrite(LAMPS[i], i == lit ? HIGH : LOW);
  }
}

void setup() {
  for (int i = 0; i < COUNT; i++) {
    pinMode(LAMPS[i], OUTPUT);
    digitalWrite(LAMPS[i], LOW);
  }
  Serial.begin(115200);
  Serial.println("Mokxi ESP32-C3: six lamps, one dot");
}

void loop() {
  for (int i = 0; i < COUNT; i++) {
    show(i);
    delay(STEP_MS);
  }
  for (int i = COUNT - 2; i > 0; i--) {
    show(i);
    delay(STEP_MS);
  }
}

Parts list

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

How it is wired

13 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.

  • ESP32-C3-DevKitM-1 pin 2; Resistor, 220 Ω (1) pin 1
  • ESP32-C3-DevKitM-1 pin 3; Resistor, 220 Ω (2) pin 1
  • Ground: ESP32-C3-DevKitM-1 pin GND; LED, red (1) pin C; LED, red (2) pin C; LED, red (3) pin C; LED, red (4) pin C; LED, red (5) pin C; LED, red (6) pin C
  • ESP32-C3-DevKitM-1 pin 4; Resistor, 220 Ω (3) pin 1
  • ESP32-C3-DevKitM-1 pin 5; Resistor, 220 Ω (4) pin 1
  • ESP32-C3-DevKitM-1 pin 6; Resistor, 220 Ω (5) pin 1
  • ESP32-C3-DevKitM-1 pin 7; Resistor, 220 Ω (6) pin 1
  • Resistor, 220 Ω (1) pin 2; LED, red (1) pin A
  • Resistor, 220 Ω (2) pin 2; LED, red (2) pin A
  • Resistor, 220 Ω (3) pin 2; LED, red (3) pin A
  • Resistor, 220 Ω (4) pin 2; LED, red (4) pin A
  • Resistor, 220 Ω (5) pin 2; LED, red (5) pin A
  • Resistor, 220 Ω (6) pin 2; LED, red (6) 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.