Circuit Documentation
Summary
This circuit consists of a KY-038 sound sensor module, an Arduino UNO microcontroller, and a red LED. The purpose of the circuit is to detect loud noises using the KY-038 sound sensor and then light up the LED for a short duration when a loud noise is detected.
Component List
KY-038 Sound Sensor Module
- Pins: +, G, A0, D0
- Description: The KY-038 is a sound sensor module that detects sound levels and outputs a digital signal when a certain threshold is reached.
Arduino UNO
- Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
- Description: The Arduino UNO is a microcontroller board based on the ATmega328P. It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button.
LED: Two Pin (red)
- Pins: cathode, anode
- Description: A standard red LED with two pins: anode (positive) and cathode (negative).
Wiring Details
KY-038 Sound Sensor Module
- + pin connected to 5V pin on Arduino UNO
- G pin connected to GND pin on Arduino UNO
- D0 pin connected to D2 pin on Arduino UNO
Arduino UNO
- 5V pin connected to + pin on KY-038 Sound Sensor Module
- GND pin connected to G pin on KY-038 Sound Sensor Module
- D2 pin connected to D0 pin on KY-038 Sound Sensor Module
- GND pin connected to cathode pin on LED
- D13 pin connected to anode pin on LED
LED: Two Pin (red)
- cathode pin connected to GND pin on Arduino UNO
- anode pin connected to D13 pin on Arduino UNO
Code Documentation
Code for Arduino UNO
int sensor = 2; // Connected to digital output of KY-038 sound sensor module
int pwr = 13; // Connected to positive of LED
boolean is_on = false; // To determine/track if LED is on or off
void setup() {
pinMode(sensor, INPUT); // Setting the pin to input for reading data
pinMode(pwr, OUTPUT); // Setting the pin to output for turning the LED on/off
}
void loop() {
int data = digitalRead(sensor); // Reading data from sensor and storing in variable
if (data == 1) { // 1 is sent from sensor when loud noise is detected
digitalWrite(pwr, HIGH);
delay(500);
digitalWrite(pwr, LOW);
}
}
This code initializes the sensor pin (D2) as an input and the LED pin (D13) as an output. In the main loop, it reads the digital signal from the KY-038 sound sensor. If a loud noise is detected (indicated by a digital high signal), the LED is turned on for 500 milliseconds and then turned off.
