Sean KolesarTodd Gunzenhauser
Published © LGPL

The Party LED Night Light

Have you ever wanted to spice up your party environment with lights? This project uses two Particle Photons, a photoresistor and LED lights.

IntermediateFull instructions provided3 hours155
The Party LED Night Light

Things used in this project

Hardware components

Photon
Particle Photon
×1
Adafruit LED NeoPixel Strip
×1
5 V 10 Amp Power Supply
×1
Male and Female DC Power Jack
×1
Photo resistor
Photo resistor
×1
220 Ohm Resistor
×1
Circuit Wires
×1

Software apps and online services

Maker service
IFTTT Maker service
Google Sheets
Google Sheets

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Screwdriver

Story

Read more

Schematics

RGB LED Circuit Diagram from Adafruit

This is the circuit diagram of the connections to the LED lights. Make sure you connect to the "Din" pin and not the "Dout" one.
Ajmzs05dnzu0ssqzh28l mvho2o2gvs

Photoresistor Circuit Diagram

Photoresistor circuit diagram connections
Ewtcawrj0puqszdpxgsj 8pmynoeepi

Code

Code for Controlling the LED Lights

C/C++
This is the code that you should upload to your Photon that controls the LED.
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>




/*-------------------------------------------------------------------------
  Spark Core, Particle Photon, P1, Electron and RedBear Duo library to control
  WS2811/WS2812/WS2813 based RGB LED devices such as Adafruit NeoPixel strips.

  Supports:
  - 800 KHz WS2812, WS2812B, WS2813 and 400kHz bitstream and WS2811
  - 800 KHz bitstream SK6812RGBW (NeoPixel RGBW pixel strips)
    (use 'SK6812RGBW' as PIXEL_TYPE)

  Also supports:
  - Radio Shack Tri-Color Strip with TM1803 controller 400kHz bitstream.
  - TM1829 pixels

  PLEASE NOTE that the NeoPixels require 5V level inputs
  and the Spark Core, Particle Photon, P1, Electron and RedBear Duo only
  have 3.3V level outputs. Level shifting is necessary, but will require
  a fast device such as one of the following:

  [SN74HCT125N]
  http://www.digikey.com/product-detail/en/SN74HCT125N/296-8386-5-ND/376860

  [SN74HCT245N]
  http://www.digikey.com/product-detail/en/SN74HCT245N/296-1612-5-ND/277258

  Written by Phil Burgess / Paint Your Dragon for Adafruit Industries.
  Modified to work with Particle devices by Technobly.
  Contributions by PJRC and other members of the open source community.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing products
  from Adafruit!
  --------------------------------------------------------------------*/

/* ======================= includes ================================= */

#include "Particle.h"
#include "neopixel.h"

/* ======================= prototypes =============================== */

void colorAll(uint32_t c, uint8_t wait);
void colorWipe(uint32_t c, uint8_t wait);
void rainbow(uint8_t wait);
void rainbowCycle(uint8_t wait);
uint32_t Wheel(byte WheelPos);

/* ======================= extra-examples.cpp ======================== */

SYSTEM_MODE(AUTOMATIC);

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

// Parameter 1 = number of pixels in strip
//               note: for some stripes like those with the TM1829, you
//                     need to count the number of segments, i.e. the
//                     number of controllers in your stripe, not the number
//                     of individual LEDs!
// Parameter 2 = pin number (most are valid)
//               note: if not specified, D2 is selected for you.
// Parameter 3 = pixel type [ WS2812, WS2812B, WS2812B2, WS2813, WS2811,
//                            TM1803, TM1829, SK6812RGBW, WS2812B_FAST,
//                            WS2812B2_FAST ]
//               note: if not specified, WS2812B is selected for you which
//                     is the same as WS2812 or WS2813 in operation.
//               note: RGB order is automatically applied to WS2811,
//                     WS2812/WS2812B/WS2812B2/WS2813/TM1803 is GRB order.
//               note: For legacy 50us reset pulse timing on WS2812/WS2812B
//                     or WS2812B2, select WS2812B_FAST or WS2812B2_FAST
//                     respectively.  Otherwise 300us timing will be used.
//
// 800 KHz bitstream 800 KHz bitstream (most NeoPixel products
//               WS2812/WS2813 (6-pin part)/WS2812B (4-pin part)/SK6812RGBW (RGB+W) )
//
// 400 KHz bitstream (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//                   (Radio Shack Tri-Color LED Strip - TM1803 driver
//                    NOTE: RS Tri-Color LED's are grouped in sets of 3)

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

void setup() {
    Particle.subscribe("ToddOn008", myHandler);
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}

void loop() {
  // Some example procedures showing how to display to the pixels:
  // Do not run more than 15 seconds of these, or the b/g tasks
  // will be blocked.
  //--------------------------------------------------------------

  //strip.setPixelColor(0, strip.Color(255, 0, 255));
  //strip.show();

  //colorWipe(strip.Color(255, 0, 0), 50); // Red

  //colorWipe(strip.Color(0, 255, 0), 50); // Green

  //colorWipe(strip.Color(0, 0, 255), 50); // Blue

  //rainbow(20);

  //rainbowCycle(20);

  //colorAll(strip.Color(0, 255, 255), 50); // Cyan
}

// Set all pixels in the strip to a solid color, then wait (ms)
void colorAll(uint32_t c, uint8_t wait) {
  uint16_t i;

  for(i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
  }
  strip.show();
  delay(wait);
}



// Fill the dots one after the other with a color, wait (ms) after each one
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Slightly different, this makes the rainbow equally distributed throughout, then wait (ms)
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) { // 1 cycle of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}


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"

  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,"on")==0) {
    // if your photoresistor detects the lights are not on, turn on the LED's and publish event saying success
    colorWipe(strip.Color(255, 0, 0), 50); // Red
    strip.show();
    Particle.publish("SeanSuccess008","On");
    
  }
  else if(strcmp(data,"off")==0) {
      Particle.publish("SeanSuccess008","Off");
      colorAll(strip.Color(0, 0, 0), 50); // Cyan
    // if the data is something else, don't do anything.
    // Really the data shouldn't be anything but those two listed above.
  }
  
}

Code for Reading Photoresistor Values and Publishing

C/C++
This is the code that should be uploaded to the Photon which takes the photo resistor values.
int boardLed = D7;
int photoresistor = A0;
int power = A5;
int analogvalue;
bool on;


// We start with the setup function.

void setup() {
  // This part is mostly the same:
  pinMode(boardLed,OUTPUT); // Our on-board LED is output as well
  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)
  digitalWrite(power,HIGH);
  bool on = false; //set lights to off to start

  // Here we are going to subscribe to your buddy's event using Particle.subscribe
  Particle.subscribe("SeanSuccess008", myHandler);
  // Subscribe will listen for the event buddy_unique_event_name and, when it finds it, will run the function myHandler()
  // (Remember to replace buddy_unique_event_name with your buddy's actual unique event name that they have in their firmware.)
  // myHandler() is declared later in this app.

  // Next, write the power of the photoresistor to be the maximum possible, which is 4095 in analog.

}


void loop() {
    int analogvalue = analogRead(photoresistor);
    if(analogvalue<40 & on == false){
        Particle.publish("ToddOn008","on");
        Particle.publish("photoResistorValue","on");
        on = true;
    }
    else if(analogvalue>40 & on == true){
        Particle.publish("ToddOn008","off");
        on = false;
    }
    delay(1000);
}


// Now for the myHandler function, which is called when the cloud tells us that our buddy's event is published.
void myHandler(const char *event, const char *data)
{
    if (strcmp(data,"On")==0){
        digitalWrite(boardLed,HIGH);
    }
    else{
     digitalWrite(boardLed,LOW);   
    }
}


Todd Gunzenhauser
11:06 PM (1 minute ago)
to Sean

// Initializing all variables
int boardLed = D7;
int photoresistor = A0;
int power = A5;
int analogvalue;
bool on;

// Setting up all the important stuff ya know?
void setup() {
 
  pinMode(boardLed,OUTPUT); // Our on-board LED is output as well
  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)
  digitalWrite(power,HIGH);
  bool on = false; // Set lights to off to start

  // Subscribing to Sean's Photon
  Particle.subscribe("SeanSuccess008", myHandler);

}


void loop() {
    int analogvalue = analogRead(photoresistor);
    if(analogvalue<100 & on == false){
        Particle.publish("ToddOn008","on");
        Particle.publish("photoResistorValue",String(analogvalue));
        on = true;
    }
    else if(analogvalue>100 & on == true){
        Particle.publish("ToddOn008","off");
        Particle.publish("photoResistorValue",String(analogvalue));
        on = false;
    }
    delay(2000);
}


// When Sean's Photon does stuff it sends it here
void myHandler(const char *event, const char *data)
{
    // if he tells me to turn my light on then I turn it on.

Credits

Sean Kolesar

Sean Kolesar

1 project • 1 follower
Todd Gunzenhauser

Todd Gunzenhauser

1 project • 0 followers
Thanks to Erik Egeland.

Comments

Add projectSign up / Login