TINKER PiEDESIGN IN INDIA

IR sensor people counterTinkerPieCircuit tutorial 20 of 24 · Intermediate · 20 minutes

Use an infrared obstacle sensor to count how many times something passes in front of it.

Open this circuit in TinkerPieCircuit (free, runs in your browser)

What you will learn

Parts

TinkerPie V1 board1 IR obstacle sensor1 LED1 resistor, 220 Ω

Steps

  1. Wire the sensor

    VCC → 3V3, GND → GND, OUT → P10.

  2. Wire the LED

    S1 → resistor → LED (+), LED (−) → GND.

  3. Read the sensor

    The sensor output is LOW when something is in front. digitalRead(P10) == LOW means "blocked".

  4. Count once

    Keep a variable wasBlocked. Count only when the sensor changes from clear to blocked.

  5. Test

    Press ▶ Start. Click the orange OBSTACLE switch on the sensor twice. The Serial monitor shows the count.

The code

let count = 0;
let wasBlocked = false;

function setup() {
  pinMode(P10, INPUT);
  pinMode(S1, OUTPUT);
}

function loop() {
  const blocked = digitalRead(P10) == LOW;
  digitalWrite(S1, blocked ? HIGH : LOW);
  if (blocked && !wasBlocked) {
    count = count + 1;
    Serial.println("People counted: " + count);
    tone(BUZZER, 880);
    delay(80);
    noTone(BUZZER);
  }
  wasBlocked = blocked;
  delay(20);
}

Copy this into the Code tab. It is Arduino-style JavaScript. The real board uses the same pin names (S1, P10…) in TinkerPie Studio.

How it works

The IR sensor sends invisible light and sees it bounce back from an object. The module pulls its output LOW when it sees a reflection. Counting only the change stops one person being counted many times.

Challenge: Show the count on the LED matrix by lighting that many dots.

← Car parking sensor · All 24 circuit tutorials · Automatic door with IR and a servo →