Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Roy AshEric ProcunierLinda Viste
Published

Dog Motion Sensor and Food Dispenser

A remote dog food dispenser accessible via WiFi, for whenever you are away (or lazy) to feed the dog by pressing a button.

Intermediate5 hours1,568
Dog Motion Sensor and Food Dispenser

Things used in this project

Hardware components

Photon
Particle Photon
×3
ES08AII
×1
PIR Motion Sensor (generic)
PIR Motion Sensor (generic)
×1
Breadboard (generic)
Breadboard (generic)
×2
Pushbutton switch 12mm
SparkFun Pushbutton switch 12mm
×1

Software apps and online services

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

Hand tools and fabrication machines

Laser cutter (generic)
Laser cutter (generic)
Hot glue gun (generic)
Hot glue gun (generic)
Gorilla Glue

Story

Read more

Custom parts and enclosures

Frame 1 PDF File

First PDF file for laser cutter. This is the file that would be used for printing on 1/4''x12''x24'' wood. Parts: top layer 4.5'' hole, middle layer 2'' hole, 2 legs.

Frame 2 PDF File

Second PDF file for laser cutter. This is the file that would be used for printing on 1/4''x12''x24'' wood. Parts: third layer 1'' hole, custom funnel sides and slide, servo flap.

Frame 1 SVG File

This file can be used in Inkscape to be modified to individual preferences.

Frame 2 SVG File

This file can be used in Inkscape to be modified to individual preferences.

Schematics

Servo

Circuit connection for servo.

Button

Circuit connection for button.

PIR Motion Sensor

Circuit connection for PIR motion sensor.

Code

Servo Food Dispenser

C/C++
This code controls the servo treat dispenser. Servo is executed by subscribing to event PressButton which will trigger a signal when the event reads 1. Event PressButton calls function Feeder. This function will string compare a difference of 1 and will execute the servo from position 90 to 270 and back to 90, LED in D7 will be activated, this corresponds to if statement.
int y=0;
Servo FoodServo;
int servoPos = 270;
int Delay1 = 2000;
int Delay2 = 5000;
int Delay3 = 1000;

void setup() {
    
    pinMode(D7, OUTPUT);
    FoodServo.attach( D0 );
    Particle.subscribe("PressButton", Feeder, "3c0055000851363136363935"); //subscription to photon that executes pressed button code

}

   
void Feeder(const char *event, const char *data)
   {
       if(strcmp(data, "1")==0) //in event that reads 1, servo will be executed
   {
       digitalWrite(D7,1);
    
    FoodServo.write(90);
    delay(Delay1);
    FoodServo.write(270);
    delay(Delay2);
    FoodServo.write(90);
    delay(Delay3);
    digitalWrite(D7,0);
    
   }
  
    //nothing will happen

}
  

Button

C/C++
This code executes pressed button functionality. When button is pressed reading will be low by cutting connection which will publish a charcter 1 and turn LED in D7 on, which is if statement. Else if statement declares that when button is not pressed connection will be high, LED in D7 is off and nothing will be published.
int ledPin = D7;

// Our button wired to D0
int buttonPin = D0;

void setup()
{

  // For input, we define the
  // pushbutton as an input-pullup
  // this uses an internal pullup resistor
  // to manage consistent reads from the device

  pinMode( buttonPin , INPUT_PULLUP); // sets pin as input

  // We also want to use the LED

  pinMode( ledPin , OUTPUT ); // sets pin as output
  
  //Particle.subscribe("Food", MY_DEVICES)

}

void loop()
{
   // find out if the button is pushed
   // or not by reading from it.
   int buttonState = digitalRead( buttonPin );

  // remember that we have wired the pushbutton to
  // ground and are using a pulldown resistor
  // that means, when the button is pushed,
  // we will get a LOW signal
  // when the button is not pushed we'll get a HIGH

  // let's use that to set our LED on or off

  if( buttonState == LOW )
  {
    // turn the LED On
    digitalWrite( ledPin, HIGH);
    //String press = String(1);
    Particle.publish("PressButton", "1" , PUBLIC);
   // Particle.publish("PressButton", press , PUBLIC);
    delay(2000);
    
  }else{
    // otherwise
    // turn the LED Off
    digitalWrite( ledPin, LOW);
    //String press = String(0);
    //Particle.publish("PressButton", press, PUBLIC);
    delay(2000);
    //Particle.publish("PressButton", "0", PUBLIC);
  }


}

PIR Motion Sensor

C/C++
This code executes the PIR motion sensor functionality. When sensor senses motion it will read high and publish character 1 as well at turning LED in D7 on, this is if statement. Else if statement states that when no motion is detected it will read low and publish charcter 0 and LED in D7 will turn off. Publish is also published in https://thingspeak.com/channels/471653.
const String data = "";
int Sensor = D0;
int led1 = D7;

void setup() 
{
    pinMode(Sensor, INPUT);
    pinMode(led1, OUTPUT);
    digitalWrite(led1, LOW);
    digitalWrite(Sensor, LOW);
}



void loop() {

       if (digitalRead(Sensor) == HIGH)
       {
           
          //String Motion = String(1);
          Particle.publish("Sensor1", "1", PUBLIC);
          digitalWrite(led1, HIGH);
          delay (5000);
       }
       // hang tight here until motion stops

     else  if (digitalRead(Sensor) == LOW) 
     {
         
         //String Motion = String(0);
         Particle.publish("Sensor1", "0", PUBLIC);
         digitalWrite(led1, LOW);
         delay (5000);
         
       }
       
}

Credits

Roy Ash

Roy Ash

1 project • 1 follower
Mechanical engineering student at the University of north Carolina in Charlotte
Eric Procunier

Eric Procunier

1 project • 1 follower
Linda Viste

Linda Viste

1 project • 1 follower

Comments