Luke LowryRobert Jenkins
Published © GPL3+

Light Up Your World

Dim the lights and get the party started with this Particle Photon project.

IntermediateFull instructions provided3 hours195
Light Up Your World

Things used in this project

Hardware components

Photon
Particle Photon
×2
NeoPixel strip
NeoPixel strip
×1
Photo resistor
Photo resistor
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×1
Resistor 680 ohm
×1
5 Volt 3 Amp DC Convertor
×1
Jumper wires (generic)
Jumper wires (generic)
×2

Software apps and online services

Maker service
IFTTT Maker service
Particle Build
Particle Console

Story

Read more

Schematics

Photoresistor Set Up

Screen shot 2017 11 20 at 3 37 11 pm ofwxp16lm7

Photoresistor Fritzing File

LED Strip Set Up

Screen shot 2017 11 20 at 4 06 21 pm cnqslqkzn0

LED Strip Fritzing File

Code

LED Control

C/C++
// This #include statement was automatically added by the Particle IDE.
#include <neopixel.h>

int led = D7;


SYSTEM_MODE(AUTOMATIC);

// IMPORTANT: Set pixel COUNT, PIN and TYPE
#define PIXEL_PIN D2
#define PIXEL_COUNT 50
#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() {
     pinMode(led, OUTPUT);
    digitalWrite(led, LOW);
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)
{
  
 
  if (strcmp(data,"intact")==0) {
    // if your buddy's beam is intact, then turn your board LED on
     digitalWrite(led, HIGH);
     off(50); 
     
     
  }
  else if (strcmp(data,"broken")==0) {
     digitalWrite(led, LOW);
    greenStrip(50);
    
  }
  
  
}

Photoresistor

C/C++
This publishes "intact" when the lights are off and "broken" when the lights are on
int photoresistor = A0; 

int power = A5; 

int analogvalue; 
int lightThreshold;

bool lightsOff = false;



void setup() {

    
    pinMode(photoresistor,INPUT);  
    pinMode(power,OUTPUT); 

    
    digitalWrite(power,HIGH);

    
    Particle.variable("analogvalue", &analogvalue, INT);
    

    lightThreshold = 40;
    
    analogvalue = analogRead(photoresistor);
    delay(1000);
    
    
    
  
}




void loop() {
   
  if (analogRead(photoresistor)<=lightThreshold) {
    Particle.publish("lights_off","intact");
        delay(1000);
        
       
    }

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

}

Credits

Luke Lowry

Luke Lowry

1 project • 0 followers
Contact
Robert Jenkins

Robert Jenkins

1 project • 0 followers
Contact

Comments

Add projectSign up / Login