Abram Kidane
Published

Lane Tech HS - PCL - Motion-Sensitive IOT Light Control

This project was part of the Lane Tech HS Physical Computing Lab course. I created this project as part of the Home Automation/IoT project.

BeginnerWork in progress4 hours702
Lane Tech HS - PCL - Motion-Sensitive IOT Light Control

Things used in this project

Hardware components

Photon
Particle Photon
×1
Servos (Tower Pro MG996R)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1

Software apps and online services

Blynk
Blynk

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Code

The Code

C Header File
This code includes blynk integration as well as infrared sensing.
#include <blynk.h>

#define BLYNK_PRINT Serial  // Set serial output for debug prints

#include <blynk.h>
char auth[] = "1409008df1e1497db59877ce947e42ad";

const int analogInPin = A0;  // Analog input pin that the receiver is attached to
int sensorValue = 0;        // value read from the receiver
Servo theServo;
int pos = 0;
void setup() {
  delay(1000);
  Blynk.begin(auth);
  pinMode(D7, OUTPUT);
  pinMode(D5, INPUT);
  pinMode(A0,INPUT_PULLUP);
  pinMode(A4, OUTPUT);
  theServo.attach(A4);
  theServo.write(150);
}
BLYNK_WRITE(V1) {
    if (param.asInt() == 1) { // On button down...
        Blynk.tweet("My Particle project is tweeting using @blynk_app and it’s awesome!\n @Particle #IoT #blynk");
        digitalWrite(7, HIGH);
        Particle.publish("002_OBJECT_NOT_DETECTED");
        theServo.write(150);
        Blynk.notify("You pressed the button and I know it ;)");
    }
    if(param.asInt()==0){
        digitalWrite(7, LOW);
        Particle.publish("001_OBJECT_DETECTED");
        theServo.write(0);              // tell servo to go to position in variable 'pos'
        delay(1000); 
    }
}

BLYNK_WRITE(V2) {
    int r = param[0].asInt();
    int g = param[1].asInt();
    int b = param[2].asInt();
    if (r > 0 || g > 0 || b > 0) {
        RGB.control(true);
        RGB.color(r, g, b);
    } else {
        RGB.control(false);
    }
}
void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);
  Particle.publish(String(sensorValue));
  Blynk.run();
  /*
  if(sensorValue < 30){ //checks if object is there or not
    digitalWrite(7, LOW);
    
    }
  else if (sensorValue>600){
    digitalWrite(7, HIGH);
    Particle.publish("002_OBJECT_NOT_DETECTED");
    //theServo.write(0);              // tell servo to go to position in variable 'pos'
    delay(100);
    }
    */
 float x=digitalRead(D5);
 if(x==HIGH){
        theServo.write(0);              // tell servo to go to position in variable 'pos'
        delay(100);
    }
}

Credits

Abram Kidane

Abram Kidane

2 projects • 2 followers
Junior at Lane Tech

Comments

Add projectSign up / Login