diy chen
Published © CC BY-NC

Wireless Charger with a Sound-Sensing Sparkle

Wireless charger with interactive light effects that can change the lighting according to the music to make your desktop more interesting.

BeginnerShowcase (no instructions)9,982
Wireless Charger with a Sound-Sensing Sparkle

Things used in this project

Hardware components

Arduino Pro Mini 328 - 5V/16MHz
SparkFun Arduino Pro Mini 328 - 5V/16MHz
×1
RGB WS2812 Light strip 60led per meter
×1
usb Downloader
×1
wireless charging Module
×1
Microphone Amplifier Breakout
Adafruit Microphone Amplifier Breakout
×1
Enameled wire welding
×1
Resistor 10k ohm
Resistor 10k ohm
×2
Resistor 1M ohm
Resistor 1M ohm
×2
Resistor 330 ohm
Resistor 330 ohm
×1

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

3d print shell -- slt

Schematics

wrielesschanger_led_bb_XO10BvOaUC.jpg

Code

Sensing the sound and changing the light

Arduino
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif

#define PIN            10

#define NUMPIXELS      16


Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int ledlighton = 7;
int colorramdom = 1;
int loopledtop = 0;
int colorR = 0;
int colorG = 0;
int colorB = 0;
int colorchange = 10;
int mic = 0;
float mictop = 10;
int mic_basic = 0;

void setup() {
  // put your setup code here, to run once:
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif

  strip.begin(); // This initializes the NeoPixel library.
  Serial.begin(9600);
 micbasic();
}




void loop() {

musicin2();


}
void musicin2()
{
    mic = analogRead(A3);

 mic = mic-mic_basic;//335
 
//  if (mic < 10)
//  {
//    mic = 0;
//  }


  if (mic < 0)
  {
    mic = ~mic + 1;
  }

    if (mic < 4)
  {
    mic = 0;
  }
  else
  {
    mic = mic-3;
    }
      mic = mic * 2;

    /////////////
  //mic = mic / 10;

  
  if (mic > 0)
  {
    Serial.print(mic);
    Serial.print("|");
    if (mic > 10)
    {
      mic = 8;
    }

    Serial.print(mic);
    Serial.println("");
    /*
    */
    ledlighton = random (0, 16);
    colorramdom =  random (1, 3);
    if (colorramdom == 1)
    {
      colorR = random (101, 255);
      colorG = random (101, 255);
      colorB = 0;
    }
    else if (colorramdom == 2)
    { colorR = random (101, 255);
      colorG = 0;
      colorB = random (101, 255);
    }
    else if (colorramdom == 3)
    { colorR = 0;
      colorG = random (101, 255);
      colorB = random (101, 255);
    }





    // strip.setPixelColor(ledlighton, strip.Color(colorR, colorG, colorB));
    strip.setPixelColor(ledlighton, strip.Color(255, 255, 255));
    // strip.setPixelColor(ledlighton, strip.Color(colorR, colorG, colorB));
    strip.show();
    delay(50);
    if (mic > 2)
    {
      for (int i = 1; i < mic; i++)
      {
        if (colorR - i * colorchange > 0)
        {
          colorR = colorR - i * colorchange ;
        }
        else
        {
          // colorR = colorR + i * colorchange ;
        }
        if (colorG - i * colorchange > 0)
        {
          colorG = colorG - i * colorchange ;
        }
        else
        {

          // colorG = colorG + i * colorchange ;
        }
        if (colorB - i * colorchange > 0)
        {
          colorB = colorB - i * colorchange ;
        }
        else
        {

          //  colorG = colorG + i * colorchange ;
        }
        strip.setPixelColor(ledlighton + i, strip.Color(colorR, colorG, colorB));
        strip.setPixelColor(ledlighton - i, strip.Color(colorR, colorG, colorB));
        strip.show();
        delay(20);
      }


      for (int i = 0; i < mic; i++)
      {
        strip.setPixelColor(ledlighton + i, strip.Color(0, 0, 0));
        strip.setPixelColor(ledlighton - i, strip.Color(0, 0, 0));
        strip.show();

        delay(30);
      }
    }
    strip.setPixelColor(ledlighton, strip.Color(0, 0, 0));
    strip.show();


  }

  }

  
void micbasic()
{

for (int mb = 0; mb <20; mb++)
{
mic_basic = mic_basic+analogRead(A3);
}
mic_basic = mic_basic/20;
}

Credits

diy chen

diy chen

0 projects • 3 followers

Comments