Francis LiangJames InmanCasey AhausCasey Ahaus
Published

Dog Sensor

Did you forget about your dog that was outside? Never again with our device!

BeginnerFull instructions provided574
Dog Sensor

Things used in this project

Hardware components

Photon
Particle Photon
×3
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Buzzer
Buzzer
×1
Micro-USB to USB Cable (Generic)
Micro-USB to USB Cable (Generic)
×3
Jumper wires (generic)
Jumper wires (generic)
×14
Breadboard (generic)
Breadboard (generic)
×3

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE
Google Sheets
Google Sheets

Story

Read more

Schematics

Circuit Diagram (Ultrasonic)

VCC from the ultrasonic sensor is connected to the VUSB port on the Particle Argon, ground from the ultrasonic sensor is connected to the ground on the Particle Argon, Trig from the ultrasonic sensor is connected to D2 on the Particle Argon and Echo from the ultrasonic sensor is connected to D6 on the Particle Argon.

Circuit Diagram (Motion Sensor)

VCC from the motion sensor is connected to the 3.3V port on the Particle Argon, ground from the motion sensor is connected to the ground on the Particle Argon, and output from the ultrasonic sensor is connected to D2 on the Particle Argon.

Circuit Diagram (Buzzer)

VCC from the buzzer is connected to the 3.3V port on the Particle Argon, ground from the buzzer is connected to the ground on the Particle Argon, and output from the buzzer is connected to D6 on the Particle Argon.

Flow Diagram

This flow diagram shows the thought process behind the code and how to Particle Argons communicate with each other.

Live Data (Ultrasonic)

This is live data collected from Google Sheets of the ultrasonic sensor

Live Data Graphing (Ultrasonic)

This is live data graphed from Google Sheets of the ultrasonic sensor

Live Data (Motion)

This is live data collected from Google Sheets of the motion sensor

Live Data Graphing (Motion)

This is live data graphed from Google Sheets of the motion sensor

Code

Motion Sensor Code

C/C++
The motion sensor begins the entire process by telling the other devices that it has sensed something.
int sensorPin = 2;                //Sensor pin
int motionsensorInput = 0;        //This reads the motion status
int temp = 0;

void setup() {
pinMode(D2, INPUT);     //sets the motion sensor pin as an input

delay(60000); //Calibration Delay for Motion Sensor
    Particle.subscribe("UltraDetected",Ultrasonic,"e00fce68a308ce520fe51aac");

}

void loop() {
 motionsensorInput = digitalRead(D2);       //reads the input value
 if (motionsensorInput == HIGH){	        //checks to see if there is an input. If there is: the argon sends a motion alert to the cloud for the ultrasonic argon to activate and check if something is there. 
  
    Particle.publish("MotionAlert","Movement");   
    delay(1000);
    
  }
  else {
      delay(1000);
  }
}

void Ultrasonic(const char *event, const char *data)
{
    Particle.publish("BothChecked", "Let the dog in!");
}
  
}

Ultrasonic Sensor Code

C/C++
The ultrasonic sensor is used to double-check if the dog is actually at the door.
//Defining variables
unsigned long duration, inch, setdistance, setdistanceinch, diff;
int trigPin = 2;
int redPin = 3;
int yellowPin = 4;
int greenPin = 5;
int echoPin = 6;

void setup()
{
    //Defining inputs and outputs
    pinMode(redPin, OUTPUT);
    pinMode(yellowPin, OUTPUT);
    pinMode(greenPin, OUTPUT);
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
    pinMode(D7, OUTPUT);
    Particle.subscribe("MotionAlert",UltrasonicCheck,"e00fce68a308ce520fe51aac"); //This particle only activates after recieving a confirmation saying that the other argon has detected motion.
    setdistanceinch = 0;
    Serial.begin(9600);
}

void UltrasonicCheck(const char *event, const char *data)
{
    delay(10); //lines 23 - 30 output and collect the soundwave, get a duration in
    //terms of microseconds, convert that time to distance since we know how fast sound travels
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW); 
    duration = pulseIn(echoPin, HIGH);
    inch = (duration/2) / 74; //divides time in half since wave has to go both there and back,
    //divides by 74 since that is the time it takes for sound to travel one inch.

    
    if (inch <= 18){ //Checks if there is anything within 18 inches of the sensor.
        //if there is, the loop will upload a "1" to the cloud
        setdistanceinch = 0; //redefine our set distance to zero so we can move into red zone if the 
        //setdistance was previously set to 20-24 inches
        Particle.publish("UltraDetected", "1");
        digitalWrite(redPin, HIGH);  
        delay(5000); //delay 5 seconds 
        digitalWrite(redPin, LOW);
        setdistanceinch = inch; //defines distance so we must change from this (EITHER direction) 
            //4 inches before lighting code will run again.
    }
    else {
       delay(500); //delay half second when outside of 18 inch range
    }
    
}

Buzzer Code

C/C++
The buzzer is the last step in the process which will buzz when both the motion detector and the ultrasonic detector have sensed that the dog is at the door.
int buzzerPin = 6;                //Buzzer pin

void setup() {
pinMode(D6, OUTPUT);    //sets the passive buzzer to be an output

    Particle.subscribe("UltraDetected",Ultrasonic,"e00fce68a308ce520fe51aac");   
}

//The buzzer is the last step in the process. 
// If the motion sensor detects motion it sends a signal to the ultrasonic sensor asking to double check if something is there
// If the ultrasonic sensor says something is there it will send a signal back to the motion sensor which will activate thsi loop from the subscribe above. 
// The buzzer will only sound if both the motion sensor and ultrasonic sensor have detected motion.


//code for passive buzzer beeps
void Ultrasonic(const char *event, const char *data)
{
    beep();

    Particle.publish("BothChecked", "Send to buzzer");
   
}
    
    
    
void beep() {
    tone(D6, 3000, 50);
  
}

Credits

Francis Liang

Francis Liang

1 project • 0 followers
James Inman

James Inman

0 projects • 0 followers
Casey Ahaus

Casey Ahaus

0 projects • 1 follower
Casey Ahaus

Casey Ahaus

10 projects • 0 followers
I am a mechanical engineering student at the University of North Carolina Charlotte. This page is a way for me to showcase my many projects!

Comments