TK61DIGITALbeginner

Infrared Speed Sensor

A slotted optical gate. Put an encoder disc through it and you can count revolutions — reliably, at speeds a mechanical switch could not survive.

Comes in this kit — not sold separately

Specifications

TypeSlotted optical interrupter
OutputDigital, changes when the slot is blocked
Slot widthAbout 5 mm
Supply voltage3.3 V or 5 V

What it is

An infrared emitter on one side of a gap and a detector on the other. Something in the gap breaks the beam.

Attach a disc with slots cut in it to a shaft, put the disc through the gap, and each slot passing gives a pulse. Count pulses per second and you have speed; count them over time and you have distance travelled.

Because it is optical there is nothing to wear out and no bounce, which is why it handles speeds a reed switch could not. The limit is the interrupt rate: at high RPM with a many-slotted disc you can generate pulses faster than the loop can count, so put it on a hardware interrupt and keep the handler to a single increment.

It also works as a simple presence detector — an end-stop, or a "the drawer is closed" switch.

Infrared Speed Sensor — front
Front
Infrared Speed Sensor — back
Back
Infrared Speed Sensor — side
Side

Pinout

  • GND (negative): Like the negative terminal (-) of a battery, connect to the control board's GND
  • VCC (positive): Like the positive terminal (+) of a battery, connect to the control board's 3.3V or 5V (this module supports both 3.3V and 5V)
  • NC (no connection): No actual circuit connection, included for unified interface, can be left unconnected
  • SIGNAL (signal output): Detection output pin, connect to the control board's digital pin (e.g. Arduino D2 or Pico GPIO 0)
    • Outputs HIGH (HIGH/1) when object blocks light
    • Outputs LOW (LOW/0) when no object detected

Wiring

Infrared Speed Sensor wiring

  1. GND → Control board GND
  2. VCC → Control board 3.3V or 5V
  3. SIGNAL → Control board digital pin (use the pin defined in your program)

Example

// Pin number: change this to match your wiring
#define PHOTO_SWITCH_PIN 2  // Arduino digital pin connected to SIGNAL (e.g. D2)
#define LED_PIN 13          // LED pin (Arduino built-in LED on pin 13, or external LED)

void setup() {
  // Initialize pin modes
  pinMode(PHOTO_SWITCH_PIN, INPUT);   // Set photoelectric switch pin as input (to read detection state)
  pinMode(LED_PIN, OUTPUT);           // Set LED pin as output (to control LED on/off)
  
  // Start serial for debugging (9600 baud)
  Serial.begin(9600);
  
  Serial.println("Photoelectric switch program started");
  Serial.println("LED on when object blocks light, LED off when no object detected");
}

void loop() {
  // Read photoelectric switch state
  int switchState = digitalRead(PHOTO_SWITCH_PIN);  // Read sensor pin level: HIGH(1)=object detected, LOW(0)=no object
  
  // Control LED based on detection state
  if (switchState == HIGH) {
    // Object blocks light: LED on
    digitalWrite(LED_PIN, HIGH);
    Serial.println("Object blocks light - LED on");
  } else {
    // No object detected: LED off
    digitalWrite(LED_PIN, LOW);
    Serial.println("No object detected - LED off");
  }
  
  delay(100);  // Brief delay to avoid reading too fast
}
Infrared Speed Sensor running on an Arduino Uno

When it doesn’t work

The count is low at speed.
Polling, or too much work in the interrupt handler. Increment a `volatile` counter and nothing else; do the arithmetic in the main loop.
It counts extra pulses.
The disc edge is passing slowly through the threshold, so the output hovers. Add hysteresis in software, or spin faster.
Ambient light affects it.
It shouldn't much — the beam is enclosed — but strong direct sun into the slot can saturate the detector. Shade it.

Edit this page — content/modules/ir-speed-sensor.mdx

Community

Questions about this product

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

Ask a question ↗

Infrared Speed 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