Sorin Trimbitas
Published © GPL3+

Sound monitoring system

A simple sound monitoring system using a microphone and a small amplifier with LM386.

BeginnerShowcase (no instructions)22,048
Sound monitoring system

Things used in this project

Hardware components

Arduino Mega 2560
Arduino Mega 2560
×1
LM386 microphone amplifier
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

LM386 microphone amplifier

Code

sound_monitoring.ino

Arduino
// Threshold (sound)
int mic_threshold = 500;
// Input pin .. on analog side
int pin_mic = 0;
// Ticks needed to change the state of the system
int ticks_needed = 100;

int mic_value;
int is_on = false;
int ticks = ticks_needed;

void setup()
{
  Serial.begin(9600);
}


void loop()
{
  // Audio value
  mic_value = analogRead(pin_mic);
  // Serial.println(mic_value, DEC);
  
  // Is the read value ok? + did we had X ticks of silence?
  if (mic_value >= mic_threshold && ticks > ticks_needed)
  {
    // System on or off?
    if (is_on == 0)
    {
      is_on = 1;
      // Do ACTION 1
    }
    else
    {
      is_on = 0;
      // Do ACTION 2
    }
    ticks = 1;
  }
  else
  {
    if (ticks > ticks_needed)
    {
      ticks = ticks_needed + 1;
    }
    else
    {
      ticks++;
    }
  }
  delay(10);
}

Credits

Sorin Trimbitas
5 projects • 32 followers
Software developer.
Contact

Comments

Please log in or sign up to comment.