Nancy Yi Liang
Published © MIT

Buzz Wolf

Internet controlled dog collar that vibrates with a push of a button. The vibration safely and effectively gets your pet's attention.

BeginnerFull instructions provided2 hours2,099
Buzz Wolf

Things used in this project

Hardware components

Adafruit Vibrating Mini Motor Disc
×3
Adafruit Lithium Ion Polymer Battery - 3.7v 1200mAh
×1
Dog Collar
×1
Electron
Particle Electron
×1

Hand tools and fabrication machines

Sewing Machine (optional)

Story

Read more

Schematics

Layout

Code

Particle Code

Arduino
This is the code used in Particle's IDE (build.particle.io)
// Pin numbers for vibrating discs
int vib1 = D7;
int vib2 = D6;
int vib3 = D5;

void setup()
{
   // Set pins to output, meaning info flows from particle to component (vibrating discs)
   pinMode(vib1, OUTPUT);
   pinMode(vib2, OUTPUT);
   pinMode(vib3, OUTPUT);

   // Method, buzz is the URL method that the front end calls, and buzzToggle is the 
   // function within this particle code (see below)
   Spark.function("buzz",buzzToggle);
   
   // Set vibration to low, so the vibrating discs don't vibrate at startup
   digitalWrite(vib1, LOW);
   digitalWrite(vib2, LOW);
   digitalWrite(vib3, LOW);

}


void loop()
{
   // Nothing to do here :)
}


int buzzToggle(String command) {
    if (command=="blip") {
        digitalWrite(vib1,HIGH);
        digitalWrite(vib2,HIGH);
        digitalWrite(vib3,HIGH);
        delay(1000);
        digitalWrite(vib1,LOW);
        digitalWrite(vib2,LOW);
        digitalWrite(vib3,LOW);
        return 2;
    }
    else if (command=="test") {
        return 3;
    }
    else {
        return -1;
    }
}

Front End Webpage

HTML
This is the front end webpage, with the "buzz" button!
<html>
  <head>      
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    
    <title>BZZZZZZ</title>
   
    <script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">

    <script>
    $(document).ready(function() {
      device_id="YOUR_DEVICE_ID"
      access_token="YOUR_ACCESS_TOKEN"
      buzztime=1000
      $("#buzz").click(function() {
        starttime=Math.floor(new Date().getTime()/1000)
        console.log("start: " + starttime)
        $.ajax({
          url: "https://api.particle.io/v1/devices/" + device_id + "/buzz?access_token=" + access_token,
          method: "POST",
          data: {args: "blip"},
          success: function(data) {
            console.log( data)
            endtime=Math.floor(new Date().getTime()/1000)
            console.log("end: " + endtime)
            $("#msg").show()
            $("#msg").show().text("buzz! (took " + (endtime-starttime-1) + " secs to respond)").fadeOut(2000) // extra second b/c the vibration is set to 1 secs
          }
        })
      })
      $("#test").click(function() {
        starttime=Math.floor(new Date().getTime()/1000)
        console.log("start: " + starttime)
        $.ajax({
          url: "https://api.particle.io/v1/devices/" + device_id + "/buzz?access_token=" + access_token,
          method: "POST",
          data: {args: "test"},
          success: function(data) {
            console.log(data)
            endtime=Math.floor(new Date().getTime()/1000)
            console.log("end: " + endtime)
            $("#msg").show()
            $("#msg").text("connected  (took " + (endtime-starttime) + " secs to respond)").fadeOut(2000) 
          }
        })
      })
    })
    </script>
    <style>
      /* Custom CSS Goes Here */
    </style>
  </head>
  <body>
    <div class="row" style="margin: 10px;">
      <div class="col-md-8 col-md-offset-2">
        <!-- YOUR HTML BODY GOES HERE -->
        <button id="buzz" class="btn btn-primary btn-lg btn-block" style="margin-bottom: 10px">Buzz</button>
        <a id="test" class="btn btn-link" style="margin-bottom: 10px">Test Connection</a>
        <div id="msg" class="alert alert-info" style="display:none"></div>
      </div>
    </div>
  </body>
</html>

Credits

Nancy Yi Liang

Nancy Yi Liang

2 projects • 12 followers
I transform code into physical things

Comments