Simon JackowskiJonathan Pauli
Published

SmartLights - Motion Sensor to Turn on Lights

This is a project that detects when there is motion in a room and turns on the lights for that room.

IntermediateFull instructions provided4 hours143
SmartLights - Motion Sensor to Turn on Lights

Things used in this project

Hardware components

PIR Motion Sensor DYP-ME003
×1
Male/Male Jumper Wires
×15
Photon
Particle Photon
×2
LED Light Strip
×1
Resistor 221 ohm
Resistor 221 ohm
×3
General Purpose Transistor NPN
General Purpose Transistor NPN
×3

Software apps and online services

ThingSpeak API
ThingSpeak API
Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Custom parts and enclosures

OEM RGB IR Receiver for LEDs

This is the original schematic for the LED light strip receiver. As indicated, the Photon connected to the lights replace the receiver micro controller that catches the IR signal from the 44-key remote. The transistors were replaced with similar NPN transistors for light activation and power separation between the 12V, and the photon's signal power.
Dizfq tnrvwbnpbq

Schematics

Motion Sensor Circuit

This is the circuit diagram for the motion sensor
Screen shot 2018 11 18 at 1 12 42 am 0letj6srga

Lights Circuit

This is the circuit that controls the lights
Screen shot 2018 11 18 at 1 33 55 am pgbh4j2zby

Code

Motion Sensor Code

C/C++
This is the code to send a signal from the motion sensor
int inputPin = D0;              
int ledPin = D1;                
int pirState = LOW;             
int val = 0;                    

int calibrateTime = 10000;      

void setup()
{
  pinMode( ledPin, OUTPUT );
  pinMode(inputPin, INPUT);     
}

void loop()
{

  
  if ( calibrated() )
  {

    readTheSensor();

   
    reportTheData();
  }
}

void readTheSensor() {
  val = digitalRead(inputPin);
}

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

void reportTheData() {

  
  if (val == HIGH) {

   
    if (pirState == LOW) {
     
      Particle.publish("motion", "2");
      
      pirState = HIGH;
      setLED( pirState );
    }
  } else {
    if (pirState == HIGH) {
     
      pirState = LOW;
      setLED( pirState );
    }
  }
}

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

Light Controller

C/C++
This code checks ThingSpeak to see if motion was detected from the PIR circuit. If motion is detected, the lights will turn on and stay on for the designated amount of time. This is very customizable!
int led = D0;
int data=false;
int motion=false;
//int ledgreen = D1;
//int ledblue = D2;




void setup ()
{
    pinMode(led,OUTPUT);
  
    
    digitalWrite(led,LOW);
    
    Particle.subscribe("motion", myAlert, "450038000351353530373132");
}

void myAlert(const char *event, const char *data)
{
    if (motion=true);
      digitalWrite(led,HIGH);
      delay(500000);
      digitalWrite(led,LOW);
      }
      

Credits

Simon Jackowski

Simon Jackowski

1 project • 0 followers
Jonathan Pauli

Jonathan Pauli

1 project • 0 followers

Comments

Add projectSign up / Login