Sarah Worthington
Published

Lane Tech HS - PCL - IOT Lamp

Turn a light on/off using a relay, Blynk, and an IR Break Beam.

IntermediateFull instructions provided5 hours223
Lane Tech HS - PCL - IOT Lamp

Things used in this project

Hardware components

Photon
Particle Photon
×1
Jumper wires (generic)
Jumper wires (generic)
×2
Relay (generic)
×1
Extension Cord
×1
Adafruit IR Break Beam Sensor - 3mm LEDs
×1
Male/Female Jumper Wires
Male/Female Jumper Wires
×3
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Blynk
Blynk

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Code

Project Code

C/C++
#include <blynk.h>

#define BLYNK_PRINT Serial

char auth[] = "fd0064959503465f889ad1f9346692c3"; //change to your personalized auth token

#define LEDPIN 6
#define SENSORPIN 4

int sensorState = 0, lastState=0;
int lightState = 0;
boolean flag = false;

void setup()
{
  pinMode(LEDPIN, OUTPUT);      
  pinMode(SENSORPIN, INPUT);     
  //pinMode(D6, OUTPUT);
  
  
  Serial.begin(9600);
  Blynk.begin(auth);
}

void loop()
{
  sensorState = digitalRead(SENSORPIN); //is sensor broken
  lightState = digitalRead(LEDPIN);     // is relay on


  if (sensorState == LOW) //broken beam
  {     
    if (lightState == HIGH) //LED on
    {
        digitalWrite(LEDPIN, LOW); 
    }
    if (lightState == LOW) //LED off
    {
        digitalWrite(LEDPIN, HIGH);
    }
  }

   Blynk.run();

}

Credits

Sarah Worthington

Sarah Worthington

2 projects • 2 followers
Contact

Comments

Add projectSign up / Login