Meghan FragomeniJustin McClellan
Published

Doggy Do Time

Keep track of your wandering pet as they love going outside and inside!

BeginnerShowcase (no instructions)3 hours68
Doggy Do Time

Things used in this project

Hardware components

Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×2
Argon
Particle Argon
×2
Breadboard (generic)
Breadboard (generic)
×2
Jumper wires (generic)
Jumper wires (generic)
×13
Male/Female Jumper Wires
Male/Female Jumper Wires
×8
LED (generic)
LED (generic)
×3
Photodiode, 45 °
Photodiode, 45 °
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
ThingSpeak API
ThingSpeak API

Story

Read more

Schematics

Outside Sensor

Inside Sensor

Code

Outside Sensor Code

C/C++
This code is for the sensor on the outside of the door
// Pin Definitions

#define trigPin D6
#define echoPin D7
#define outsideLight D3
// Initializing
int analogValue = 0;
long duration;
long distance;
bool Inside = false;
int brightness;


void setup()

{ 
    Serial.begin (9600);
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
    pinMode(outsideLight, OUTPUT);
    // Listening to the inside sensor
    Particle.subscribe("Inside Activity", diode);
    
}

void loop()
{ 
    // Distance calculation 
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(1000);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = (duration/2)/74;
    Serial.print(distance);
    Serial.println(" inches");
    delay(200);
    // Checking if the dog is going inside
    if (distance < 10){
        Inside = true;
        Particle.publish("Outside Activity", String(Inside));
        digitalWrite(outsideLight, LOW);
    }
}


void diode(const char *event, const char *data){
    // Check if it is light or dark and turn on LED accordingly
    analogValue=analogRead(A3);
    if (analogValue <= 50){
        digitalWrite(outsideLight, HIGH);
    }
    Inside = false;
}

Inside Sensor Code

C/C++
This code is for the sensor on the inside of the door
// Pin Definitions
#define trigPin D6
#define echoPin D7
#define redLight D2
#define greenLight D4
// Initialization 
long duration;
long distance; 
bool Outside = false;
    
    
void setup()
{ 
    Serial.begin (9600);
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
    pinMode(redLight, OUTPUT);
    pinMode(greenLight, OUTPUT);
    Particle.subscribe("Outside Activity", leds);

}
void loop()
{
    // Distance calculation 
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(1000);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = (duration/2)/74;
    Serial.print(distance);
    Serial.println(" inches");
    delay(200);
    
    // Checking if dog is leaving the house
    if (distance < 10){
        Outside = true;
        Particle.publish("Inside Activity", String(Outside));
        digitalWrite(redLight, HIGH);
        digitalWrite(greenLight,LOW);
        // Tells the graph when the dog is leaving
        Particle.publish("Going Outside", String(Outside), PRIVATE);
        //Channel ID: 1580458
        //API Key: M2U0PI0TOAVV7RN9
    }
}

void leds(const char *event, const char *data){
        // Turns the green light on if the dog has returned
            digitalWrite(greenLight, HIGH);
            digitalWrite(redLight, LOW);
            Outside = false;
            // Tells the graph the dog has returned
            Particle.publish("Going Outside", String(Outside), PRIVATE);
}

Credits

Meghan Fragomeni

Meghan Fragomeni

1 project • 1 follower
I am a mechanical engineering student at UNC Charlotte.
Justin McClellan

Justin McClellan

1 project • 1 follower
Student at UNC Charlotte, dual majoring in Mechanical Engineering and Physics. Graduating in Spring 2023

Comments

Add projectSign up / Login