Erik EgelandLuke Green
Published © GPL3+

Party up with Controlled RGB LED Light Strip!

Turn your lights off in your room and watch the RGB led light strip light up. Great for parties and can be used for exterior illumination.

IntermediateFull instructions provided3 hours1,965
Party up with Controlled RGB LED Light Strip!

Things used in this project

Hardware components

Photon
Particle Photon
×2
NeoPixel strip
NeoPixel strip
Any WS2812B RGB LED strip should work here. Amazon had some that are cheaper.
×1
5 V 10 Amp power supply
Any 5 Volt 10 Amp power supply will work here.
×1
Male & Female Pair DC Power Jack
×1
Photo resistor
Photo resistor
×1
Resistor 221 ohm
Resistor 221 ohm
Any 220 ohm resistor will work here.
×1

Story

Read more

Schematics

RGB led circuit diagram

This is the schematic needed to hook up a particle, power supply and RGB led light strip.

Photo resistor circuit diagram

This is the schematic need to hook up a photo resistor to the particle photon. Ignore the Led and other resistor hooked up to the particle. That will not be needed for this project.

Code

Code For controlling the LED strip

C/C++
This is the code that will be flashed to the particle that is controlling the RGB led light strip. This is not the code for the other photon that measuring the analog value of the photo resistor.
// This #include statement was automatically added by the Particle IDE.
#include "neopixel/neopixel.h"


SYSTEM_MODE(AUTOMATIC);

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 200
#define PIXEL_TYPE WS2812B

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

int ledState = 0;



void stripSetPixelColor(unsigned char red, unsigned char green, unsigned char blue)
{
    uint16_t i;
    for (int i = 0 ; i < strip.numPixels() ; i += 1 )
    {
        strip.setPixelColor(i, strip.Color(red,green,blue));
    }
    strip.show();
}

void redStrip(uint8_t wait)
{
    stripSetPixelColor(255, 0, 0);
    delay(wait);
}

void orangeStrip(uint8_t wait)
{
    stripSetPixelColor(255,150,0);
    delay(wait);
}

void yellowStrip(uint8_t wait)
{
    stripSetPixelColor(255,255,0);
    delay(wait);
}

void greenStrip(uint8_t wait)
{
    stripSetPixelColor(0,255,0);
    delay(wait);
}

void cyanStrip(uint8_t wait)
{
    stripSetPixelColor(0,255,255);
    delay(wait);
}

void blueStrip(uint8_t wait)
{
    stripSetPixelColor(0,0,255);
    delay(wait);
}

void purpleStrip(uint8_t wait)
{
    stripSetPixelColor(255,0,255);
    delay(wait);
}

void magentaStrip(uint8_t wait)
{
    stripSetPixelColor(155,48,255);
    delay(wait);
}

void pinkStrip(uint8_t wait)
{
    stripSetPixelColor(255,0,150);
    delay(wait);
}

void whiteStrip(uint8_t wait)
{
    stripSetPixelColor(255,255,255);
    delay(wait);
}

void off(uint8_t wait)
{
    stripSetPixelColor(0,0,0);
    delay(wait);
}

int ledColor(String command)
{
    
    if(command == "White")
    {
        whiteStrip(20);
        return 1;
    }
    else if(command == "Pink")
    {
        pinkStrip(20);
        return 1;
    }
    else if(command == "Red")
    {
        redStrip(20);
        return 1;
    }
    else if(command == "Orange")
    {
        orangeStrip(20);
        return 1;
    }
    else if(command == "Yellow")
    {
        yellowStrip(20);
        return 1;
    }
    else if(command == "Green")
    {
        greenStrip(20);
        return 1;
    }
    else if(command == "Cyan")
    {
        cyanStrip(20);
        return 1;
    }
    else if(command == "Blue")
    {
        blueStrip(20);
        return 1;
    }
    else if(command == "Purple")
    {
        purpleStrip(20);
        return 1;
    }
    else if(command == "Magenta")
    {
        magentaStrip(20);
        return 1;
    }
    
    else if(command == "Off")
    {
        off(20);
        return 1;
    }
    
    else return -1; 
}

void setup() {
strip.begin();
  strip.show(); // Initialize all pixels to 'off'
  /* Set up particle function to recieve code for  */
  Particle.function("ledcolor", ledColor);
  strip.setBrightness(100);
  Particle.subscribe("lights_off", myHandler);
}

void loop() {

}

void myHandler(const char *event, const char *data)
{
  /* Particle.subscribe handlers are void functions, which means they don't return anything.
  They take two variables-- the name of your event, and any data that goes along with your event.
  In this case, the event will be "buddy_unique_event_name" and the data will be "intact" or "broken"

  Since the input here is a char, we can't do
     data=="intact"
    or
     data=="broken"

  chars just don't play that way. Instead we're going to strcmp(), which compares two chars.
  If they are the same, strcmp will return 0.
  */

  if (strcmp(data,"intact")==0) {
    // if your buddy's beam is intact, then turn your board LED of
     blueStrip(20);
  }
  
  else if (strcmp(data,"broken")==0) {
     off(20); 
  }
  
  
}

Code For Particle to read photoresistor

C/C++
This is the code for the particle to read analog values from a photo resistor. Then publish an event on the internet which the other particle hooked up to the led light strip will subscribe to that event. Based on the analog values from the photo resistor the particle will either turn on or off the led light strip.
// -----------------------------------------
// Function and Variable with Photoresistors
// -----------------------------------------
// In this example, we're going to register a Particle.variable() with the cloud so that we can read brightness levels from the photoresistor.
// We'll also register a Particle.function so that we can turn the LED on and off remotely.

// We're going to start by declaring which pins everything is plugged into.

// This is where your LED is plugged in. The other side goes to a resistor connected to GND.

int photoresistor = A0; // This is where your photoresistor is plugged in. The other side goes to the "power" pin (below).

int power = A5; // This is the other end of your photoresistor. The other side is plugged into the "photoresistor" pin (above).
// The reason we have plugged one side into an analog pin instead of to "power" is because we want a very steady voltage to be sent to the photoresistor.
// That way, when we read the value from the other side of the photoresistor, we can accurately calculate a voltage drop.

int analogvalue; // Here we are declaring the integer variable analogvalue, which we will use later to store the value of the photoresistor.
int lightThreshold;

bool lightsOff = false;

// Next we go into the setup function.

void setup() {

    // First, declare all of our pins. This lets our device know which ones will be used for outputting voltage, and which ones will read incoming voltage.
    pinMode(photoresistor,INPUT);  // Our photoresistor pin is input (reading the photoresistor)
    pinMode(power,OUTPUT); // The pin powering the photoresistor is output (sending out consistent power)

    // Next, write one pin of the photoresistor to be the maximum possible, so that we can use this for power.
    digitalWrite(power,HIGH);

    // We are going to declare a Particle.variable() here so that we can access the value of the photoresistor from the cloud.
    Particle.variable("analogvalue", &analogvalue, INT);
    // This is saying that when we ask the cloud for "analogvalue", this will reference the variable analogvalue in this app, which is an integer variable.

    lightThreshold = 100;
    // check to see what the value of the photoresistor is and store it in the int variable analogvalue
    analogvalue = analogRead(photoresistor);
    delay(1000);
    
  
}


// Next is the loop function...

void loop() {
   // This loop sends a publish when the lights are off.
  if (analogRead(photoresistor)<=lightThreshold) {
    Particle.publish("lights_off","intact");
        delay(1000);
        // publish this public event
        // rename lights_off with your actual unique event name. No spaces, 63 ASCII characters.
        // give your event name to your buddy and have them put it in their app.

        // Set the flag to reflect the current status of the lights.
       
    }

  else if (analogRead(photoresistor)>lightThreshold) {
       // Same deal as before...
        Particle.publish("lights_off","broken");
         delay(1000);
       
      }
   

}

Credits

Erik Egeland

Erik Egeland

1 project • 0 followers
Luke Green

Luke Green

1 project • 0 followers
Thanks to MobileRez.

Comments