Heart beating animation on 16x16 LED matrix with sound sensor

Hi there, here another newbe.
Can someone please help me with my project?
Two weeks ago I had an idea about a beating LED heart to the beat of the music.
But I couldn't find anything so decided to make it myself. So I googled and bought an Arduino starter kit, but now I'm stuck.

I've now got the matrix working, managed to animate a heart and I can also sort of set the brightness with a potentiometer.

However, I can't manage to code the sound sensor to move to the beat.
And I have not yet figured out which portable power supply I need in combination with which circuit (enough power supply 256 LEDs but not too much for Arduino nano). I've allready blew up a 16x16 LED matrix :grimacing:

Is there someone who can help me with this?

Rgds, Cris

hereby the code:

/* Arduino 256 RGB LEDs Matrix Animation Frame 
 * Using WS2812 LED Strips
 
Created by Yvan / https://Brainy-Bits.com

This code is in the public domain...

You can: copy it, use it, modify it, share it or just plain ignore it!
Thx!

*/

#include <avr/pgmspace.h>  // Needed to store stuff in Flash using PROGMEM
#include "FastLED.h"       // Fastled library to control the LEDs

// How many leds are connected?
#define NUM_LEDS 256

// Define the Data Pin
#define DATA_PIN 3  // Connected to the data pin of the first LED strip

// Define the array of leds
CRGB leds[NUM_LEDS];


#define MAX_BRIGHTNESS 164      // Thats full on, watch the power!
#define MIN_BRIGHTNESS 10       // set to a minimum of 25%

const int brightnessInPin = A0;  // The Analog input pin that the brightness control potentiometer is attached to.

int micPin = A1;
int sensorValue = 0;


// Create the array of retro arcade characters and store it in Flash memory
const long HeartBeat01[] PROGMEM =
{
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000,  
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000
};

const long HeartBeat02[] PROGMEM =
{
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000,  
0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 
0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 
0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 
0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000
};

const long HeartBeat03[] PROGMEM =
{
0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000,  
0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 
0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 
0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 
0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 
0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 
0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 
0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 
0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff0000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 
0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff0000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000, 0xff000000
};




void setup() { 


Serial.begin (9600);


FastLED.addLeds<NEOPIXEL,DATA_PIN>(leds, NUM_LEDS);  // Init of the Fastled library
FastLED.setBrightness(MAX_BRIGHTNESS);
}

void loop() { 
 // read the analog brightness value:
  //int brightValue = analogRead(brightnessInPin);            
  // map it to the range of the FastLED brightness:
  int mappedValue = map(analogRead(brightnessInPin), 0, 1023, 0, 255);

FastLED.setBrightness(constrain(mappedValue, MIN_BRIGHTNESS, MAX_BRIGHTNESS));

sensorValue = analogRead (micPin);
Serial.println (sensorValue, DEC);
delay (1000);


// Put HeartBeat01 delay750
for(int passtime = 0; passtime < 1; passtime++) { // Display it 1 time

FastLED.clear();
for(int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(HeartBeat01[i]));  // Read array from Flash
  }

FastLED.show();
delay(750);


// Put HeartBeat02 delay 50
FastLED.clear();
for(int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(HeartBeat02[i]));
  }

FastLED.show();
delay(25);


// Put HeartBeat03 delay 50
FastLED.clear();
for(int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(HeartBeat03[i]));
  }

FastLED.show();
delay(25);


// Put HeartBeat02 delay 50
FastLED.clear();
for(int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(HeartBeat02[i]));  // Read array from Flash
  }

FastLED.show();
delay(25);


// Put HeartBeat01 delay 133
FastLED.clear();
for(int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(HeartBeat01[i]));
  }

FastLED.show();
delay(67);


// Put HeartBeat02 delay 60
FastLED.clear();
for(int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(HeartBeat02[i]));
  }

FastLED.show();
delay(25);


// Put HeartBeat03 delay 50
FastLED.clear();
for(int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(HeartBeat03[i]));
  }

FastLED.show();
delay(25);


// Put HeartBeat02 delay 50
FastLED.clear();
for(int i = 0; i < NUM_LEDS; i++) {
    leds[i] = pgm_read_dword(&(HeartBeat02[i]));  // Read array from Flash
  }

FastLED.show();
delay(25);



}


}


Welcome to the forum.

That is a nice project.
Do you know what is also nice ? Your project in a simulation:

The microphone (your microphone module) is not a sound pressure meter, it gives the audio signal. You would need to sample that signal with a few kHz and then do a FFT analysis and then maybe you can find the beat.
But perhaps others know a simpler way.

The FastLED library has a function to limit the current.
Have you measured how much current you need. With all the leds off, you already need 250 mA. I'm thinking about a car battery and a DC/DC-converter.

The problem with the sim code you (both) reference is it does not actually do anything with the sound sensor it only fakes it with delays.

Your sensor outputs an analog signal which (sort of) corresponds to sound intensity, as well as a digital signal from the onboard LM393 comparator that is HIGH when sound intensity exceeds a threshold, and is LOW when the sound intensity is below a threshold.

As a first attempt you can try to use the digital output, and adjust the threshold by adjusting the blue trimpot on the board. This will turn the output on or off based on intensity which is not the same as "beat" but might be OK for what you are doing. To get something closer to beat you could start with a low pass filter on an analog signal to get something closer to the bass beat but I'm not gonna go into that - do some research on low pass filters, they are simple enough.

Here is a basic outline of the code to light up the LEDs based on the sound sensor digital output. You will have to merge in your LED matrix code.

int  sensorDigitalPin = 3;    // Connect Sound sensor digital out D0 to MCU Pin 3
int  sensorDigitalValue;      // Variable to store the digital value (HIGH or LOW) from the Sound Sensor


void setup()
{
  Serial.begin(9600);               
  pinMode(sensorDigitalPin,INPUT);  // Define pin 3 input, to accept digital input
}

void loop(){
 
  sensorDigitalValue=digitalRead(sensorDigitalPin); // Read the value of the sensor
  Serial.println(sensorDigitalValue); // Send the value to the serial monitor just for test purposes
  
  if(sensorDigitalValue==HIGH)      // If the sensor reads HIGH turn on heart LED
  {
    //Light up heart
  }
  else
  {
    //Turn off heart
  }
  
  delay(20);                  // Slight pause between reads
}

thanx! It's working. Even with 2 differents shows under a button (-:

Wow Koepel, the simulation tool is genius!! thanx a lot

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.