Home

How to Use the Grove Sound Sensor

This is an analog sensor, and will need to be connected to one of the analog input sockets (A0 to A6) on the Grove Shield for Nano or Uno. The following code fragment illustrates how to do something (turn on the LED in this example) whenever a loud enough noise is detected. A threshold value of 512 is about right to detect conversational voice levels. You can vary it from 0 (most sensitive: the LED will be on virtually all the time) to 1023 (least sensitive: the LED will flash only on the loudest of noises).

void loop()
{
  if (analogRead(A0) > 512)
  {
    digitalWrite(LED_BUILTIN, true);
    delay(500);
    digitalWrite(LED_BUILTIN, false);
  }
}

Home


Questions or comments to phil@munts.net