TK17DIGITALbeginner

Collision Sensor

A lever microswitch with its 10 kΩ pull-down and a red hit light already fitted: SIGNAL reads HIGH while the lever is pushed in. The bumper for a TinkerBlock robot, and the sense that never reports a wall that is not there.

Comes in this kit — not sold separately

Specifications

TypeLever microswitch bumper, normally open, active high
SwitchUsakro UK-E0516 lever microswitch, 12.7 mm long, lying flat with its lever past the top edge; clicks after about 1.4 mm of lever travel at about 70 gf
Pull-down10 kΩ from SIGNAL to GND, on the board. At rest reads LOW, lever pushed in reads HIGH
Hit lightRed LED with a 1 kΩ resistor on SIGNAL. Lights while the lever is in, about 3 mA from 5 V
Supply3.3 V or 5 V on VCC. On a hit, SIGNAL is at VCC, so use 3V3 beside an ESP32, ESP32-S3 or Pico and 5V beside an Uno
CurrentNothing at rest. About 3.5 mA from 5 V while the lever is held in
Pins to wire3 of the 4: GND, VCC and SIGNAL. NC is connected to nothing on the board
Header4-pin right-angle male, 2.54 mm pitch: GND, VCC, NC, SIGNAL, with GND on the square pad
Switch rating48 V DC or 125 V AC, 0.1 A; contact resistance 100 mΩ max; rated for 1 000 000 operations
Board22.4 × 30.4 mm, two 4.8 mm mounting holes 16 mm apart; 7.3 mm tall at the switch
In the box1 × TK17 block. It also ships inside the TinkerBlock kits

What it is

A lever microswitch, a 10 kΩ pull-down resistor, and a red LED that lights while the lever is pushed in. At rest the pull-down holds SIGNAL at 0 V and your board reads LOW. When something pushes the lever in about a millimetre and a half, the switch clicks, connects SIGNAL to VCC, and your board reads HIGH. Let go and it is LOW again.

The TK17 at an angle: a black board with a gold-plated border, a black and white lever microswitch lying flat along the far edge with a flat metal lever reaching past it, the switch's three legs soldered into the board, two small resistors and a tiny LED in the middle, two big mounting holes, lonely binary along the left edge, a boxed DIGITAL along the right, and a right-angle header whose four pins point out past the near edge.
The TK17. The lever reaches past the top edge, so that edge faces forward on a robot.

It is the TK04 push button's circuit with a different switch, and it reads the same way. What it is for is different. Ultrasonic and infrared sensors report a distance, and some surfaces fool them. A bumper reports nothing at all until it touches something, and then it is certain. Use a distance sensor such as the TK50 to slow down for what it can see, and this for what it could not.

VCC is the voltage your pin sees

The switch joins SIGNAL straight to VCC, so whatever is on VCC is what your pin receives on a hit:

Your boardVCC toOn a hit, SIGNAL isHit light
Arduino Uno5V5 Vabout 3 mA, bright
ESP32, ESP32-S3, Pico3V33.3 Vabout 1.3 mA, a little dimmer

Never 5V beside a 3.3 V board, and never a motor battery. With VCC unconnected, the bumper does nothing and the light never comes on. The LED currents are worked out from a red LED's typical forward voltage rather than measured.

Which pin is which

Switch at the top, header at the bottom, reading left to right:

GNDto your board's GNDthe square pad: count from here
VCCto 3V3 or 5Vyour board's logic voltage
NCnothingnot connected on the board
SIGNALto a digital inputHIGH while the lever is in

The switch has contacts called COM, NO and NC of its own. The board wires COM to VCC and NO to SIGNAL, and leaves the switch's NC unconnected; the header's NC pin is a different thing that also goes nowhere. The back prints TK17 COLLISION SENSOR and DETECTS IMPACTS instead of pin names. Turned over, the square pad is on the right, and it is still GND.

Wiring, in three lines

  1. GND to your board's GND.
  2. VCC to 5V on an Uno, 3V3 on an ESP32, ESP32-S3 or Pico.
  3. SIGNAL to a digital pin: D2 on an Uno, GPIO 25 on an ESP32, GPIO 4 on an ESP32-S3, GP15 on a Pico.

Leave NC unconnected. Set the pin to INPUT, not INPUT_PULLUP: the pull-down is already on the board. These are the TK04 push button's pins too.

Example

// The GPIO number SIGNAL is wired to.
// Uno: 2. ESP32: 25. ESP32-S3: 4. Pico: 15.
const int BUMPER_PIN = 4;

void setup() {
  Serial.begin(115200);
  pinMode(BUMPER_PIN, INPUT);   // the block has its own pull-down
}

void loop() {
  if (digitalRead(BUMPER_PIN) == HIGH) {   // HIGH is a hit
    Serial.println("hit");
  } else {
    Serial.println("clear");
  }
  delay(200);
}

Where to start

The handbook below is ten short articles, each with a working figure. The first read is the whole build in three wires and a few lines, and stop and back off is the sketch a robot actually needs.

If your hit counter goes up by more than one per bump, read one bump counts as several and then counting hits.

And before plugging it into an ESP32, VCC sets the voltage is the one page that protects the board.

When it doesn’t work

Does it read HIGH or LOW on a hit?
HIGH. The board has a 10 kΩ pull-down, not a pull-up: at rest SIGNAL sits at 0 V and reads LOW; with the lever pushed in, the switch connects it to VCC and it reads HIGH. Sketches written for active-low bumpers test for LOW and get this block backwards.
Should VCC go to 3V3 or 5V?
To your board's logic voltage: 3V3 on an ESP32, ESP32-S3 or Pico, 5V on an Uno. On a hit the switch connects SIGNAL straight to VCC, so the voltage on VCC is the voltage your pin receives. 5V on a 3.3 V board's pin is past its rating on every bump. Never the motor battery.
INPUT or INPUT_PULLUP?
INPUT. The block brings its own pull-down. The chip's internal pull-up would fight it and leave the resting level somewhere around a volt, which no datasheet promises to read as LOW. In MicroPython, Pin(pin, Pin.IN) with no pull argument.
Is there a sensitivity adjustment?
No. There is no potentiometer on the board. The switch clicks after its lever has moved about a millimetre and a half, at about 70 gf, and that is set by the switch. To cover a wider front, fit a light bumper plate that presses on the lever; do not bend the lever or load it with a long wire.
One bump counts as several.
Contact bounce: the switch's contacts make and break a few times in the first few milliseconds of every hit. Believe a change only once the pin has held still for about 20 ms. The handbook's sketch does it with millis() and no library.
It never reads a hit.
Push the lever until it clicks and look at the red LED. If it stays dark, VCC or GND is not connected, or the cable is one pin over. If it lights, the block is fine and SIGNAL is on a different pin from the one your sketch reads.

The collision sensor handbook

10 articles · about 45 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.

A bumper

2 articles

What a lever switch can promise that a distance sensor cannot, how far the lever moves before it counts, and the four pins, three of them wired.

How a touch becomes HIGH

3 articles

The switch's three contacts and the two the board uses, the pull-down and the red light, and the one rule that protects a 3.3 V board: whatever goes on VCC is what your pin sees on a hit.

Reading it

2 articles

Three wires and a sketch that prints what the pin says, then a hit counter that counts one bump three times, and why.

One hit, one action

3 articles

A debounced hit counter, a robot that backs away from what it hits without ever stopping to wait, and the short list of reasons a hit does nothing.

Lessons using TK17

Each one is a working build, not a snippet.

Edit this page — content/modules/collision-sensor.mdx

Community

Questions about this product

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

Ask a question ↗

Collision Sensor

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