Seth MortonChandler Swaim
Published

LED Light Control

Use Particle Argons, Blynk IoT app, and a motion sensor to activate and change colors of an LED light strip.

BeginnerFull instructions provided2 hours156
LED Light Control

Things used in this project

Hardware components

Argon
Particle Argon
×2
LED Strip, NeoPixel Digital RGB
LED Strip, NeoPixel Digital RGB
×1
DIYmall PIR sensor
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Blynk
Blynk
Maker service
IFTTT Maker service

Story

Read more

Schematics

Argon 1 Circuit Diagram

Circuit diagram for motion sensor and LED strip.

Argon 2 Circuit Diagram

Circuit diagram for Blynk Argon.

Code

Color Picker

C/C++
Code to publish color picked by Blynk to the Particle Cloud. Replace "Auth Token" with the auth token provided by Blynk for your project.
//blynk setup
#define BLYNK_PRINT Serial
#include <blynk.h>
char auth[] = "J6dnIVaOHOn2RORAoRJAmpaIIf16dFVe";

void setup()
{
  Serial.begin(9600);
  delay(5000);
  Blynk.begin(auth);
  pinMode(D7, OUTPUT);
  
  Particle.subscribe("motion", d7toggle);  
}

void loop()
{
  Blynk.run();
}

//read rgb from blynk and publish
BLYNK_WRITE(V0)
{
  int r = param[0].asInt();
  int g = param[1].asInt();
  int b = param[2].asInt();  
  Particle.publish("Red", String(r));
  delay(1000);
  Particle.publish("Green", String(g));
  delay(1000);  
  Particle.publish("Blue", String(b));
  delay(1000);  
}

void d7toggle(const char *event, const char *data)
{
  if (strcmp(data,"False")==0) {
    digitalWrite(D7,LOW);
  }
  else if (strcmp(data,"True")==0) {
    digitalWrite(D7,HIGH);
  }
  else {
  }
}

Motion Sensor

C/C++
Determines if motion occurs and applies proper lighting to LED Strip
#include "Particle.h"
#include "neopixel.h"

SYSTEM_MODE(AUTOMATIC);

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

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);

int red;
int green;
int blue;

int inputPin = D2;               
int ledPin = D6;
int val = 0;  
 
void setup() {
     
  pinMode(inputPin, INPUT); 
  pinMode(ledPin, OUTPUT);
  
  digitalWrite(ledPin, LOW);
  strip.begin();
  
  Particle.subscribe("Red", red2);
  Particle.subscribe("Green", green2);
  Particle.subscribe("Blue", blue2);
  
}

void red2(const char *event, String data) {
    red = String(data).toInt();
}
void green2(const char *event, String data) {
    green = String(data).toInt();
}
void blue2(const char *event, String data) {
    blue = String(data).toInt();
}
 
void loop(){
  
  val = digitalRead(inputPin);  
  
  if (val == LOW) {
    
    colorAll(strip.Color(0,0,0),30);
    Particle.publish("motion", "False");
    delay(1000);
  }
  
  else if (val == HIGH) {            
    
    Particle.publish("motion" , "True");
    
    colorAll(strip.Color(red, green, blue),30);
    delay(6000);
     } 
  
  delay(1000);
  
}

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);
}

Credits

Seth Morton

Seth Morton

1 project • 0 followers
Chandler Swaim

Chandler Swaim

0 projects • 0 followers

Comments

Add projectSign up / Login