Labs / Bipes + MicroPython / 10 Comprehensive Case

10.10 Infrared Sound-Transmitting Toy

Author: Li Zisheng · Source: FreakStudio open documentation · License: CC BY 4.0

Contents

Young makers, do you want to make a magical "sound transmission through the air" toy🪄? No wires needed — you can send your voice to a distant place via invisible infrared rays, just like playing with a "whisper transmitter"! Today, we’ll use an infrared module and a microphone to create a small infrared sound-transmission toy that lets your voice "fly"~

1. Case Introduction

1.1 Modules Used

1.2 Creative Gameplay

This toy can achieve the magical effect of "wireless sound transmission":

1.3 Core Learning Points (Essential for Beginners to Master)

  1. Learn to transmit and receive infrared signals (understand the principle of "invisible wireless communication");
  2. Master the acquisition and conversion of analog audio signals (the complete link: microphone → electrical signal → infrared → buzzer);
  3. Understand signal threshold judgment (determine whether there is sound input based on the microphone value);
  4. Enable multi-module collaborative operation (the complete process of input → encoding → transmission → decoding → output);
  5. Master the flexible use of advanced interfaces (temporarily use the I2C interface as a DIO port to drive the buzzer).

2. Wiring Instructions

This case requires connecting 4 modules, which can be directly plugged into the standard interfaces of the development board as required.

10.10 Infrared Sound-Transmitting Toy

2.1 Wiring of TSP034138 Infrared Receiving Module

We connect the TSP034138 infrared receiving module to the DIO0 interface of the development board

2.2 Wiring of IR333C Infrared Transmitting Module

We connect the IR333C infrared transmitting module to the DIO1 interface of the development board.

2.3 Wiring of Passive Buzzer Module

We connect the passive buzzer module to the I2C0 interface (temporarily used as a DIO port)

2.4 Microphone Module Wiring

We connect the microphone module to the AIN0 interface of the development board

📌 Wiring Tips

  • The GND of all modules must be connected to the common ground of the development board; otherwise, the signals will jump erratically and the modules will not function properly.
  • The infrared transmitting and receiving modules must be placed in alignment (with no obstruction in between), otherwise signal transmission will fail;
  • Connecting the buzzer to the I2C0 interface is a flexible application of "using a high-level interface as a low-level one", and it is necessary to ensure that the I2C0 interface is not occupied by other devices.

3. Program Description

The core of this case lies in the process of "sound collection → infrared transmission → infrared reception → sound playback". We will break it down according to the sequence of building block assembly, so even beginners can follow along step by step:

10.10 Infrared Sound-Transmitting Toy
  1. Hardware Initialization Block (Pre-step, Critical!)
    • Infrared module initialization: Set DIO0 (reception) to input mode and DIO1 (transmission) to output mode;
    • Microphone initialization: Set AIN0 to analog input mode for reading sound signals;
    • Buzzer Initialization: Set Pin6 of the I2C0 interface to output mode + PWM function to prepare for driving the buzzer to generate sound.
  2. Infinite Loop Block (repeat while true)
    • Function: Continuously collect sound, transmit infrared signals, receive and play audio to realize real-time sound transmission;
    • Location: All function blocks must be placed inside this loop.
  3. Sound Collection and Judgment Block
    • Read the volume: Use the Read RPI Pico ADC Input block to read the analog value of the microphone on AIN0, and store it in the adc variable;
    • Threshold judgment: Use if adc > 100 to determine whether there is sound input (if the volume exceeds 100, it is judged as "sound present");
    • Logic description: The higher the microphone value, the louder the sound, and the threshold can be adjusted according to the ambient noise.
  4. Infrared emission block (within the if branch)
    • Encoding and Transmission: Convert the analog value from the microphone into a PWM signal, and send it to the infrared transmitting module through the DIO1 pin;
    • Logical Description: The infrared module encodes electrical signals into infrared light and transmits it into the air, thus realizing the conversion from "sound to infrared".
  5. Infrared Receiving and Playing Building Block
    • Receive signal: Use the read digital input block to read the infrared received signal from the DIO0 pin;
    • Buzzer Playback: Convert the received signal into a PWM signal, and drive the buzzer to sound via Pin6 of the I2C0 interface;
    • Logic description: The buzzer plays sounds according to the frequency and amplitude of the signal, realizing the restoration from "infrared" to "sound".
  6. Debounce Delay Block
    • Add a delay of 20 milliseconds to prevent frequent triggering caused by ambient noise and ensure more stable sound transmission.

Program running effect:

10.10 Infrared Sound-Transmitting Toy
10.10 Infrared Sound-Transmitting Toy

A Beginner’s Guide to Avoiding Common Pitfalls

  1. Infrared receiver not picking up signal?
    • Check whether the infrared transmitting and receiving modules are aligned, and whether there is any obstruction between them;
    • Adjust the sound threshold (e. g., change "100" to "50") to increase the sensitivity.
  2. Buzzer not sounding / low volume?
    • Check whether the buzzer is connected to the I2C0 interface (Pin6), and whether the PWM frequency is in the range of 1000-3000Hz;
    • Make sure the buzzer is powered by 5V; 3.3V power supply will result in weak sound.
  3. Microphone not picking up any sound?
    • Check whether the wiring of the AIN0 interface (Pin31) is loose and whether the microphone is close to the sound source;
    • Rotate the potentiometer on the microphone module to adjust the gain (turn clockwise to increase the volume).

✨ Interactive Quick Quiz

  1. Think about it: If you block the light between the infrared transmitting and receiving modules with your hand, can the buzzer still play sound? (Answer: No! The infrared signal is an optical signal, which cannot be transmitted after being blocked, and the buzzer will be muted)
  2. Try it out: Add a "volume adjustment" function to the example — use a potentiometer to adjust the microphone's sensitivity for clearer sound transmission. Can you add the potentiometer block to it?

Directly importable building blocks:

Buzzer version infrared sound toy.xml 22 KB