ShreyanR
Published © GPL3+

LED Sound Visualizer

Use the Sparkfun Sound Detector to create an LED soundbar.

IntermediateFull instructions provided2,124
LED Sound Visualizer

Things used in this project

Hardware components

Arduino Mega 2560
Arduino Mega 2560
I used an Arduino Mega, but any other Arduino Board is fine.
×1
SparkFun Sound Detector (with Headers)
SparkFun Sound Detector (with Headers)
Sparkfun Sound Detector.
×1
5 mm LED: Red
5 mm LED: Red
Red LED
×1
LED, Blue
LED, Blue
Blue LED
×1
5 mm LED: Yellow
5 mm LED: Yellow
Yellow LED
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
The Basic Arduino IDE.
Arduino Web Editor
Arduino Web Editor
A web-based alternative to Arduino IDE.

Story

Read more

Schematics

Sound Detector Hookup

LED hookup

Code

LEDSoundVisualizer.ino

C/C++
Method of using Sound Detector by Sparkfun. Copy and paste into Arduino IDE.
//Use Sparkfun's Sound Detector Guide to Create a Sound Visualizer

// Define the Pin connections
#define PIN_GATE_IN 2
#define IRQ_GATE_IN  0
#define PIN_LED_OUT 13
#define PIN_ANALOG_IN A0

void soundISR()
{
  int pin_val;

  pin_val = digitalRead(PIN_GATE_IN); 
  digitalWrite(PIN_LED_OUT, pin_val);
}

void setup()
{
  Serial.begin(9600); //Starts Newline Baud Connection

  pinMode(PIN_LED_OUT, OUTPUT); //Setting builtin LED for the SOUND detector as OUTPUT

  pinMode(PIN_GATE_IN, INPUT); //Setting the Gate Pin as input
  attachInterrupt(IRQ_GATE_IN, soundISR, CHANGE);

//Set LED Pins as OUTPUT
  pinMode(5, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(3, OUTPUT);
}

void loop()
{
//Sets the LEDs to OFF
  digitalWrite(5, LOW);
  digitalWrite(4, LOW);
  digitalWrite(3, LOW);
  
  int value;

  value = analogRead(PIN_ANALOG_IN);

  Serial.println("Volume Value: ");

  if ((value>=10) && (value <=20))
  {
    digitalWrite(5, HIGH);
    Serial.print(value);
    Serial.println("LOW VOLUME");
  }
  else if ( (value > 20) && (value <= 30) )
  {
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    Serial.print(value);
    Serial.println("MEDIUM VOLUME");
  }
  else if (value > 30)
  {
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);
    digitalWrite(5, HIGH);
    Serial.print(value);
    Serial.println("HIGH VOLUME");
  }

  else {
    Serial.println("LITTLE/NO VOLUME DETECTED");
  }

  
  delay(1000);
}

Credits

ShreyanR

ShreyanR

0 projects • 6 followers

Comments