1. Introduction
A sound sensor is used to detect sound levels in the environment. It works using a microphone that converts sound waves into electrical signals. This sensor is commonly used for clap detection and sound-activated systems.
2. Components
- Raspberry Pi
- Sound Sensor Module
- LED
- 220Ω Resistor
- Breadboard
- Jumper Wires
3. Circuit and connections
| Raspberry Pi Pinout Diagram |
| Pinout Diagram of Sound Sensor Module |
Connections:
- VCC → 5V (Pin 2)
- GND → GND (Pin 6)
- DO → GPIO17 (Pin 11)
- LED + → GPIO18 (Pin 12)
- LED – → GND (via 220Ω resistor)
4. Detailed Step By Step Circuit working
- Microphone detects sound waves
- Sound is converted to electrical signal
- Comparator circuit generates digital output
- When sound exceeds threshold → DO becomes LOW
- Raspberry Pi reads signal
- When sound detected → LED turns ON
- When no sound → LED OFF
5. Libraries to be included
import RPi.GPIO as GPIO
import time
6. Code
import RPi.GPIO as GPIO
import time
sound = 17
led = 18
GPIO.setmode(GPIO.BCM)
GPIO.setup(sound, GPIO.IN)
GPIO.setup(led, GPIO.OUT)
while True:
if GPIO.input(sound) == 0: # Sound detected
GPIO.output(led, True)
print("Sound Detected")
else:
GPIO.output(led, False)
time.sleep(0.1)
7. Detailed Step By Step Code working
- Import GPIO and time libraries
- Assign sound sensor to GPIO17
- Assign LED to GPIO18
- Set GPIO mode to BCM
- Set sensor as input
- Set LED as output
- Read sensor value
- If LOW → sound detected → LED ON
- Else → LED OFF
- Add delay for stability
8. Tips
- Adjust sensitivity using onboard potentiometer
- Avoid noisy environments for testing
- Place sensor close to sound source
- Use proper shielding for stable readings
9. Uses
- Clap switch systems
- Sound-activated lights
- Noise monitoring
- Security alarms
10. Conclusion
The sound sensor is a simple and effective module for detecting sound events. This project helps in building interactive and automation systems using Raspberry Pi.