Sound and Vibration Sensing

0% Complete
Microphones

Microphones convert sound waves into electrical signals. Different types of microphones use various principles to achieve this conversion.

Microphone Types
  • Dynamic microphones
  • Condenser microphones
  • MEMS microphones
  • Piezoelectric microphones
  • Electret microphones
Sound Detection
// Sound level detection
const int micPin = A0;
const int sampleWindow = 50;
unsigned int sample;

float getSoundLevel() {
  unsigned long startMillis = millis();
  unsigned int signalMax = 0;
  unsigned int signalMin = 1024;

  while (millis() - startMillis < sampleWindow) {
    sample = analogRead(micPin);
    if (sample < 1024) {
      if (sample > signalMax) {
        signalMax = sample;
      }
      if (sample < signalMin) {
        signalMin = sample;
      }
    }
  }
  
  return signalMax - signalMin;
}
Acoustic