Week 09 Input devices

This week's assignment is about Input Devices. Since my PCB fabrication is not yet completed, I am using an Arduino UNO to complete this week's work.

Learning Objectives

1 Introduction

๐Ÿ’ก1.1 Sound Sensor

A sound sensor is a component that receives sound waves and converts them into electrical signals. It works like a microphone to detect the sound intensity in the surrounding environment. It has various applications, such as noise monitoring, voice control, and security alarms.

1 1

Component

1

๐Ÿ“œSound Sensor Pins

1
Pin Function
A0 Analog Output (Range 0~1023)
VCC Power Input (5V)
G Ground
1

๐Ÿ’ก1.2 Buzzer

A buzzer is an audio signaling device that can be controlled by electrical signals to produce sounds of different frequencies and intensities. It is commonly used for alarms, notifications, and sound feedback applications.

1 1

๐Ÿ“œPassive Buzzer Pins

Pin Function
VCC Power Inpuy (5V)
I\O Connected to D9 via tone() control
GND Ground

๐Ÿ“œActive Buzzer & Passive Buzzer

Feature Active Buzzer Passive Buzzer
Internal Oscillator โœ… Built-in Oscillator โŒ Requires PWM
Control Method Simply turn on/off with HIGH/LOW signal Requires PWM signal for sound generation. Requires tone()
Sound Types Fixed frequency Can produce multiple tones and melodies
Sound Modulation โŒ Fixed Frequency โœ… Can Play Melodies
Wiring Directly Connect to Arduino Requires PWM Control
Common Uses Alarms, simple notifications Music tones, sound effects

๐Ÿ› 2 Component Introduction

2.1 Main Hardware

Component Function
Arduino UNO Controls the entire system
Sound Sensor Detects sound intensity in the environment
Passive Buzzer Generates alarm sounds
Jumper Wires Connects components
Breadboard Used for circuit assembly

3 Circuit Connections

3.1 Connecting the Sound Sensor

Sound Sensor Arduino
A0 A0
VCC 5V
G GND
1

3.2 Connecting the Passive Buzzer

Passive Buzzer Arduino
VCC 5V
I/O D9
GND GND
1

4 Arduino Code

1

#define SOUND_SENSOR_AO A0
#define BUZZER_PIN 9

int threshold = 600;

void setup() {
    pinMode(BUZZER_PIN, OUTPUT);
    Serial.begin(9600);
}

void loop() {
    int soundLevel = analogRead(SOUND_SENSOR_AO);
    Serial.print("Sound Intensity: ");
    Serial.println(soundLevel);
    delay(10);
    if (soundLevel > threshold) {
        tone(BUZZER_PIN, 3000);
    } else {
        noTone(BUZZER_PIN);
    }
    delay(100);
}
    

5 Compilation & Testing

Upload the code and test it by monitoring sound intensity in the Serial Monitor.

1 1

๐Ÿ” Buzzer signal is unstable

Issue Cause Solution
Buzzer keeps beeping Threshold too low or sensor too sensitive Adjust threshold (e.g., set to 400)
No sound from buzzer Sound level below threshold Increase sound source or lower threshold
Unstable sensor values Connection issue or noise interference Check wiring and minimize interference

โš™๏ธBuzzer Keeps Beeping

Issue Possible Cause Solution
Buzzing too frequently Sound sensor threshold too low Increase the threshold value in the code.
Incorrect buzzer type usage Using passive buzzer with digitalWrite(HIGH) Use tone(BUZZER_PIN, frequency) for passive buzzers.
Incorrect wiring Incorrect VCC or GND connection Verify the buzzerโ€™s VCC and GND connections to Arduino.
Unstable sensor values Connection issue or noise interference Check wiring and minimize interference

6 Conclusion

This project demonstrates a sound-based alarm system. When sound intensity exceeds a set threshold, the buzzer activates. Adjusting the threshold and frequency can optimize performance for noise monitoring and smart classroom applications.

Code01 for this week

Upload and Run Arduino Program

Step-by-Step Guide:

  1. ๐Ÿ”Œ Connect the Arduino Board: Use a USB cable to connect the Arduino to computer.
  2. ๐Ÿ–ฅ Open Arduino IDEArduino official website.
  3. โš™๏ธ Select Board & Port:
    • Go to Tools โ†’ Board and select your Arduino Uno.
    • Go to Tools โ†’ Port and select the correct port COM5.
  4. ๐Ÿ“‹ Code: Open the code.
  5. โœ… Compile & Upload Code:
    • Click the โœ”๏ธ (checkmark icon) to verify the code.
    • Click the โฌ†๏ธ (upload icon) to upload the code.
  6. ๐Ÿ“Ÿ Open Serial Monitor:
    • Go to Tools โ†’ Serial Monitor .(shift+alt+M)
    • Set baud rate to 9600.
    • Check code