Andrew McPartlandEli CroweEthan Ames
Published © GPL3+

Automatic Pet Door Lock

This device will automatically lock any kind of pet door using two different methods.

IntermediateShowcase (no instructions)4 hours12
Automatic Pet Door Lock

Things used in this project

Hardware components

DC Motor in Micro Servo Body
×1
Adafruit AHT20 - Temperature & Humidity Sensor Breakout Board - STEMMA QT / Qwiic
×1
Mini Illuminated Momentary Pushbutton - Blue Power Symbol
×1
Argon
Particle Argon
×3
Breadboard (generic)
Breadboard (generic)
×3

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
adafruit.io

Story

Read more

Schematics

Temperature and Humidity Sensor

Button Circuit

Motor Circuit

Temperature and Humidity Sensor Schematic

Button Schematic

Motor Schematic

Code

Temperature Sensor Code

C/C++
This code has a #include function at the very beginning. In order to make the sensor function properly it is crucial that this function is included and that the library is included in your project.
// This #include statement was automatically added by the Particle IDE.

#include <Wire.h>
#include <SparkFun_Qwiic_Humidity_AHT20.h> 

// declare humiditySensor, this is the device we've connected to
AHT20 humiditySensor;

// setup check to make sure that we can connect to the device 
void setup()
{
    // Setup 
  Wire.begin(); //Join I2C bus required!!! 

  //Check if the AHT20 will acknowledge, make sure it connects !! 
  if (humiditySensor.begin() == false)
  {
    Particle.publish("AHT20 not detected. Please check wiring. Freezing.");
    while (1);
  }
  Particle.publish("AHT20 acknowledged.");
}

// start the loop 
void loop()
{

    //Get the temperature and humidity value
    float temp = humiditySensor.getTemperature();
    float humidity = humiditySensor.getHumidity();
    
    //Print the results to the cloud! 
    Particle.publish("Temperature: ", String::format("%.1f", temp));
    Particle.publish("Humidity: ", String::format("%.1f", humidity));
    
    if (abs(humiditySensor.getTemperature()) >= 50)
    {
        Particle.publish("Hightemp");
    }

    // change to number of seconds 10000 = 10 seconds
    delay(1000);
}

Servo Motor Code

C/C++
Servo myservo;  // create servo object to control a servo
                

void setup()
{
  myservo.attach(A2);  // attaches the servo on the A2 pin to the servo object
  
myservo.write(10);
}

void loop()
{
//Particle.subscribe("Temperature", DoorUnlock);
  // Subscribe will listen for the event and, when it finds it, will run the function
  //delay(1000);
Particle.subscribe("Pushbutton", DoorUnlock);
  delay(1000);
Particle.subscribe("Hightemp", DoorUnlock);
  delay(1000);
}

void DoorUnlock(const char *event, const char *data)
{
  /* Particle.subscribe handlers are void functions, which means they don't return anything.
  They take two variables-- the name of your event, and any data that goes along with your event. */
  
    {
    myservo.write(180); 
    Particle.publish("DoorStatus","Open");
    delay(20000);
    myservo.write(10); 
    delay(1000);
    Particle.publish("TaskStatus1234","Completed");
  }
 
}

Push Button Code

C/C++
void setup() {
pinMode(D3, INPUT);
}

void loop() {
int tfbutton = digitalRead(D3);
if (tfbutton == HIGH) {
    Particle.publish("Pushbutton","activated");
}

}

Credits

Andrew McPartland

Andrew McPartland

0 projects • 0 followers
Eli Crowe

Eli Crowe

0 projects • 0 followers
Ethan Ames

Ethan Ames

0 projects • 0 followers

Comments

Add projectSign up / Login