Sensor

๐ŸŽค Sound Sensor

๐Ÿ“Œ Description

A sound sensor detects noise levels in the environment. It converts sound vibrations into an electrical signal that the microcontroller can read. Louder sounds produce higher values, while quieter sounds produce lower values.

๐ŸŽฏ Use

In our projects, the sound sensor is used to:

  • Detect claps or loud noises.
  • Trigger actions when sound reaches a certain level.
  • Make robots interactive by responding to voice or environmental sounds.

๐Ÿ‘‰ Think of the sound sensor as the robotโ€™s ears โ€” it listens and reacts to noise.

Module parameters

Pin name Description
G GND (Power Input Negative)
V VCC (Power Input Cathode)
S Digital signal pins
A Analog signal pins
  • Supply voltage: 3.3V/5V
  • Connection: 2.54mm pin header
  • Installation method: double screw fixing

๐Ÿ–ฅ๏ธ Code Explanation

import machine
import time

adc36 = machine.ADC(machine.Pin(36))    # Sound sensor connected to pin 36
pin25 = machine.Pin(25, machine.Pin.OUT) # LED output

while True:
    if adc36.read() >= 3090:            # If sound level is high
        pin25.value(1)                  # Turn LED ON
        time.sleep_ms(500)              # Keep LED on for 0.5 seconds
    else:
        pin25.value(0)                  # LED OFF

Step by Step

  1. adc36 = machine.ADC(machine.Pin(36)) โ†’ Reads the analog signal from the sound sensor.
  2. pin25 = machine.Pin(25, machine.Pin.OUT) โ†’ Pin 25 controls the LED (output).
  3. while True: โ†’ Loop that repeats forever.
  4. adc36.read() โ†’ Reads the sound intensity (0โ€“4095).
  5. if adc36.read() >= 3090: โ†’ Checks if the sound is loud (threshold set at 3090).
  6. pin25.value(1) โ†’ Turns the LED on when sound is detected.
  7. time.sleep_ms(500) โ†’ Keeps the LED on for half a second.
  8. else: โ†’ If sound is below thresholdโ€ฆ
  9. pin25.value(0) โ†’ Turns the LED off.

๐Ÿ‘‰ Together, this program makes the LED flash when a loud sound is detected.


โœ… Conclusion of the Test

  • If clapping or making a loud noise turns the LED on briefly, the program is working correctly.
  • This test shows how the robot can listen to sounds and react with an output (LED).
  • Later, the sound sensor could be used to trigger motors, alarms, or even start/stop the robot with a clap command.
On this page