Maureen Thomas
Published © GPL3+

Lane Tech HS - PCL - IR Burglar Alarm with IOT relay twist

Use a photon to control IR LEDs as a object detector to trigger a relay giving power to an extension cord.

IntermediateFull instructions provided10 hours1,683
Lane Tech HS - PCL - IR Burglar Alarm with IOT relay twist

Things used in this project

Hardware components

Photon
Particle Photon
×1
Buzzer
Buzzer
×1
IR receiver (generic)
led
×1
IR transmitter (generic)
led
×1
Relay (generic)
×1
Coin Cell Battery CR2032
Coin Cell Battery CR2032
×1
Coin Cell Battery Holder
Coin Cell Battery Holder
×1
Resistor 100 ohm
Resistor 100 ohm
×1
Resistor 330 ohm
Resistor 330 ohm
×1
Jumper wires (generic)
Jumper wires (generic)
×3
Male/Female Jumper Wires
Male/Female Jumper Wires
×6
small PCB board
×1
extension cord
×1

Software apps and online services

Particle

Hand tools and fabrication machines

wire clippers
wire stripper
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schematics

Code

RelaywithParticle

Java
int analogInPin = A0;  // Analog input pin that the receiver is attached to
int sensorValue = 0;
bool checker = true; //true means that loop is running
int buzzerpin = D0; //has to be a PWM (Pulse Width Modulation)     
    
void setup() {
    
    
    pinMode(6, OUTPUT); //for the relay
    pinMode(analogInPin, INPUT); //reading the IR reciever led
    Particle.function("switch", pinSwitch); //IOT on/off
    Serial.begin(9600);
    pinMode( buzzerpin, OUTPUT ); //for the buzzer

}

void loop() {

 // read the analog in value:
   sensorValue = analogRead(analogInPin);

  // print the results to the serial monitor:
  Serial.print("\nsensor = ");
  Serial.print(sensorValue);
  //the threshold found fron analog In Out program was when object is detected, the sensor value is below 100
  //the threshold varies for different sets of emitter-receiver pairs
  if(sensorValue < 100 && (checker)){ //checks if object is there or not and 
    digitalWrite(6, HIGH);
    Serial.print("\No object in Front");
     noTone(buzzerpin);
    }
  else if (checker)
  {
    digitalWrite(6, LOW);
    Serial.print("\nObject Detected");
    tone(buzzerpin, 2551, 1000); //plays G3 for a second 
   
    }
   //delay(500)
  
}

int pinSwitch(String state)
{
    if (state.equals("on"))
    {
        checker = false; //disables loop
        digitalWrite(6, LOW);
        
    }
    else if (state.equals("off"))
    {
        checker = false; //disables loop
        digitalWrite(6, HIGH); //high is off
    }
    else if(state.equals("loop")) //enables the loop and sensor
    {
        checker = true;
    }
    return 1;
}

Credits

Maureen Thomas

Maureen Thomas

3 projects • 4 followers
Thanks to Goks_If.

Comments