mechanical key/Using it/09. When it misbehaves
Using it · 09 of 9

When it misbehaves

The key and the light share only GND and VCC, so they fail apart: a key that reads perfectly beside a dark LED is one fault, not two. Decide which half is wrong first, then check the wire, the pin number and the one line of code that half depends on.

Which half

What it does, and where to look
What it does
Check that the WS2812 wire is on the pin LED_PIN names (the GPIO number, not the position on the header), that VCC and GND are in, and that the sketch calls show() or write() after setting a colour: setting it alone sends nothing. The LED does not light from the key. Try red first; on 3V3 it is the colour most likely to show.

Run the first press sketch and watch two things: the serial monitor, which is the key, and the keycap, which is the light.

  • Lines print, the key stays dark: the light. Look at the WS2812 wire, LED_PIN, and the show() or write() call.
  • The key lights, but nothing prints or it prints the wrong thing: the key. Look at the BUTTON wire, BUTTON_PIN, and the test for HIGH.
  • Neither: what they share, VCC and GND.

The key

A key that never reads HIGH has no VCC, or is being read on the wrong pin: the pull-down holds BUTTON LOW until the switch joins it to VCC. A key that reads backwards is being tested for LOW, the mistake the page this handbook replaced made. A key that steps two modes for one press is bouncing, and needs the debounce the modes sketch uses.

The light

A dark LED is a missing show(), the wrong pin, or no supply. Red showing as green is the colour order: NEO_GRB. Green and blue weak beside a bright red, on a 3.3 V board, is the LED running under its 3.5 V minimum. It is not broken; One VCC, two jobs shows how to give it 5 V without putting 5 V on your pin.

When it does not work

Neither the key nor the light does anything.

That is the half they share: GND and VCC. Check both wires, and that VCC is on a pin that has power. With VCC off, BUTTON stays LOW through the pull-down and the LED has no supply, which looks exactly like two faults at once.

The LED shows a random colour when the board starts.

A WS2812 can start up showing something before it is told anything. Both sketches send a dark frame in setup() for that reason. If yours does not, add key.show() (Arduino) or key.write() (MicroPython) straight after starting the LED.

It worked, then the key got warm or my board reset when I pressed.

Something is shorting when the key closes: most likely BUTTON is on a pin that is driving an output, or VCC and GND are swapped. Unplug it and check the four wires against the square pad before trying again.

The colour flickers with long wires.

The board has no capacitor at the LED, though its maker's sheet asks for one. Keep the wires short, and if it still flickers put 100 nF across VCC and GND at the header.

Where this goes next

Five LEDs of the same kind in a chain on one data pin, and why that one wants 5 V on VCC.

The TK33 WS2812 RGB LED Bar →

Edit this page — content/books/mechanical-key/when-it-misbehaves.mdx

Community

Questions about this product

See what other owners have asked, and read their solutions.

Ask a question ↗

Mechanical Key and LED

Loading discussions…

Discuss this article

Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.

Browse Modules and blocks on the forum →