TINKER PiEDESIGN IN INDIA

Knock Sensor Brick

Kit Bricks · SKU TP-K19

Spring sensor that feels a tap or a knock.

₹299

Pre-order

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

Spring sensor that feels a tap or a knock. The Knock Sensor Brick is a carrier for the KY-031 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

Specifications

Kit moduleKY-031 Knock Sensor (module 19 of the 37-in-1 sensor kit)
SocketKIT SENSOR: 2.54 mm female, S + -
Size48 x 32 mm, M3 holes on the 8 mm grid
Connectors2 x JST-PH 4-pin TP-BUS (IN / OUT)
InterfaceI2C 0x08-0x0F (8 on one bus)
Power3.3 V from the SENSOR port
BrainWCH CH32V003
Arduino classtpb::KitSensor

How to use it with TinkerPie

  1. Plug the KY-031 module into the 2.54 mm socket on the top edge. Match the pin names: the brick says S + -, the module has the same letters.
  2. Connect BUS IN to any TinkerPie SENSOR 1-4 port with a 4-pin JST-PH cable (the same cable as the other sensors).
  3. 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 (0x08-0x0F; the first is 0x08).
  4. 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++)
// Knock Sensor Brick (TP-K19): 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::KitSensor s;

void setup() {
  Serial.begin(115200);
  tinkerpie::begin();            // also starts the SENSOR ports (I2C bus Wire1)
  if (!s.begin()) Serial.println("Knock Sensor Brick not found at 0x08: check the cable to SENSOR 1-4");
}

void loop() {
  bool level = s.state();            // the S pin, debounced
  uint8_t n = s.events();            // how many times it fired (counts up, wraps at 255)
  Serial.printf("S = %d   events = %u\n", level, n);
  if (level) led::fill(Colors::Green); else basic::clearScreen();
  basic::pause(100);
}

Project: Secret knock lock

Knock three times within two seconds to unlock: a servo on S1 turns and the matrix shows a tick.

Secret knock lock (Arduino C++)
// Secret knock lock: Knock Sensor Brick (TP-K19)
// Knock three times within two seconds to unlock: a servo on S1 turns and the matrix shows a tick.
#include <TinkerPie.h>
#include <TinkerPieBricks.h>
using namespace tinkerpie;

tpb::KitSensor knock;
uint8_t last = 0;
int knocks = 0;
uint32_t firstAt = 0;

void setup() {
  Serial.begin(115200);
  tinkerpie::begin();            // also starts the SENSOR ports (I2C bus Wire1)
  if (!knock.begin()) Serial.println("Knock Sensor Brick not found at 0x08: check the cable to SENSOR 1-4");
  last = knock.events();
  servos::setAngle(ServoPort::S1, 0);
}

void loop() {
  uint8_t n = knock.events();
  if (n != last) { last = n; if (knocks == 0) firstAt = millis(); knocks++; music::playTone(800, 30); }
  if (knocks > 0 && millis() - firstAt > 2000) {
    if (knocks == 3) { basic::showIcon(IconNames::Yes, Colors::Green); servos::setAngle(ServoPort::S1, 90); basic::pause(3000); servos::setAngle(ServoPort::S1, 0); }
    else basic::showIcon(IconNames::No, Colors::Red);
    basic::clearScreen(); knocks = 0;
  }
  basic::pause(10);
}

More TinkerPie Bricks

DS18B20 Temperature Brick (TP-K01)DS18B20 Temperature BrickTP-K01 · Environment · KY-001Waterproof-grade digital thermometer chip, read in C over I2C.₹299Pre-orderShock Switch Brick (TP-K02)Shock Switch BrickTP-K02 · Motion · KY-002Detects knocks and vibration with a spring switch.₹299Pre-orderHall Magnetic Sensor Brick (TP-K03)Hall Magnetic Sensor BrickTP-K03 · Magnetic · KY-003Senses a magnet near the A3144 hall switch.₹299Pre-orderButton Switch Brick (TP-K04)Button Switch BrickTP-K04 · Input · KY-004A tactile push button on the bus.₹299Pre-order

See all 53 TinkerPie Bricks