TINKER PiEDESIGN IN INDIA

Car parking sensorTinkerPieCircuit tutorial 19 of 24 · Advanced · 25 minutes

Combine an ultrasonic sensor, an RGB LED and a buzzer into a car parking assistant.

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

What you will learn

Parts

TinkerPie V1 board1 ultrasonic sensor1 RGB LED3 resistors, 220 Ω

Steps

  1. Wire the sensor

    VCC → 5V, GND → GND, TRIG → P10, ECHO → P11.

  2. Wire the RGB LED

    S1, S2, S3 through 220 Ω resistors to R, G and B. Long leg to GND.

  3. Set the zones

    More than 40 cm is green. 15 to 40 cm is orange with a slow beep. Under 15 cm is red with a steady tone.

  4. Test

    Press ▶ Start and drag the distance slider.

The code

function colour(r, g, b) {
  analogWrite(S1, r);
  analogWrite(S2, g);
  analogWrite(S3, b);
}

function loop() {
  const cm = readDistance(P10, P11);
  if (cm > 40) {
    colour(0, 255, 0);
    noTone(BUZZER);
  } else if (cm > 15) {
    colour(255, 140, 0);
    tone(BUZZER, 600);
    delay(60);
    noTone(BUZZER);
    delay(300);
  } else {
    colour(255, 0, 0);
    tone(BUZZER, 1000);
  }
  delay(100);
}

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 program reads the distance and picks a zone with if / else if. Each zone sets a different colour and sound. Real cars use exactly this idea.

Challenge: Add a fourth zone under 5 cm where the light blinks red.

← Distance meter with an ultrasonic sensor · All 24 circuit tutorials · IR sensor people counter →