Supplier photo of an assembled infinity mirror light cube illuminated on a dark background.
Supplier photo
Temu affiliate offer ยท Project idea

Build an infinity light cube

Listing specifies 5-volt direct current. Soldering required; battery and glue not included.

View kit on Temu

Tricky Circuit may earn a commission through these links. Product ideas have not been bench-tested by Tricky Circuit and are not verified lesson parts lists.

Pico Ultrasonic Theremin: Turn Hand Distance into Sound

Move your hand toward a distance sensor and hear the pitch rise. This small instrument turns a measured distance into sound, showing how a sensor, a mathematical rule and an output work together. It is inspired by a theremin, although it uses ultrasound rather than the original instrument’s radio-frequency sensing.

Target: original Raspberry Pi Pico or Pico H with the RP2040 microcontroller, running MicroPython 1.26. MicroPython is a version of Python for microcontrollers. Pico is different from a Raspberry Pi computer running Linux.

Pico GP14 triggers HC-SR04, a 2.2 kฮฉ and 3.3 kฮฉ divider protects GP15, and GP16 drives a passive piezo through 1 kฮฉ.
Original Tricky Circuit connection diagram. Component values are design values; physical build results have not been measured.

Parts and the important voltage boundary

  • Pico/Pico H, USB data cable and breadboard.
  • HC-SR04 ultrasonic module with a 5 V supply and a documented 3.3 V-compatible trigger input.
  • 2.2 kฮฉ and 3.3 kฮฉ resistors, preferably 1% tolerance, for the echo voltage divider.
  • Passive piezoelectric sounder suitable for 3.3 V drive, plus a 1 kฮฉ series resistor. Do not substitute a low-impedance speaker or magnetic buzzer.

The HC-SR04 sends an ultrasonic burst and returns a timed pulse. Its ECHO output can reach 5 V, while the Pico uses 3.3 V signals. A voltage divider, two resistors in series, reduces that signal before it reaches the Pico.

ConnectionPurpose
Pico VBUS, physical pin 40 โ†’ sensor VCCUSB’s 5 V supply. Use USB power for this experiment.
Pico GND โ†’ sensor GNDCommon voltage reference.
GP14, physical pin 19 โ†’ TRIGStarts a measurement.
ECHO โ†’ 2.2 kฮฉ โ†’ GP15, physical pin 20Upper divider resistor.
GP15 node โ†’ 3.3 kฮฉ โ†’ GNDLower divider resistor; both are required.
GP16, physical pin 21 โ†’ 1 kฮฉ โ†’ passive piezo โ†’ GNDCurrent-limited tone output.

With a 5.0 V echo, the nominal divided voltage is 5 ร— 3.3 / (2.2 + 3.3) = 3.0 V. At 5.25 V it is 3.15 V before resistor tolerance. The divider draws about 0.91 mA at 5 V. Never wire ECHO directly to the Pico. VBUS is not the 3V3 output or the VSYS input.

Load the program

  1. Install the official MicroPython firmware for the original Pico, following Raspberry Pi’s MicroPython guide. Select the matching Pico interpreter in your editor.
  2. Disconnect USB while wiring. Check both divider resistors and the shared ground.
  3. Reconnect USB, save the following program to the Pico as main.py, and run it. The editor’s serial console displays distance and frequency.
  4. Hold a broad, flat object 10โ€“60 cm in front of the two round transducers. Move it slowly closer, then farther away.
  5. Remove the target or aim into open space. An invalid measurement should silence the sounder instead of producing an extreme note.

Full MicroPython program

"""Original Pico / Pico H + HC-SR04 with a 2.2k / 3.3k echo divider."""
def distance_from_pulse(pulse_us):
    if pulse_us < 0:
        return None
    cm = pulse_us * 0.0343 / 2
    return cm if 2 <= cm <= 80 else None

def frequency_for_distance(cm):
    if cm is None or not 2 <= cm <= 80:
        return None
    return round(1800 - (cm - 2) * (1800 - 220) / (80 - 2))

def main():
    from machine import Pin, PWM, time_pulse_us
    import time
    trigger = Pin(14, Pin.OUT, value=0)
    echo = Pin(15, Pin.IN)
    tone = PWM(Pin(16), freq=440, duty_u16=0)
    try:
        while True:
            trigger.off()
            time.sleep_us(2)
            trigger.on()
            time.sleep_us(10)
            trigger.off()
            pulse = time_pulse_us(echo, 1, 30000)
            distance = distance_from_pulse(pulse)
            frequency = frequency_for_distance(distance)
            if frequency is None:
                tone.duty_u16(0)
            else:
                tone.freq(frequency)
                tone.duty_u16(32768)
            print("cm:", distance, "Hz:", frequency)
            time.sleep_ms(70)  # More than 60 ms between trigger pulses.
    finally:
        tone.duty_u16(0)
        tone.deinit()
        trigger.off()

if __name__ == "__main__":
    main()

How the measurement becomes a note

The trigger pulse lasts 10 microseconds. A microsecond is one millionth of a second. We use 343 metres per second as an approximate room-temperature speed of sound, or 0.0343 centimetres per microsecond. The pulse measures the outward and return trip, so distance in centimetres is pulse duration ร— 0.0343 / 2.

A 1,000 ยตs pulse represents about 17.15 cm. Our rule maps 2 cm to 1,800 Hz and 80 cm to 220 Hz; Hz, or hertz, means cycles per second. A 41 cm distance gives 1,010 Hz. This is a linear mapping of distance to frequency, not a musical scale.

PWM means pulse-width modulation: repeatedly switching a digital output on and off. The program uses a 50% duty cycle, meaning equal high and low times, and changes its frequency to change pitch. The piezo element turns those changes into sound.

The measurement has a timeout, a maximum waiting period. A negative timeout result or a distance outside the chosen 2โ€“80 cm playing range becomes silence. The loop waits another 70 ms after a measurement, giving the sensor time before the next burst.

What to change and what to check

Soft fabric, tilted objects and a small hand can produce poor echoes; first test with a flat book. Clone modules differ: if a verified divider and supply still give no reading, check the module’s required trigger-high voltage. Do not โ€œfixโ€ that by sending 5 V into the Pico. A fixed-pitch active buzzer will not follow this frequency mapping.

Challenge: why divide the travel distance by two?

The sound travels from the sensor to the object and back. Omitting the division doubles the reported distance.

Continue with the loaded voltage-divider experiment. References: HC-SR04 timing sheet, MicroPython pulse timing, RP2 pin and PWM reference, and Raspberry Pi MicroPython setup.

๐Ÿ“กBroadcast the signal โ€” amplify the connection.

Leave a Reply

Temu affiliate offers

Find your next electronics project

Explore these do-it-yourself project kits. Check the selected option, included parts and instructions on each offer.

Tricky Circuit may earn a commission if you buy through these Temu affiliate links. These are product ideas; they have not been bench-tested by Tricky Circuit and are not verified lesson parts lists.

Supplier photo of a breadboard, jumper wires and assorted electronic components in a plastic storage case.

Supplier product photo

Try breadboard experiments

Breadboard, wires and assorted parts. Arduino controller board not included.

View kit on Temu

Supplier photo of an assembled blue surface-mount soldering practice board with a circular ring of small lights.

Supplier product photo

Solder a chasing-light board

Surface-mount soldering practice. Battery and battery holder not included.

View kit on Temu

Supplier photo of an assembled two-wheeled line-following car with a blue circuit board, two motors and an empty battery holder.

Supplier product photo

Build a line-following car

Soldering and assembly required. Check battery and track requirements before buying.

View kit on Temu