Things used in this project

Hardware components:
Photon new
Particle Photon
×2
Neopixel strip
NeoPixel strip
×1
Adafruit industries ada161 image 75px
Photo resistor
×1
Adafruit industries ada592 image 75px
USB-A to Micro-USB Cable
×1
Resistor 680 ohm
×1
5 Volt 3 Amp DC Convertor
×1
11026 02
Jumper wires (generic)
×2
Software apps and online services:
Q8wtlimqnp04fzhtr9v5
IFTTT Maker service
Particle Build
Particle Console

Schematics

Photoresistor Set Up
Screen shot 2017 11 20 at 3 37 11 pm ofwxp16lm7
Photoresistor Fritzing File
photoresistor_L1d9zqlqCF.fzz
LED Strip Set Up
Screen shot 2017 11 20 at 4 06 21 pm cnqslqkzn0
LED Strip Fritzing File
led_strip_qiy6Z2gSMV.fzz

Code

LED ControlC/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);
    
  }
  
  
}
PhotoresistorC/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

0d4a12aae205fe571029582aa2a31294
Luke Lowry
1 project • 0 followers
Contact
F9ec5b1c7b9ba0c87f57cf592767bbf9
Robert Jenkins
1 project • 0 followers
Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Add projectSign up / Login