Sound sensor on A0 and pin 3, on an Arduino Uno
A sound sensor module with its analog output on A0 and its digital output on pin 3: the level is printed, and the Uno’s LED on pin 13 lights while the sound is over the threshold. The whole build, an Arduino Uno and 1 more part, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.
Teaching? Assign it to your class in one click.
Beginner Runs in your browser. Free, and no account needed.
The code
The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.
// Sound sensor module: how loud, and is it over the line?
//
// module AO -> A0 module DO -> pin 3 VCC -> 5V GND -> GND
// the Uno's own LED on pin 13 shows the digital output
//
// The module has a microphone and two outputs. AO is the microphone's level,
// amplified, for analogRead(). DO is a comparator: it goes HIGH when the level
// passes the threshold set by the little screw on the module, and LOW again
// when it falls back.
//
// Drag the sound level on the module to make some noise.
const int ANALOG_PIN = A0;
const int DIGITAL_PIN = 3;
const int LED = 13;
void setup() {
pinMode(DIGITAL_PIN, INPUT);
pinMode(LED, OUTPUT);
Serial.begin(9600);
Serial.println("Mokxi Uno: sound sensor on A0 and pin 3");
}
void loop() {
int level = analogRead(ANALOG_PIN);
bool loud = digitalRead(DIGITAL_PIN) == HIGH;
digitalWrite(LED, loud ? HIGH : LOW);
Serial.print("level ");
Serial.print(level);
Serial.println(loud ? " loud" : "");
delay(200);
}
Parts list
3 parts, plus the jumper wires. Every one is in the editor's parts bin.
How it is wired
4 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.
- Arduino Uno R3 pin 3; Sound sensor, KY-038 pin DO
- Arduino Uno R3 pin 5V; Sound sensor, KY-038 pin VCC
- Ground: Arduino Uno R3 pin GND; Sound sensor, KY-038 pin GND
- Arduino Uno R3 pin A0; Sound sensor, KY-038 pin AO
Change it and keep it
Open it in the editor, change the circuit or the code, and keep your version in a free account.