Project showcase
PIR-Sensor Activated RGB Strip Controlled by Uno R3

PIR-Sensor Activated RGB Strip Controlled by Uno R3 © GPL3+

At my age you have to get up at night and tend to be tired on the way to the bathroom. Use a PIR-Sensor to trigger the light on!

  • 1,470 views
  • 0 comments
  • 5 respects

Components and supplies

Apps and online services

About this project

Background

Based on my My PIR project with a Particle Photon, I copied it here with the components of Seeedstudio. With the Grove components, simple plug and play is possible.

A second power supply is needed (one for operating the LED strip and one for the Arduino itself). Otherwise, I could quickly adjust my code. This solution is designed without WLAN. For my motivation and my application scenario, please read the photon project.

You can purchase Grove kits, so you can install additional Grove components and expand the solution, for example, by a button. I wish lots of success and a lot of light in dark corners!

What it looks like 

An schematic picture is not available: put the grove base shield with the pins on top the Arduino Uno. Thats all.

Examples from Grove

Further examples with a introduction in components from Grove Starter Kit can be found here:

More projects under my account.

Code

MyPIR with Grove Components on Arduino UnoC/C++
// BOM
// 1x Arduino UNO R3
// 1x Grove Base Shield V2 for Arduino from seeedstudio.com
// 1x Grove LED Strip Driver V1.2 from seeedstudio.com
// 1x Grove Light Sensor V1.2 from seeedstudio.com
// 1x PIR Sensor Standard
// 1x one colored Standard LED
// 6x Jumper-cable for Standard LED and PIR Sensor
// 2x Grove 4pin Jumper from seeedstudio.com to plug there components
// 1x 12V 1A or 2A power output to power LED Strip
// 1x 5V power jack to power your Arduino Uno
// 1x power adapter from power jack (12V) to connect jumpers to power an LED Strip Driver
// 1x 4pin Standard cable to connect from LED Strip Driver to analog RGB Strip
// in my case I soldered the 4pin cable to the analog RBG Strip
// for flashing from your Desktop (create.arduino.cc) to Arduino UNO is an USB-cable necessary

// MyPIR - v1.0 - Ingo Lohs - 17.04.2017

// LEDStripDriver - Version: Latest from seeedstudio - download libary here: http://wiki.seeed.cc/Grove-LED_Strip_Driver/
#include <RGBdriver.h>

#define CLK 2 // pin definitions for the driver        
#define DIO 3
RGBdriver Driver(CLK,DIO);           // create instance for LED Driver Stripe

const int inputPin = 8;              // choose the input pin (for PIR sensor)
const int ledPin = 4;                // Standard LED connected to digital pin 4 to check that PIR Sensor works
int pirState = LOW;                  // we start, assuming no motion detected
int val = 0;                         // variable for reading the pin status
int analogvalue;                     // variable for environment light
int calibrateTime = 10000;           // wait for the thingy to calibrate
float light_threshold = 200;         // max brightness is presents with value 1304; decide its time for more light - adjust this value according to your needs
#define photoresistor A0             // photoresistor for reading analog values - bought by seeedstudio.com
 
void setup() {
  Serial.begin(115200);
    
  pinMode(photoresistor,INPUT);      // Our photoresistor pin is input     
 
  pinMode(ledPin,OUTPUT);
  digitalWrite(ledPin,LOW); 

    // LED Stripe off
  Driver.begin(); // begin
  Driver.SetColor(0, 0, 0); // set analog RBG Strip off
  Driver.end();
  
}
 
void loop() {
  
  // check to see what the value of the photoresistor is and store it in the int variable analogvalue
  analogvalue = analogRead(photoresistor);
  Serial.println(analogvalue); // --> output to Serial Monitor 
  delay(100);
  
  // if the sensor is calibrated
  if ( calibrated() )
  {
  // get the data from the sensor
    readTheSensor();
  // report it out, if the state has changed
    reportTheData();
  }
}
 

void readTheSensor() {
  val = digitalRead(inputPin);
   Serial.println(digitalRead(inputPin));
}


bool calibrated() {
  return millis() - calibrateTime > 0;
}


void reportTheData() {

  // if the sensor reads high
  // or there is now motion
  if (val == HIGH) {

    // the current state is no motion
    // i.e. it's just changed
    // announce this change by publishing an eent
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected - Control LED is on, but analogvalue from environment > light_threshold");  

      pirState = HIGH;
      setLED( pirState );

        if (analogvalue < light_threshold) {
                Serial.println("Motion detected - spot lights on");
                ColorFade();
        } //else {

        //}

    }
    
  } else {
    if (pirState == HIGH) {
      // we have just turned of
      // Update the current state
      pirState = LOW;
      setLED( pirState );
    }
  }
}


void setLED( int state )
{
  digitalWrite(ledPin,state);
}


void ColorFade() {

  // LED Stripe on
  Driver.begin(); // begin
  Driver.SetColor(255, 255, 255); //all RGB colors on
  Driver.end();
  
  delay(15000); // 15 sec on
  
  // LED Stripe off
  Driver.begin();
  Driver.SetColor(0, 0, 0); // all RGB colors off
  Driver.end();
  
}

Comments

Similar projects you might like

Multicolor Knight Rider with RGB PL9823 LED + Arduino UNO

Project tutorial by Giovanni Gentile

  • 3,978 views
  • 0 comments
  • 10 respects

Arduino controlled RGB LED strip

Project tutorial by Raphael Nestler and Danilo Bargen

  • 21,699 views
  • 2 comments
  • 19 respects

SmartPhone Controlled RGB MOOD Light

Project tutorial by Prajjwal Nag

  • 4,122 views
  • 1 comment
  • 10 respects

Motion activated SMS Shield- Tutorial

Project tutorial by Burger

  • 3,790 views
  • 2 comments
  • 5 respects

Motion Activated Night Light

Project tutorial by Haziq Afandi

  • 3,369 views
  • 0 comments
  • 4 respects

Laser Measurements Controlled by Arduino Nano

Project in progress by Ingo Lohs

  • 3,151 views
  • 2 comments
  • 5 respects
Add projectSign up / Login