DIGITALbeginner

Mechanical Key and LED

A keyboard switch with a WS2812 RGB LED under its clear keycap, as two separate circuits: the key reads HIGH when pressed through its own 10 kΩ pull-down, and the LED shows whatever colour your sketch sends it. VCC is your board's logic voltage.

Comes in this kit — not sold separately

Specifications

TypeA keyboard key and an RGB LED on one block, as two separate circuits: pressing the key does not light the LED
SwitchMX-style keyboard switch, blue stem, clear housing, under an 18 mm frosted clear keycap. The parts list names no maker or model
Key outputBUTTON reads HIGH while the key is down and LOW while it is up, through a 10 kΩ pull-down on the board. Set the pin to INPUT
LEDOne XINGLIGHT XL-2020RGBC-WS2812B under the switch: 24 bits a colour, green first, 256 levels per colour, on its own data pin
SupplyYour board's logic voltage on VCC: 5V on an Uno, 3V3 on an ESP32, ESP32-S3 or Pico. A press puts VCC on the BUTTON pin. The LED is rated 3.5 to 5.5 V, so on 3V3 it runs under its rating
Current0.5 mA dark and up to 5 mA per colour for the LED, about 15.5 mA at full white; 0.5 mA at 5 V through the pull-down while the key is held
Pins to wireAll 4: GND, VCC, WS2812 and BUTTON. There is no NC pin
Header4-pin right-angle male, 2.54 mm pitch: GND, VCC, WS2812, BUTTON, with GND on the square pad
Board22.4 × 30.4 mm, two 4.8 mm mounting holes 16 mm apart beside the header. The back prints TK96 MECHANICAL KEY AND LED
Height24.06 mm from the bottom of the board to the top of the keycap (the mechanical drawing)
In the box1 × TK96 block with its keycap fitted. It also ships inside the TinkerBlock kits

What it does

A keyboard key and a colour light on one block. The key is an MX-style switch under a frosted clear keycap: pressed, it joins BUTTON to VCC, and a 10 kΩ resistor holds BUTTON at GND the rest of the time, so the pin reads HIGH while the key is down. Under the switch sits one WS2812, an RGB LED with its own controller, on a separate data pin.

Drag to turn it
The TK96. The LED is under the switch. Turn it over for the back.

The two are not connected to each other. Pressing the key does not light the light; your sketch reads the key and decides what colour to send. That is what makes it useful: the colour can show a mode or a state, not only that a finger is on the key.

The page this replaces got the board backwards in places. It said the key reads LOW when pressed (HIGH), put VCC on 5V for every board (a press would put 5 V on a 3.3 V pin), described the light as a plain LED behind a resistor (it is a WS2812, with no resistor), and its sketches drove pin 13 instead of the LED.

Two things to know before wiring

  • VCC is your board's logic voltage. A press puts VCC on the BUTTON pin: 5V on an Uno, 3V3 on an ESP32, ESP32-S3 or Pico. On 3V3 the LED runs under its 3.5 V rating; red holds up best.
  • A press is HIGH. Set the pin to INPUT, not INPUT_PULLUP, and debounce it if a press has to count once.

Wiring, in four lines

  1. GND to your board's GND.
  2. VCC to 5V on an Uno; 3V3 on an ESP32, ESP32-S3 or Pico.
  3. WS2812 to an output pin: D6 on an Uno, GPIO 4 on an ESP32, GPIO 5 on an ESP32-S3, GP14 on a Pico.
  4. BUTTON to an input pin: D2 on an Uno, GPIO 25 on an ESP32, GPIO 4 on an ESP32-S3, GP15 on a Pico.

Then install Adafruit NeoPixel, and the key lights red while you hold it.

Where to start

The handbook below is nine short articles, each with a working figure. The first press is the whole build. A key that remembers steps through modes, one colour each, one step per press.

For how it works, read two circuits, one key and one VCC, two jobs. If it does not behave, when it misbehaves.

When it doesn’t work

The LED does not light when I press the key.
It is not meant to. The key and the LED share only GND and VCC: a press sets BUTTON HIGH, and the LED changes colour only when your sketch sends it data on the WS2812 pin. Read BUTTON, then set the colour in code, as the first press sketch does.
Does a press read HIGH or LOW?
HIGH. The board has a 10 kΩ pull-down from BUTTON to GND, and the switch joins BUTTON to VCC. Use pinMode(pin, INPUT) and treat HIGH as pressed. The page this replaced said LOW; that was wrong.
Should VCC go to 3V3 or 5V?
To your board's logic voltage: 5V on an Uno, 3V3 on an ESP32, ESP32-S3 or Pico, because a press puts VCC on the BUTTON pin. On 3V3 the LED is under its 3.5 V minimum; it usually still lights, red best, green and blue dimmer. For full colour on a 3.3 V board, VCC on 5V and a 10 kΩ and 20 kΩ divider on BUTTON.
One press counts as several.
Contact bounce: the switch makes and breaks a few times as it closes. Accept a change only after the reading has been steady for about 20 ms, as the modes sketch does.
Can I chain several TK96s on one data pin?
No. The LED's data output is connected to nothing on this board, so each TK96 needs its own WS2812 pin.
What is the difference from the TK04?
The key circuit is the same: a switch to VCC and a 10 kΩ pull-down, HIGH when pressed. The TK04's small red LED is wired to the button and lights on its own; the TK96's WS2812 is on its own pin and does only what the sketch tells it, in any colour.

The mechanical key handbook

9 articles · about 40 minutes

This page is the reference: what the part is, what it is made of, and the questions people arrive already asking. The handbook is the walk — the same part in the order somebody actually meets it.

The board

2 articles

A keyboard switch and a WS2812 under it: two circuits that share GND and VCC and nothing else.

Wiring it

2 articles

Four pins, all of them wired, and a VCC that is both the key's HIGH and the light's supply.

How it works

2 articles

A press reads HIGH because of a pull-down, and a colour is 24 bits sent green first.

Using it

3 articles

A key that lights while held, a key that remembers a mode, and what to check when either misbehaves.

Edit this page — content/modules/mechanical-key.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 →