Neopixel Christmas Lights dancing to music with MSGEQ7 Spectrum Shield

Make your holiday lights dance to music!

NeopixelChristmasLightsThis uses a 300 LED Adafruit Neopixel strip driven by Sparkfun Spectrum Shield (make sure you buy the stackable headers with this) and Arduino Uno. The connections are fairly simple as shown in this pic. Apart from the ground and 5v you just need to connect one data pin to the Neopixel strip to control it (refer to Adafruit Neopixel Guide). There are two standard 1/8″ audio jacks on the Shield that you can connect input audio and pass through the other to your speaker.

The code was adapted from http://michaelteeuw.nl/post/84599343577/micro-disco. (Thanks Michael!).



#include <Adafruit_NeoPixel.h> // include the Adfruit Neopixel library
 
#define PIN_NEOPIXELS 8 // connect Neopixel strip to this pin
#define PIN_STROBE 4 // spectrum shield strobe pin
#define PIN_RESET 5 // spectrum shield reset pin
#define PIN_SOUND 1 //analog input pin spectrum shield - using only one/right channel
#define NUMLEDS 300 // LEDs in Neopixel strip
 
#define MINPOWER 128 // minimum amplitude value to be considered
#define MAXPOWER 1023 // max amplitude value
 
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMLEDS, PIN_NEOPIXELS, NEO_GRB + NEO_KHZ800);
 
int soundvalue[7]; //band array to store amplitutde value for each band
 
void setup() 
{
 strip.begin(); //initialize neopixels
 strip.setBrightness(35);
 strip.show();
 //initialize spectrum shield graphic equalizer
 pinMode(PIN_RESET, OUTPUT); // reset
 pinMode(PIN_STROBE, OUTPUT); // strobe
 digitalWrite(PIN_RESET,LOW); // reset low
 digitalWrite(PIN_STROBE,HIGH); //pin 5 is RESET on the shield
}
 
void loop() {

 readMSGEQ7();
 int bColor = colorValue((soundvalue[0]+soundvalue[1])/2);
 int gColor = colorValue((soundvalue[2]+soundvalue[3]+soundvalue[4])/3);
 int rColor = colorValue((soundvalue[5]+soundvalue[6])/2);
 byte red = rColor; //convert to 0-255 byte value for Neopixel
 byte blue = bColor;
 byte green = gColor;
 
 for (int i = 0; i < NUMLEDS; i=i++) //show strip
 {
 if(i<=240) {strip.setPixelColor(i, (i<=rColor) ? red : 0,(i<=gColor) ? green : 0,(i<=bColor) ? blue : 0);}
 else {strip.setPixelColor(i, (i<=rColor) ? 255 : 0,(i<=gColor) ? 255 : 0,(i<=bColor) ? 255 : 0);} 
 } //you might have to play with this based on your setup. The if statement is to make the top LEDs show brighter
 strip.show();
 delay(5);
}
 
int colorValue(int powerValue) // calculate a a RGB color value from the sound bands
{
 return map(powerValue, MINPOWER, MAXPOWER, 0, NUMLEDS);
}
 
// Read the Analog sound data from 7 bands
void readMSGEQ7()
{
 digitalWrite(PIN_RESET, HIGH); //reset the data
 digitalWrite(PIN_RESET, LOW);
 for(int band=0; band < 7; band++) { //loop thru all 7 bands
 digitalWrite(PIN_STROBE,LOW); // go to the next band 
 delayMicroseconds(10); //gather some data
 soundvalue[band] = analogRead(PIN_SOUND); // store left band reading
 digitalWrite(PIN_STROBE,HIGH); // reset the strobe pin
 }
}
Advertisements

Real-time goal alert – littleBits cloudBit, IFTTT, Arduino

littleBits just launched their cloudBit product. This is Omkar’s first true IoT project that takes data from the cloud to activate something local. In this case, taking goal alerts from a twitter feed to light up LEDs whenever a goal is scored. littleBits cloudBit is truly the easiest way for anyone to make a internet of things project.

The cloudBit works with IFTTT (If This Then That), a cloud service for making ‘Recipes’ to trigger actions based on events. Essentially, you create a Recipe on IFTTT using the the littleBits ‘Channel’ and you have a means to send a signal to the cloudBit based on an event defined in the Recipe.

We had to do a bit of a hack to make this work in real-time as soon as a goal is scored. Most IFTTT recipes don’t trigger in real-time (it usually triggers in 15 minute cycles) except a few. One of the real-time ones is the Email recipe. So for this project we used a work around in order to trigger cloudBit via the Email recipe on IFTTT as illustrated in the video below.

This could be done more simply by writing a web app as well. However, for this project we’ve tried to make it work without any web coding. Some Arduino programming is used to show a more meaningful alert on the device with sounds (though it is not essential to do any coding to make something similar).

Notes and acknowledgements:

  • Thanks to littleBits for choosing us for a early Beta trial of the cloudBit. This project was done during the Worldcup. But we couldn’t publish it before the launch of the cloudBit product.
  • Thanks to  Andy Jiang who created a twitter feed of Worldcup goal alerts that we were able to use as data feed for this project.
  • The goals and alerts shown in the videos are live alerts recording during live game broadcasts.
  • The first video shows a version of this project with the Adafruit Neopixel strip.
  • The project details are available on the littleBits project page.

Interactive Neopixel Lamp (INL). LED Neopixel + Arduino Uno + Ultrasonic Ping Sensor

An interactive lamp that changes speed based on distance of objects in front of it. This uses the Arduino UNO a 60 LED Adafruit NeoPixel strip and an Ultrasonic Ping Sensor.

This also introduces the concept of functions in programming. The circuit is fairly straight forward as Om has tried to illustrate in this diagram! 🙂

Neopixel INL

Refer to Adafruit’s Neopixel Überguide and the Arduino Ping Sensor examples for detailed how to’s. (Note the ping sensor we used has a two separate pins for input and output rather than just one shown in the Arduino example.).

Here is the code.

#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, 2);

int delaytime=30;
const int pingPin = 7;
const int echoPin = 8;

void setup() {
 strip.begin();
 strip.show();
 pinMode(pingPin, OUTPUT);
 pinMode(echoPin, INPUT);
}

void loop() {

 delaytime=pingyity();
 for(int i=0; i<60; i++){
 strip.setPixelColor(i, 255, 0, 0);
 strip.show();
 delay(delaytime);}

 delaytime=pingyity();
 for(int i=0; i<60; i++){
 strip.setPixelColor(i, 255, 255, 0);
 strip.show();
 delay(delaytime);}

 delaytime=pingyity();
 for(int i=0; i<60; i++){
 strip.setPixelColor(i, 0, 255, 255);
 strip.show();
 delay(delaytime);}

 delaytime=pingyity();
 for(int i=0; i<60; i++){
 strip.setPixelColor(i, 0, 255, 0);
 strip.show();
 delay(delaytime);}

 delaytime=pingyity();
 for(int i=0; i<60; i++){
 strip.setPixelColor(i, 0, 0, 255);
 strip.show();
 delay(delaytime);}

 delaytime=pingyity();
 for(int i=0; i<60; i++){
 strip.setPixelColor(i, 255, 0, 255);
 strip.show();
 delay(delaytime);
 }
}

int pingyity()
{
 //Send ping signal out
 long duration, inches;
 digitalWrite(pingPin, LOW);
 delayMicroseconds(2);
 digitalWrite(pingPin, HIGH);
 delayMicroseconds(5);
 digitalWrite(pingPin, LOW);

 //read ping sensor signal input
 duration = pulseIn(echoPin, HIGH);
 // convert the time into a distance
 inches = duration / 74 / 2;

 //set light delay time based on sensor
 if(inches<=30) return(inches);
 else return(30);
}

Adafruit Neopixel LED strip on Spark Core Arduino

Getting start on the Adafruit Neopixel on the Spark Core. This shows a WS2812B 60 LED strip from Adafruit and uses the Neopixel port on Spark Core to run it.

It is quite easy to code thanks to the Adafruit library and a good way to get kids introduced to the for loop.

#include "neopixel/neopixel.h"
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, D2, WS2812B);

void setup() {
    strip.begin();
    strip.show();}

void loop() {
    for(int i=0; i<60; i++){
    strip.setPixelColor(i, 255, 0, 0);
    strip.show();
    delay(5);
    }
    for(int i=0; i<60; i++){
    strip.setPixelColor(i, 255, 255, 0);
    strip.show();
    delay(5);
    }
    for(int i=0; i<60; i++){
    strip.setPixelColor(i, 0, 255, 255);
    strip.show();
    delay(5);
    }
    for(int i=0; i<60; i++){
    strip.setPixelColor(i, 0, 255, 0);
    strip.show();
    delay(5);
    }
    for(int i=0; i<60; i++){
    strip.setPixelColor(i, 0, 0, 255);
    strip.show();
    delay(5);
    }
    for(int i=0; i<60; i++){
    strip.setPixelColor(i, 255, 0, 255);
    strip.show();
    delay(5);
    }
}