Powered by TinkerSpace
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 from ultrasonic import *. Then distance() gives you the distance in centimetres.

TinkerPy
from tinkerpy_mega import *

from ultrasonic import *

def setup():
    pass  # your code goes here

def loop():
    if distance() < 20:
        write_output(o1, pwm(100))
    else:
        write_output(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.

Chat with TinkerPy ๐Ÿ‘‹