Caden PainterBenjamin Rizza
Published

IOT Pet Door

Automate your pet's entrance to your house and receive real time updates as to when your pet is entering and exiting.

BeginnerFull instructions provided263
IOT Pet Door

Things used in this project

Hardware components

SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Hall Effect Sensor
Hall Effect Sensor
×1
Argon
Particle Argon
×2
Jumper wires (generic)
Jumper wires (generic)
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Breadboard (generic)
Breadboard (generic)
×2

Story

Read more

Schematics

Ultrasonic Argon Circuit Schematic

Wiring: Red = Vcc to VUSB on Argon, Green = Trig to pin D3, Blue = Echo to pin D2, Black = Ground

Servo/Hall Effect Argon Circuit Schematic

Servo Wiring: Red = VUSB on argon, Yellow = to pin D2, Black = Ground
Hall Effect Sensor Wiring: Black = Ground, Red = VUSB, Yellow = to pin D5

Pet Door Model

Picture of the entire model

Servo/Hall Effect Argon

Picture of the servo side of the model

Ultrasonic Argon

Picture of the Ultrasonic side of the model

Adafruit Graphing

Our graph displays a value of 0 when the door is closed and a 1 when it is open. This is data collected from the hall effect sensor.

Code

Servo/ Hall Effect Argon

C/C++
This is the code for the argon that subscribes to the data coming from the ultrasonic sensor and opens the door for the pet.
// subscribes the receiver Argon to the published events from the
// mesauring argon. In the last arguement for the subscribe function, enter
// the device ID from the publishing argon.
Servo myservo;  // create servo object to control a servo
                // a maximum of eight servo objects can be created

int pos = 0; 
int state = 0; 
int hallSensorPin = D5;
void setup() {
    


    myservo.attach(D2);   // attach the servo on the D2 pin to the servo object
     pinMode(hallSensorPin, INPUT);
   


   
    Particle.subscribe("PETSTATUS7845", b);
   
}
// converts Unix time data from subscribe functions to an integer value

void loop(){
      state = digitalRead(hallSensorPin);

  if (state == HIGH) {        
   Particle.publish("adafruitwebhook", String(0));  
  } 
  else {
    Particle.publish("adafruitwebhook", String(1)); 
  }
  delay(2500);
}
void b(const char *event, const char *data) {
     
 loop();
{
for(pos = 0; pos < 150; pos += 1)  // goes from 0 degrees to 150 degrees ; in steps of 1 degree
  {                                  
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(10);                       // waits 10ms for the servo to reach the position
  }
  for(pos = 150; pos>=1; pos-=1)     // goes from 150 to 0
  {
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(50);                       // waits 50ms for the servo to reach the position
}}}
  

Ultrasonic Argon

C/C++
This is the argon that uploads data from an ultrasonic sensor after detecting a pet in close proximity (10cm)
// Pin Definitions

#define HCSR04_PIN_TRIG	D3
#define HCSR04_PIN_ECHO	D2

int sound = 0;
bool armed = true; 
int timenow = 0;
int future = 0;
int status= 1;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
 
  pinMode(HCSR04_PIN_TRIG, OUTPUT);
  pinMode(HCSR04_PIN_ECHO, INPUT);
 
}

void loop() {
  // put your main code here, to run repeatedly:
  long timeTaken, distance;
  digitalWrite(HCSR04_PIN_TRIG, LOW);
  delayMicroseconds(2);
  digitalWrite(HCSR04_PIN_TRIG, HIGH);
  delayMicroseconds(10);
  digitalWrite(HCSR04_PIN_TRIG, LOW);
  timeTaken = pulseIn(HCSR04_PIN_ECHO, HIGH);//determine distance of wave
  distance = (timeTaken/2)/29.1;//using timeTaken calc distance of object

  /*determine corressponding leds to light up with respect to the distance
  of object*/


    if(distance<=10 && armed ){
       Particle.publish("PETSTATUS7845", String(distance));
       delay(1000);
       armed = false;
       timenow = millis();
       future = timenow + 3000; //10s in the future


    }
    else{
}
    delay(1000);
  


    if(millis() > future){  //do it again
    armed = true;
    }}

Credits

Caden Painter
1 project • 0 followers
Contact
Benjamin Rizza
0 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.