Every inventor began with one small project. Pick one and bring your idea to life today!
Great inventors and great teachers all started with one small step. Take yours today!
The same kits we use in 40+ school labs — grab yours and build something you’re proud of.
Log in to continue
Three special modules, seven functions: the ultrasonic sensor measures distance like a bat, the DHT11 feels temperature and humidity, and the joystick turns your thumb into numbers. Let’s code all of them!
The ultrasonic sensor’s reading in centimetres. Its pins are fixed (Mega: i3 TRIG, i4 ECHO), so you write no pin: d = distance().
The DHT11’s temperature in °C: t = dht_temperature(weather) for a DHT11 named weather.
How much water vapour is in the air, in %: h = dht_humidity(weather).
How far the stick is pushed: −100 to 100, 0 in the middle. x is left/right, y is down/up. TinkerPy Mega only.
Where the stick points as a letter: 'F' up, 'B' down, 'L', 'R', or 'S' in the middle.
Drag the wall closer or further. The sensor times the echo — and the warning LED decides.
Tap each module to see its functions, pins and what it gives back.
# Add the libraries you need import ultrasonic import buzzer # Give your pins easy-to-remember names o1 = set_name("warning") o2 = set_name("beeper") # ===== Car parking sensor ===== # This code block executes only once setup: i3 = set_input(ultrasonic_trig) # cannot be changed i4 = set_input(ultrasonic_echo) # cannot be changed warning = set_output(led) beeper = set_output(buzzer) # This code block executes forever loop: d = distance() # how far the wall is, in cm (-1 = nothing in range) if d > 0 and d < 10: # when d > 0 and d < 10 warning = ON # turn warning ON beeper = ON # turn beeper ON elif d > 0 and d < 30: # otherwise, when d > 0 and d < 30 warning = ON # turn warning ON beeper = ON # turn beeper ON wait(100) # pause here for 100 milliseconds before continuing beeper = OFF # turn beeper OFF wait(300) # pause here for 300 milliseconds before continuing else: # otherwise warning = OFF # turn warning OFF beeper = OFF # turn beeper OFF
A car parking sensor with three zones: closer than 10 cm the LED and beeper stay on, 10–29 cm the beeper ticks, 30 cm or more (or nothing in range, −1) all is quiet. This is the TinkerPy Mega wiring (i3, i4); on a Mini, Circuit Connections uses i2 and i1 instead.
# Add the libraries you need import dht11 # Give your pins easy-to-remember names i3 = set_name("weather") o1 = set_name("fan") o2 = set_name("humid_led") # ===== Classroom comfort meter ===== # This code block executes only once setup: weather = set_input(dht11) fan = set_output(fan) humid_led = set_output(led) # This code block executes forever loop: t = dht_temperature(weather) # temperature in °C h = dht_humidity(weather) # humidity in % if t > 30: # when t > 30 fan = ON # turn fan ON else: # otherwise fan = OFF # turn fan OFF if h > 70: # when h > 70 humid_led = ON # turn humid_led ON else: # otherwise humid_led = OFF # turn humid_led OFF wait(2000) # a DHT11 likes a reading about every 2 seconds
A classroom comfort meter: the fan comes on above 30 °C and an LED warns when the air is very humid (above 70%). It reads the DHT11 named weather on i3 every 2 seconds (TinkerPy Mega; on a Mini, put the DHT11 on i1).
# Add the libraries you need import joystick import buzzer # Give your pins easy-to-remember names o1 = set_name("left_led") o2 = set_name("right_led") o4 = set_name("top_led") o5 = set_name("beeper") # ===== Joystick light ===== # This code block executes only once setup: i1 = set_function(joystick_x) # joystick X (left / right) — needs one of i1-i4 i2 = set_function(joystick_y) # joystick Y (up / down) — needs one of i1-i4 i3 = set_function(joystick_swt) # joystick push switch — any pin, or delete this line left_led = set_output(led) right_led = set_output(led) top_led = set_output(led) beeper = set_output(buzzer) # This code block executes forever loop: d = joystick_direction() # F, B, L, R or S if d == 'L': # when d == 'L' left_led = ON # turn left_led ON right_led = OFF # turn right_led OFF elif d == 'R': # otherwise, when d == 'R' left_led = OFF # turn left_led OFF right_led = ON # turn right_led ON else: # otherwise left_led = OFF # turn left_led OFF right_led = OFF # turn right_led OFF y = joystick_y() # -100 (down) to 100 (up) if y > 0: # when y > 0 top_led = pwm(y) # set top_led to y else: # otherwise top_led = OFF # turn top_led OFF if joystick_pressed() == 1: # when joystick_pressed() == 1 beeper = ON # turn beeper ON else: # otherwise beeper = OFF # turn beeper OFF
A joystick-controlled light (TinkerPy Mega). Push left or right and that LED lights; push up and top_led gets brighter with joystick_y(); press the stick in and the buzzer sounds. Ticking the Joystick library wrote the three set_function lines.
Bats shout sounds too high for us to hear and listen for the echo to find insects in the dark — the same trick as your ultrasonic sensor.
On humid days the air already holds lots of water vapour, so sweat dries slowly and you feel sticky. A DHT11 can show you the number.
Many game controller sticks are two knobs inside — one for left/right and one for up/down — read as numbers, just like joystick_x() and joystick_y().
Build the three-zone parking sensor on a cardboard garage wall. Change it so the beeper ticks faster as the car gets closer: use a third zone below 20 cm with a shorter wait.
🧰 You need: TinkerPy Mega, ultrasonic sensor, LED, buzzerFour LEDs in a plus shape: joystick_direction() lights the LED in the direction you push, and pressing the stick in turns them all on.
🧰 You need: TinkerPy Mega, joystick module, 4 LEDsSound travels about 343 metres every second in air, so an echo from a wall 1 metre away comes back in about 6 thousandths of a second — and the sensor times it.
5 quick questions to check yourself — free with your TinkerPy account.
Log in