Close
0%
0%

GPS Dog Fence

Connected GPS Geofence Collar

Similar projects worth following
This project allows the user to define a fencing area based on latitude and longitude coordinates and if the dog approaches the fence boundary it sends out a radio frequency that triggers a PetSafe Invisible fence collar. This allows for use of the existing electrostatic deterrent circuit which has proven to be safe while allowing the actual fence boundary polygon to be defined by coordinates.

Background:
This project begin a year ago when I was living on 160 acres and brought home a new great pyrenees puppy. I quickly learned that he was a wanderer and I would need a fence to keep our new furry friend around.

Not growing up on a farm, I started asking the question, how does one fence 160 acres? As I was searching, I quickly realized there wasn't much out there for anyone that owns over an acre of land and doesn't want to spend a fortune.

So, I did some research and set out to combine a previous open source project with a GPS geofence trigger.

Electronics

Test Circuit 1: PetSafe Collar Trigger Circuit

Although this had already been done before, I wanted to try it myself. I got a PetSafe collar and the items listed by whyameye on Instructables which was basically two 555 timers and the correct resistors and capacitors to generate the specific frequency for the PetSafe collar. This breadboard circuit worked perfectly, but being an Arduino guy I also tried the Arduino based configuration developed by crazy1gadgets on Instructables. This also worked so I decided on a GPS and made my first prototype board. It was basically an Arduino Uno Shield that included a GPS and a transistor for outputting to the antenna.

(Not-so) Functional Prototype 1: Arduino

I ordered this pcb from my favorite pcb manufacturer OSHPARK, and ordered a Sparkfun Copernicus II GPS. I connected everything and made up a basic code using Arduiniana's TinyGPS to read the location data. When I got everything soldered into place, I couldn't seem to make it work. I could not receive data from the Copernicus II. After much head scratching and reading the user manual for the GPS I found out that supply and logic voltage should be 3.3V not the Uno's 5V. I had fried the GPS...

Test Circuit 2: GPS + Processing Circuit

At this point I either needed to find a way to convert between logic levels or find another microcontroller that ran at 3.3V. That is when I found the Particle Electron. It is faster, connected, and runs at 3.3V. I decided to go this route. I was stuck in this area for a while. More info on this in the Software Section.

Functional Prototype 2: Particle Electron, Copernicus II GPS, and 555 Timers

This is the current design V008. The pcb includes multiple RGB LEDs, a buzzer, and all of the essential control circuitry.  You can purchase the PCB through OSHPARK via the link in the links section.

Software

GPS Parser:

Since I chose to use open source hardware and software, I used Arduiniana's TinyGPS Parser.

Fencing Algorithm V1:

For the first proof of concept software, I simply created a bounding box based on a min and a max of both latitude and longitude. Obviously, this has a lot of limitations, but it worked well to prove the concept and move the project to the next stage.

Fencing Algorithm V2: Utilizing Point in Polygon Algorithm

I again borrowed this code, but it works excellently. I will go into detail on how this works later, and explain it by running the algorithm through a few loops. It wasn't until I did this on a few sheets of paper that I truly understood how it worked.

Case Top 001.STL

3D printable STL file for the top of the case (note: units in mm)

Standard Tesselated Geometry - 220.79 kB - 10/19/2017 at 18:56

Download

Case Bottom 001.STL

3D printable STL file for the bottom of the case (note: units in mm)

Standard Tesselated Geometry - 487.48 kB - 10/19/2017 at 18:55

Download

Case Top 001.SLDPRT

Solidworks file for the top of the case

sldprt - 340.02 kB - 10/19/2017 at 18:55

Download

Case Bottom 001.SLDPRT

Solidworks file for the bottom of the case

sldprt - 274.79 kB - 10/19/2017 at 18:55

Download

GPS Collar v008.fzz

Fritzing File for the PCB

fzz - 219.19 kB - 10/16/2017 at 03:04

Download

View all 6 files

  • 1 × Particle Electron 3G Sparkfun WRL-14211
  • 1 × Sparkfun Copernicus II GPS Sparkfun GPS-11858
  • 1 × 2.2kOhm Resistor Adafruit 2782
  • 1 × 9V Buck Boost Pololu 2116
  • 1 × TIP120 Transistor Adafruit 976

View all 22 components

  • GPS Collar Case

    Erik Wachlin10/19/2017 at 18:51 0 comments

    Dogs who are likely to need this collar are active in all conditions.  So, in order to keep all of the electronics safe, we really need a case.  I just designed this one.  You can find a render of it in the gallery.  It includes supports for the board inside allowing it to be secured using #4 sheet metal screws that are 1/4" long.  The case uses an 3/32" o-ring that will need to be cut to size, and the top screws down using #4 sheet metal screws, compressing the o-ring and making a water resistant seal (I can't say waterproof because I have not tested it yet.)  There are 4 tabs with 1/4" holes in them that allow you to use paracord to attach the case to the dogs collar.  The solidworks files are attached for editing, and the STL files for the top and bottom of the case can be found there as well.  You can use the STL files to 3D print the case yourself or send them to a service to have one made for you if you do not have a 3D printer at home. 

  • Battery

    Erik Wachlin10/03/2017 at 20:02 0 comments

    The original design for the GPS dog collar includes the use of Li-ion batteries.  The batteries are rechargeable and have significant power capacity to weight ratio which is ideal for this mobile application.  The only issue is that there is no way to know how much charge the battery has.  I am working on integrating a "fuel gauge" IC that will allow monitoring of battery status so that the battery won't just go out and you lose your furry friend.  It will likely be included in board V009.  Board V008 will be posted soon and includes the 555 timers instead of the 556 timers.

  • LM556 Dual Timer's Discontinued

    Erik Wachlin10/03/2017 at 19:56 1 comment

    Board Update

    The LM556 dual timer is going to be discontinued, so I working on an updated circuit using the 555s and am going to integrate it into the PCB.  There will be an updated set of boards that I will be posting shortly.  

  • GPS Selection

    Erik Wachlin06/01/2017 at 11:41 0 comments

    Testing and comparing GPS modules is a tedious process because claims often vary greatly from actual performance. Thankfully, our friends at Sparkfun have done the work for the ones that they carry -Sparkfun GPS Tutorial. After reviewing the information they found, I decided to use the Copernicus II because it consistently had the most accurate results.

    NOTE: This GPS technology has the correct amount of accuracy for farms or people with yards over 1 acre. In order to be accurate enough for most city yards, RTK GPS technology would be necessary. The cost for such technology has dropped significantly in recent times, but it is still expensive relative to the WAAS GPS of the Copernicus II and at the time was not necessary for my needs. WAAS GPS technology was developed for landing aircraft in the USA without having a visual of the runway and is fairly accurate.

    RTK Accuracy: Plus or Minus 2-3 centimeters XYZ

    WAAS GPS Accuracy: Plus or Minus 1-2 meters in XY and Plus or Minus 2-3 meters in Z

  • Microcontroller Selection

    Erik Wachlin05/22/2017 at 14:13 0 comments

    When I first began this project, the only microcontroller family that I was familiar with were Arduino boards. But for a large range geofence, I decided that it was also important for it to be a connected device. With all the excitement about pet tracking, it seemed like a logical choice. Also, with all of the APIs already created for particle, the ease of improvement and innovation on the basic concept would be seemless. I am not a programmer by trade. What I know, I have learned from others or the internet, so I am excited to see the innovative additions that will be created on top of this open source project.

View all 5 project logs

  • 1
    Setting up your code

    • First you need to decide what you want to fence in.
    • Using Google Maps, select as many points as you need to zone your yard, farm, etc. and write down the latitude and longitude pairs. You will need at least 4 points, but they don't need to make up a perfect square.
    • Click the link to get the generic particle code that I created for this project- GPS Collar Code
    • Scroll down to where it says double latitude[100] and add all of the latitude locations that you selected, all separated by commas.
    • Then go to double longitude[100] and add all of the longitude locations that you selected , all separated by commas.
    • Next go to where it says int NumPoints and put in the count of the number of latitude and longitude pairs you selected for your geofence.
    • Go to the upper left corner of the screen and press the checkmark to check if your code compiles. If it doesn't, check to make sure that you inputted the same amount of latitude positions as you did longitude.
    • Your code is ready.
    • NOTE: for those hackers and innovators out there, this code is very basic, and the PCB allows for more to be built upon. Please innovate and share!
  • 2
    Uploading to Your Particle Electron

    This process took me a while to figure out, so I am going to walk through it in detail.

    Once you have your particle board connected to the mobile network and your account set up on particle follow these steps:

    NOTE: If you are only uploading the code once you may press the lightning bolt button that says flash. It will flash over the air (OTA) and will use some of your data for the month. It is very minimal if you are only uploading once and is the easiest way so I recommend doing this if you aren't trying to alter the code.

    If you are going to alter the code follow these steps:

    • Go to your code that you just generated and press the <> button on the left side of the page.
    • Next to where it says GPS_COLLAR_GENERIC there is a cloud-like button, press this button to download a .bin file that you can use to upload locally onto your particle electron.
    • Follow the directions here to set up your command line for uploading directly to your electron - Particle Docs
    • Once this is complete you are ready to upload over USB.
    • Connect the electron via USB.
    • Open a new terminal in the folder where your .bin file is saved.
    • Type "particle flash --Serial YOURFILENAME.bin" and of course replace your file name with the name of your file.
    • Hit enter on the command line.
    • Press and hold the mode button on the electron until it flashes blue.
    • Press enter on the command line again.
    • Your code should upload. If it does not, check that you typed everything into the command line correctly and try again. It should work.
  • 3
    Ordering parts

    You will need to order all the parts listed in the parts list in order to create this project and also some type of a bag that your dog can wear to hold all of the components.  This may be dog specific since there are many different sized dogs.

    Also, if you don't have these tools, getting a set of helping hands, a soldering iron, solder, and a set of wire cutters is pretty much essential for this build.

View all 5 instructions

Enjoy this project?

Share

Discussions

Brian wrote 11/19/2019 at 23:32 point

Looks like this project has been idle for a while, but I am interested in doing something similar and including LoRa radios for communicating back to the internet. Im curious how I would be able to add a proximity alarm, so the dog would get an audible warning when they are 10 feet or so from the boundary. Then if they cross the boundary they receive a vibration correction.

  Are you sure? yes | no

Adam Conrad wrote 03/26/2018 at 07:24 point

How is this progressing?  I  am thinking of something similar but  using much  more basic stuff :) that  I can  scrounge. Thank you for the inspiration!

  Are you sure? yes | no

Bharbour wrote 10/05/2017 at 01:36 point

That Copernicus module is a pretty nice receiver. I have done several projects with it.

  Are you sure? yes | no

Erik Wachlin wrote 06/12/2017 at 23:47 point

This was supposed to be entered in the IOT contest.  Messed up on the dates.

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates