powered by TinkerSpace.in
Join free
TinkerPy Projects lessons
๐Ÿ“
Lesson 8 of 10 ยท Maker ยท 10 min

Distance sensor

Measure how far away things are with an ultrasonic sensor.

๐Ÿ”Œ Wiring

The ultrasonic sensor always uses i3 and i4. Put an LED on o1.

Add import ultrasonic. Then distance() gives you the distance in centimetres.

TinkerPy
import ultrasonic

setup:

loop:
    if distance() < 20:
        o1 = pwm(100)
    else:
        o1 = 0
A parking sensor: the LED lights up when something is closer than 20 cm.
๐Ÿš€ Your turn

Add a buzzer on o2 that beeps when something is closer than 10 cm.