Rotary Encoder Brick



Pictured with the KY-040 kit module plugged in.
Kit Bricks · SKU TP-K33
Endless knob with push button: menus and volume.
₹299
Works with TinkerPie V1 · Arduino C++ with the TinkerPieBricks library · Delivery across India: ₹100, 3–7 days · 7-day replacement for damaged or defective kits
About this kit
Endless knob with push button: menus and volume. The Rotary Encoder Brick is a carrier for the KY-040 module from common 37-in-1 sensor kits: plug the module into the socket and connect one cable to a TinkerPie SENSOR port. A small CH32V003 processor on the brick does the timing work, so your program simply reads the result over I2C.
Features
- Position counter (int16) decoded in the brick
- 20 detents per turn
- Push button counter
- Plug the kit module straight into the socket – no jumper wires
- One cable to any TinkerPie SENSOR port (I2C), BUS IN + BUS OUT to chain more bricks
- On-board CH32V003 does the timing – your code just reads the result
Specifications
| Kit module | KY-040 Rotary Encoder (module 33 of the 37-in-1 sensor kit) |
|---|---|
| Socket | KIT ENCODER: 2.54 mm female, CLK DT SW + GND |
| Size | 48 x 32 mm, M3 holes on the 8 mm grid |
| Connectors | 2 x JST-PH 4-pin TP-BUS (IN / OUT) |
| Interface | I2C 0x2E-0x2F (2 on one bus) |
| Power | 3.3 V from the SENSOR port |
| Brain | WCH CH32V003 |
| Arduino class | tpb::KitEncoder |
How to use it with TinkerPie
- Plug the KY-040 module into the 2.54 mm socket on the top edge. Match the pin names: the brick says CLK DT SW + G, the module has the same letters.
- Connect BUS IN to any TinkerPie SENSOR 1-4 port with a 4-pin JST-PH cable (the same cable as the other sensors).
- More bricks? Plug the next one into BUS OUT. Two bricks of the same type need different addresses: bridge ADDR +1, +2 or +4 on the back (0x2E-0x2F; the first is 0x2E).
- Install the TinkerPie and TinkerPieBricks Arduino libraries, open the quick-start sketch below, choose the board ESP32S3 Dev Module and upload.
Libraries: TinkerPie and TinkerPieBricks (Arduino IDE: Sketch → Include Library → Add .ZIP Library). Full guide: getting started with TinkerPie Bricks.
Quick start
Upload this, open the Serial Monitor at 115200 baud and watch the TinkerPie matrix.
Quick-start sketch (Arduino C++)
// Rotary Encoder Brick (TP-K33): quick start
// Reads the brick and shows the value on the TinkerPie matrix and in the Serial Monitor (115200 baud).
#include <TinkerPie.h>
#include <TinkerPieBricks.h>
using namespace tinkerpie;
tpb::KitEncoder k;
void setup() {
Serial.begin(115200);
tinkerpie::begin(); // also starts the SENSOR ports (I2C bus Wire1)
if (!k.begin()) Serial.println("Rotary Encoder Brick not found at 0x2E: check the cable to SENSOR 1-4");
}
void loop() {
int16_t pos = k.position(); // turns: + clockwise, - anticlockwise
if (k.pressed()) k.zero();
Serial.println(pos);
led::plotBarGraph(abs(pos) % 31, 30, pos >= 0 ? Colors::Green : Colors::Blue);
basic::pause(50);
}
Project: Volume knob synth
Turn the knob to change the note, press it to play. Each click is a step of the C-major scale.
Volume knob synth (Arduino C++)
// Volume knob synth: Rotary Encoder Brick (TP-K33)
// Turn the knob to change the note, press it to play. Each click is a step of the C-major scale.
#include <TinkerPie.h>
#include <TinkerPieBricks.h>
using namespace tinkerpie;
tpb::KitEncoder knob;
const int SCALE[] = { 262, 294, 330, 349, 392, 440, 494, 523, 587, 659, 698, 784, 880, 988, 1047 };
void setup() {
Serial.begin(115200);
tinkerpie::begin(); // also starts the SENSOR ports (I2C bus Wire1)
if (!knob.begin()) Serial.println("Rotary Encoder Brick not found at 0x2E: check the cable to SENSOR 1-4");
}
void loop() {
int step = constrain(knob.position(), 0, 14);
led::plotBarGraph(step, 14, Colors::Purple);
if (knob.pressed()) music::playTone(SCALE[step], 200);
basic::pause(20);
}
More TinkerPie Bricks
DS18B20 Temperature BrickTP-K01 · Environment · KY-001Waterproof-grade digital thermometer chip, read in C over I2C.₹299Pre-order
Shock Switch BrickTP-K02 · Motion · KY-002Detects knocks and vibration with a spring switch.₹299Pre-order
Hall Magnetic Sensor BrickTP-K03 · Magnetic · KY-003Senses a magnet near the A3144 hall switch.₹299Pre-order
Button Switch BrickTP-K04 · Input · KY-004A tactile push button on the bus.₹299Pre-order