breadboard
docs

Example project · Displays

Ring with a power switch

The toggle switch gates the NeoPixel ring's 5 V pin while the ESP32-C3 keeps streaming rainbow frames: flick it off and the ring goes dark instantly; flick it on and the next frame repaints.

The Ring with a power switch circuit as rendered by the simulator

How it works

This is the NeoPixel ring with one change to the wiring: a latching toggle switch sits between the breadboard's positive rail and the ring's VCC pad. The ESP32-C3 and the ring still share ground, and G2 still carries the data, so the switch controls nothing but the ring's supply.

The script does not know the switch exists. It sends a new rainbow frame every 120 ms for 4000 frames, about eight minutes, whether the ring is powered or not. When the switch opens, the ring loses power and every pixel goes dark at once. After you close the switch, the pixels stay dark until the next frame. If the script has finished, press Run on board to start sending frames again. A real WS2812 behaves the same way, because each pixel holds its colour in its own latch, and that latch needs power.

What to watch

Click the switch lever to open it. The ring goes dark at once, while the C3 carries on and Serial stays quiet. While the script is running, close the switch again. The next frame lights the ring at the current point in the rotation. The lever position is saved with the circuit, so the project opens the way you left it.

What's on the bench

  • ESP32-C3
  • NeoPixel ring ×12
  • Toggle switch

How it's wired

  • hole a10→hole B-5
  • hole a11→hole B+5
  • hole B+9→hole a30
  • hole c32→hole a40
  • hole a42→hole B-9
  • hole a14→hole c41
  • ESP32-C3 · gnd→hole e10
  • ESP32-C3 · vin→hole e11
  • ESP32-C3 · g2→hole e14

The code

This MicroPython script runs on the emulated board every boot; edit it in Code.

# Rainbow chase on the ring. The toggle switch gates the ring's 5 V pin:
# flick it off and the pixels go dark instantly; flick it back on and the
# next frame repaints them. The C3 keeps streaming frames throughout.
import machine, neopixel, time

RAINBOW = [
    (255, 0, 0), (255, 96, 0), (255, 200, 0), (96, 255, 0),
    (0, 255, 60), (0, 255, 200), (0, 160, 255), (0, 40, 255),
    (90, 0, 255), (200, 0, 255), (255, 0, 160), (255, 0, 60),
]
np = neopixel.NeoPixel(machine.Pin(2), 12)
for step in range(4000):
    for i in range(12):
        np[i] = RAINBOW[(i + step) % 12]
    np.write()
    time.sleep_ms(120)
print('ring demo done')

Try this

  • Hover the ring's VCC pad with the switch closed and then open. It reads about 4.7 V when closed and close to 0 V when open.
  • Move the switch so it breaks the G2 data wire instead of VCC. Opening it now freezes the ring on its last frame, because the pixels still have power but receive no new data.
  • Change range(4000) to range(400) in Code and press Run on board. Serial prints ring demo done after about 48 s.

Related projects