ELEGOO MEGA · LESSON 20
Sound Sensor Module
Print the microphone module’s analog samples while L follows its digital threshold output.
Distinguish an analog signal from a comparator threshold output.
Parts List
- ELEGOO Mega 2560 R3 is a 5 V ATmega2560 AVR board with many I/O pins and four hardware UARTs for control systems with several peripherals. Long ELEGOO-branded Mega PCB with USB-B and barrel connector, ATmega2560 marking, extended side headers and a large double-row digital header at the end. Read printed Mega labels; its SPI hardware placement is not the same numeric pins as an Uno.
- A USB-A to USB-B cable carries USB power and, when its data conductors are present, a host/device data link. USB-A plug and square USB-B plug. Inspect the plug shape; micro-USB is not USB-C, and USB-B is the squarer device connector.
- A microphone carrier converts sound pressure into an electrical signal for sound-event experiments. Look for a small metal microphone capsule, often a trimmer and analog/digital output labels.
- Male-to-female jumper leads make removable point-to-point connections for low-current prototype signals. Pin at one end and socket at the other. Check intact insulation and snug contacts before use.
Assembly
- Disconnect USB and identify all four module labels.
- Reconnect, open Monitor at 9600 baud and adjust the trimmer near the quiet-room switching point.
- Make a nearby sound and compare the printed samples with L.

Source-reviewed wiring. Hardware not bench-tested; firmware uploads have not been performed.
Code
PlatformIO configuration
[env:mega]
platform = atmelavr@5.3.0
board = megaatmega2560
framework = arduino
monitor_speed = 9600
Open PlatformIO Monitor at 9600 baud after Upload. Close Monitor before another Upload if the port is busy.
#include <Arduino.h>
const uint8_t ANALOG_PIN = A0;
const uint8_t DIGITAL_PIN = 3;
const uint8_t LED_PIN = 13;
void setup() {
Serial.begin(9600);
pinMode(DIGITAL_PIN, INPUT);
pinMode(LED_PIN, OUTPUT);
}
void loop() {
// AO is an instantaneous voltage sample, not loudness in decibels or recorded audio.
const int analogValue = analogRead(ANALOG_PIN);
// DO is the comparator's threshold output; the trimmer controls that threshold.
const int digitalValue = digitalRead(DIGITAL_PIN);
Serial.println(analogValue);
// Preserve the supplied HIGH-following behavior; some modules trigger LOW instead.
if (digitalValue == HIGH) digitalWrite(LED_PIN, HIGH);
else digitalWrite(LED_PIN, LOW);
delay(50); // About 20 printed samples/s, far too slow to reconstruct ordinary audio.
}
Source: SOURCE_RECONCILED. Compile: COMPILE_VERIFIED. Hardware: NOT_TESTED. Upload: NOT_PERFORMED.
Expected behavior
AO values print about every 50 ms; L directly follows DO HIGH. A module with an active-LOW sound event may turn L off at the event. These values are neither decibels nor an audio recording.
Experiments & Challenges
- Turn the threshold trimmer and compare DO/L behavior while AO still prints.
Troubleshooting
- If nothing changes, verify AO/DO are not swapped and try several trimmer rotations near the switching point.