Back to Parent

//Created by John Soh
// January 29, 2016
// IoT Spring 2016, Carnegie Mellon University

//This code will use a combination of sensors to either confirm that the latch lock on the dog crate is locked or send a notification if it's unlocked.


//crate weight to see if sherlock is in the crate
int dog = A1;
//range finder to see if theres a person
int person=A0;
//hall sensor to see if its been locked
int hall = D4;
//led to show that the latch has been locked
int led = D1;

int lock = 0;

void setup() {
  //FSR reads
  pinMode(dog, INPUT);
  //range finder reads
  pinMode(person, INPUT);
  //led writes
  pinMode(led, OUTPUT);
  //hall sensor reads
  pinMode(hall, INPUT);

  //serial to check
  Serial.begin(9600);


}

void loop() {

//read button variable-digital
int crated = analogRead(dog);
//read range finder variable-analog
int presence = analogRead(person);

lock = digitalRead(hall);


//if the dog is in the crate and someone is in front of the crate
if (crated >= 500 && presence > 700 && lock == LOW){
    //check hall sensor to see if its been locked

      digitalWrite(led, HIGH);}
      // if the latch has NOT been locked, turn led off
      else digitalWrite(led, LOW);{

      }

// if the dog is in the crate, no one is in front of the crate, and the latch is not locked
if (crated >= 500 && presence < 700 && lock == HIGH){
  //publish notice to IFTTT to notify phone
Particle.publish("Crate_Latch","UNLOCKED!!");
}

//Serial to check
Serial.print(crated);
Serial.print('/');
Serial.print(presence);
Serial.print('/');
Serial.println(lock);

//delay every 5 seconds to not overload the phone.
  delay(5000);
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0