Sound Reactive (VU) Colour Changing Mason Jar Lamp

by TechMartian in Circuits > Arduino

2218 Views, 22 Favorites, 0 Comments

Sound Reactive (VU) Colour Changing Mason Jar Lamp

VU LED Lamp
IMG_2504.jpg

This is a simple yet elegant looking colour-changing frosted mason jar lamp that changes colour based on the surrounding music. The frostings on the mason jar diffuses the light from the RGB LED making it look very uniform and beautiful especially in the dark.

Clean

IMG_20170827_131955.jpg
IMG_20170827_133201.jpg
IMG_20170827_141613.jpg

Run a stream of hot water over the adhesive for about 3 to 5 minutes. The sticker should peel off very easily. The, scrub off the excess adhesive and let it dry on a piece of clothe.

Spray

IMG_2406.jpg
IMG_2404.jpg

Lightly and evenly coat it with 3 layers of frosted spray paint. I have a more comprehensive guide on how to frost mason jars in this Instructable: https://www.instructables.com/id/How-to-Make-an-E...

Solder

IMG_2554.jpg
IMG_2552.jpg

Solder the resistor onto the anode of the LED so it is more convenient to wire up. This also allows this project to go breadboard-less.

Wiring

IMG_2507.jpg
IMG_2515.jpg
IMG_2510.jpg
IMG_2509.jpg

* Connect the ground pin of the RGB LED (the longest one) to the GND pin on the Arduino

* Connect the red LED pin of the RGB LED (the one at the edge right next to the longest one) to pin 5 on the Arduino.

* Connect the green LED pin of the RGB LED (the one at the centre next to the longest one) to pin 6 on the Arduino.

* Connect the blue LED of the RGB LED (the last one by process of elimination) to pin 9 on the Arduino.

Note that these pins numbers are very important as these are the PWM pins of the Arduino which is the only way we can control the individual brightness of each of these LEDs thus being able to light every colour in the visible spectrum.

Sound Detector

* Connect the VCC pin to 3.3V on the Arduino

* Connect the GND pin to the GND pin on the Arduino

* Connect the Envelope Pin to pin A0 on the Arduino.

Code

Screen Shot 2017-08-29 at 12.13.28 AM.png
Screen Shot 2017-08-29 at 12.13.30 AM.png
//pin variables
const int redPin = 5;
const int greenPin = 6;
const int bluePin = 9;
const int soundPin = 0;
//variables for storing raw sound and scaled value
int sound;
int scale;
void setup()
{
 //start the serial port a@ 9600bps
 Serial.begin(9600);
 //set RGB pins to OUTPUT
 pinMode(redPin, OUTPUT);
 pinMode(greenPin, OUTPUT);
 pinMode(bluePin, OUTPUT);
}
void loop()
{
 //read and store the audio from Envelope pin
 sound = analogRead(soundPin);
 //map sound which in a quiet room a clap is 300
 //from 0 to 3 to be used with switch case
 scale = map(sound, 0, 300, 0, 3);
 //print values over the serial port for debugging
 Serial.print(sound);
 Serial.print("   ");
 Serial.println(scale);
 //switch case on scaled value
switch (scale)
{
//if 0 RGB = Blue
case 0:
   digitalWrite(redPin, LOW);
  digitalWrite(greenPin, LOW);
  digitalWrite(bluePin, HIGH);
  break;
//if 1 RGB = Green  
case 1:
  digitalWrite(redPin, LOW);
  digitalWrite(greenPin, HIGH);
  digitalWrite(bluePin, LOW);
  break;
//if 2 RGB = Yellow  
case 2:
  digitalWrite(redPin, HIGH);
  digitalWrite(greenPin, HIGH);
  digitalWrite(bluePin, LOW);
  break;
//if 3 RGB = Red
case 3:
  digitalWrite(redPin, HIGH);
  digitalWrite(greenPin, LOW);
  digitalWrite(bluePin, LOW);
  break;
//default off
default:
  digitalWrite(redPin, LOW);
  digitalWrite(greenPin, LOW);
  digitalWrite(bluePin, LOW); 
  break;
 }
}

Enjoy!

IMG_2506.jpg
IMG_2502.jpg

Enjoy your pretty little sound reactive lamp!