Dancing Lights LED Lamp

by jhilyard2130 in Circuits > LEDs

281 Views, 0 Favorites, 0 Comments

Dancing Lights LED Lamp

final product.jpg
Dancing Lights LED Lamp
led wire1.jpg
led wire2.jpg

This is a small project, something cool that you could add to any room in your house. Any performance, party, or study session is better with music and lights, but that equipment can be expensive to buy so here is a way that you can build it yourself step by step for much cheaper and you can feel the satisfaction of knowing that you built this awesome LED Light that dances with the music.

This led light is very bright for its size. It reacts to the sounds going on in the room, whether that be background noise, conversation, or your favorite songs. It does not require any connection to your phone or other music players, and can be used anywhere you can plug it in. With that being said, let's get to building this your very own Dancing Lights LED Lamp!

Supplies

1 Solderless Breadboard

1 330 Ohm Resistor

1 AT MEGA 2560 Arduino Microcontroller

1 USBA to USBB cable (can be purchased with the Arduino)

4 Male to Male Wires(Black Wire above)

3 Male to Female (Yellow Wire above)

1 8x8 LED Matrix

1 DEVMO High Sensitivity Sound Sensor

1 opaque covering on top to protect your eyes from the brightness (Optional) (We used a white trash bag)

Masking or Duct Tape

1 Cardboard Box (for housing)

Assembly of Electronic Components

Wiring Diagram-1.jpg
breadboard wiring.jpg
Matrix Wiring.jpg
sound sensor wiring.jpg
sound sensor wiring 2.jpg

Once project supplies have been acquired it is time to begin assembling the electronic components of the project. For reference, breadboards are organized such that the horizontal rows are connected except for across the middle (as shown in the sample image of the breadboard).

  • Insert male-to-male jumper wire in Digital Port 2.
  • Insert the other end of the jumper into breadboard.
  • Insert 330-ohm resistor into breadboard hole (connected to the jumper).
  • Connect a jumper from the output of the resistor to the data line (DIN) of the LED Matrix.
  • Connect 5V to red wire adjacent to DIN using a male-to-male jumper wire.
  • Connect GND to white wire adjacent to DIN using a male-to-male jumper wire.
  • Connect Red and White wires in the center of the matrix to the terminal block adapter of the power supply.
  • Connect 5V and GND to the 5V and GND pin of the sound sensor using male-to-female jumper wires.
  • Connect analog out (AO) pin of the sound sensor to A0 port of Arduino using a male-to-female jumper wire.

For reference refer to the wiring diagram included in this step.

Coding

  • For ease of use, the working program has been provided. Please download it in an easily located folder.
    • Alternatively, create an Arduino sketch and copy and paste the code from below into the sketch.
  • To download code to the microcontroller download the Arduino IDE here.
  • Once downloaded, open the IDE, locate the previously saved program, and open.
  • Connect USBA-to-USBB cable from Arduino to computer.
  • Select the arrow icon to upload the program to the Arduino.
  • RGB values for the lights are pre-set in the program. If you wish to edit the color locate the lines of code that read: leds[i] = CRGB ( 234, 10, 132);
  • The color is controlled by the three numeric values ranging from 0 to 255.
  • The first number controls the intensity of the red LEDs, the second controls the green LEDs, and the third controls blue.
/*
 File/Sketch Name: Sound_to_Light

 Version No.: v1.0 Created 19 April, 2022
 
 Original Author: Spencer Johnson, Purdue Polytechnic Institute MET

Contains code from: 
	Clyde A Lettsome, PhD, PE, MEM
	File/Sketch Name: AudioFrequncyDetector
	v1.0 Created 12 December, 2019	
 
 Description:  This code/sketch makes displays the approximate frequency of the loudest sound detected by a sound detection module. For this project, the analog output from the 
 sound module detector sends the analog audio signal detected to A0 of the Arduino Mega2560. The analog signal is sampled and quantized (digitized). A Fast Fourier Transform (FFT) is
 then performed on the digitized data. The FFT converts the digital data from the approximate discrete-time domain result. The maximum frequency of the approximate discrete-time
 domain result is then determined and displayed via the Arduino IDE Serial Monitor. The output of the frequency detection is then fed into if statements to determine the frequenccy range 
 in 50 HZ increments from 100 Hz to 1000 Hz. This is used to assign a value between 0 and 17 to be fed into switch case construct to enter a for loop to address all LED's to predetermined
 RGB color values. The program will repeat this program loop indefinetly so loang as it is powered.

 Note: The arduinoFFT.h library needs to be added to the Arduino IDE before compiling and uploading this script/sketch to an Arduino.

 License: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License (GPL) version 3, or any later
 version of your choice, as published by the Free Software Foundation.

 Notes: Copyright (c) 2019 by C. A. Lettsome Services, LLC
 For more information visit <a href="https://clydelettsome.com/blog/2019/12/18/my-weekend-project-audio-frequency-detector-using-an-arduino/" rel="nofollow"> https://clydelettsome.com/blog/2019/12/18/my-week...</a>

*/

#include "arduinoFFT.h"
#include <FastLED.h>

#define LED_PIN     2
#define NUM_LEDS    64
#define SAMPLES 128             //SAMPLES-pt FFT. Must be a base 2 number. Max 128 for Arduino Uno.
#define SAMPLING_FREQUENCY 2048 //Ts = Based on Nyquist, must be 2 times the highest expected frequency.


arduinoFFT FFT = arduinoFFT();
CRGB leds[NUM_LEDS];
 
unsigned int samplingPeriod;
unsigned long microSeconds;
unsigned int num;
 
double vReal[SAMPLES]; //create vector of size SAMPLES to hold real values
double vImag[SAMPLES]; //create vector of size SAMPLES to hold imaginary values
 
void setup() 
{
    Serial.begin(115200); //Baud rate for the Serial Monitor
    samplingPeriod = round(1000000*(1.0/SAMPLING_FREQUENCY)); //Period in microseconds
    FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS); 
}
 
void loop() 
{  
    /*Sample SAMPLES times*/
    for(int i=0; i<SAMPLES; i++)
    {
        microSeconds = micros();    //Returns the number of microseconds since the Arduino board began running the current script. 
     
        vReal[i] = analogRead(0); //Reads the value from analog pin 0 (A0), quantize it and save it as a real term.
        vImag[i] = 0; //Makes imaginary term 0 always

        /*remaining wait time between samples if necessary*/
        while(micros() < (microSeconds + samplingPeriod))
        {
          //do nothing
        }
    }
 
    /*Perform FFT on samples*/
    FFT.Windowing(vReal, SAMPLES, FFT_WIN_TYP_HAMMING, FFT_FORWARD);
    FFT.Compute(vReal, vImag, SAMPLES, FFT_FORWARD);
    FFT.ComplexToMagnitude(vReal, vImag, SAMPLES);

    /*Find peak frequency and print peak*/
    double peak = FFT.MajorPeak(vReal, SAMPLES, SAMPLING_FREQUENCY);
    Serial.println(peak);     //Print out the most dominant frequency.

  if (peak>100 && peak<150){
    num = 0;
  }

  if (peak>150 && peak<200){
    num = 1;
  }

  if (peak>200 && peak<250){
    num = 2;
  }

  if (peak>250 && peak<300){
    num = 3;
  }

  if (peak>300 && peak<350){
    num = 4;
  }

  if (peak>350 && peak<400){
    num = 5;
  }

  if (peak>400 && peak<450){
    num = 6;
  }

  if (peak>450 && peak<500){
    num = 7;
  }

  if (peak>500 && peak<550){
    num = 8;
  }

  if (peak>550 && peak<600){
    num = 9;
  }

  if (peak>600 && peak<650){
    num = 10;
  }

  if (peak>650 && peak<700){
    num = 11;
  }

  if (peak>700 && peak<750){
    num = 12;
  }

  if (peak>750 && peak<800){
    num = 13;
  }

  if (peak>800 && peak<850){
    num = 14;
  }

  if (peak>850 && peak<900){
    num = 15;
  }

  if (peak>900 && peak<950){
    num = 16;
  }

  if (peak>950 && peak<1000){
    num = 17;
  }

  Serial.println(num);

  switch (num){
  case 0:
   for (int i = 0; i <= 64; i++) {
      leds[i] = CRGB ( 0, 0, 255);
      FastLED.show();
      delay(5);
    }
    break;
    
   case 1:
    for (int i = 0; i <= 64; i++) {
      leds[i] = CRGB ( 0, 255, 0);
      FastLED.show();
      delay(5);
    }
    break;

   case 2:
    for (int i = 0; i <= 64; i++) {
      leds[i] = CRGB ( 234, 10, 132);
      FastLED.show();
      delay(5);
    }
    break;
   
   case 3:
    for (int i = 0; i <= 64; i++) {
      leds[i] = CRGB ( 21, 244, 238);
      FastLED.show();
      delay(5);
    }
    break;

   case 4:
    for (int i = 0; i <= 64; i++) {
      leds[i] = CRGB ( 250, 128, 114);
      FastLED.show();
      delay(5);
    }
    break;

   case 5:
    for (int i = 0; i <= 64; i++) {
      leds[i] = CRGB ( 106, 113, 173);
      FastLED.show();
      delay(5);
    }
    break;

   case 6:
    for (int i = 0; i <= 64; i++) {
      leds[i] = CRGB ( 255, 0, 0);
      FastLED.show();
      delay(5);
    }
    break;

   case 7:
    for (int i = 0; i <= 64; i++) {
      leds[i] = CRGB ( 195, 192, 20);
      FastLED.show();
      delay(5);
    }
    break;

   case 8:
    for (int i = 0; i <= 64; i++) {
      leds[i] = CRGB ( 255, 140, 0);
      FastLED.show();
      delay(5);
    }
    break;

   case 9:
    for (int i = 0; i <= 64; i++) {
      leds[i] = CRGB ( 215, 252, 0);
      FastLED.show();
      delay(5);
    }
    break;

   case 10:
    for (int i = 0; i <= 64; i++) {
      leds[i] = CRGB ( 100, 35, 86);
      FastLED.show();
      delay(5);
    }
    break;

   case 11:
    for (int i = 0; i <= 64; i++) {
      leds[i] = CRGB ( 145, 175, 237);
      FastLED.show();
      delay(5);
    }
    break;

   case 12:
    for (int i = 0; i <= 64; i++) {
      leds[i] = CRGB ( 175, 237, 204);
      FastLED.show();
      delay(5);
    }
    break;

   case 13:
    for (int i = 0; i <= 64; i++) {
      leds[i] = CRGB ( 0, 0, 255);
      FastLED.show();
      delay(5);
    }
    break;

   case 14:
    for (int i = 0; i <= 64; i++) {
      leds[i] = CRGB ( 48, 64, 69);
      FastLED.show();
      delay(5);
    }
    break;

   case 15:
    for (int i = 0; i <= 64; i++) {
      leds[i] = CRGB ( 69, 169, 69);
      FastLED.show();
      delay(5);
    }
    break;

   case 16:
    for (int i = 0; i <= 64; i++) {
      leds[i] = CRGB ( 237, 120, 9);
      FastLED.show();
      delay(5);
    }
    break;

   case 17:
    for (int i = 0; i <= 64; i++) {
      leds[i] = CRGB ( 13, 100, 255);
      FastLED.show();
      delay(5);
    }
   break;

   delay(50);
  }
}

Downloads

Assembly of Case

New Housing-1.jpg
Housing Model.png
1B898671-B11E-4CA6-B794-667DD80D22CF.jpeg
  • Case material and design are at your discretion.
  • This project used a cardboard box for the container and a piece of a trash bag for the diffuser.
  • Materials used in the example shown were a cardboard box, masking tape, and a piece of a trash bag.
  • The box was painted white with spray paint.
  • An access hole was cut in the bottom of the box to aid in troubleshooting in the case that a wire came loose.
  • Alternative housing materials include sheet metal, wood, or plastic.
  • IMPORTANT: If using a plastic film taped to the top of the box, ensure to install electronic components and connect any necessary power cables to both the LED Matrix and the microcontroller.
  • Once electronics are installed use a scrap of cardboard to form a shelf for the LED Matrix to sit on and tape this inside the box approximately 2 inches from the top edge.
  • The LED matrix can be taped to this shelf with double-stick tape to keep it in place in the event of a bump or fall.
  • Finally, stretch the plastic film/trashbag over top of the box and secure with tape.

References

C. Lettsome, “My weekend project: Audio frequency detector,” clydelettsome.com, 29-Aug-2020. [Online]. Available: https://clydelettsome.com/blog/2019/12/18/my-weekend-project-audio-frequency-detector-using-an-arduino/. [Accessed: 28-Apr-2022].

Dejan, “How to control WS2812B individually addressable leds using Arduino,” howtomechatronics.com, 17-Feb-2022. [Online]. Available: https://howtomechatronics.com/tutorials/arduino/how-to-control-ws2812b-individually-addressable-leds-using-arduino/. [Accessed: 28-Apr-2022].