Following Pigs: Building An Injectable Livestock Tracking System

I’m often asked to design customer and employee tracking systems. There are quite a few ways to do it, and it’s an interesting intersection of engineering and ethics – what information is reasonable to collect in different contexts, anonymizing and securely storing it, and at a fundamental level whether the entire system should exist at all.

On one end of the spectrum, a system that simply counts the number of people that are in your restaurant at different times of day is pretty innocuous and allows you to offer better service. On the other end, when you don’t pay for a mobile app, generally that means your private data is the product being bought and sold. Personally, I find that the whole ‘move fast and break things’ attitude, along with a general disregard for the privacy of user data, has created a pretty toxic tech scene. So until a short while ago, I refused to build invasive tracking systems – then I got a request that I simply couldn’t put aside…

The small form factor of the injectable tags is quite nice. The rather large needle used to insert them, less so.

A friend working with a large agricultural firm wanted an injectable RFID system to track pigs from birth to slaughter. I laid out the system architecture next to what I had from various proposed consumer tracking systems. I looked from pig to consumer, then consumer to pig again, and true to Orwellian archetype, it was impossible to say which was which. One thing was clear: I was going to waive my fee and build some demo hardware… I was too amused to do otherwise!

Many of you will have heard of injectable RFID tags from news articles describing someone implanting themselves with one to open car doors or similar. Fundamentally, these are tiny RFID chips tightly wrapped with a coil of wire, and encapsulated in an inert package a bit larger than a grain of rice. Most of the devices on the market are rated for veterinary use only and are very inexpensive, although there are some rated for human use as well. If you’re into that sort of thing, then you’re sort of building a livestock tracking system for yourself (or perhaps a pet), and some of the below might be useful for you!

Understanding Tracking Implants

Unlike the 13.56MHz NFC / RFID systems you might be familiar with, these implantable systems for pets and livestock generally work off a 125kHz carrier frequency. They also have their own communication standard defined, ISO 11784. I saw only a couple of higher frequency tags available, so I went and bought the cheapest/finest reader and a few low frequency injectable tags available on Taobao. I ended up with something vaguely like this, but with more unlabeled ICs. Note that for human use, you probably won’t want the injectable tags I use here as they don’t support encryption or NFC.

The antenna is just a square coil of magnet wire.

The reader was not a terribly impressive device – a raw board with a magnet wire antenna that breaks off easily, needing to be resoldered during testing. It provides output as 9600 baud serial communications. I had a WeMos ESP8266 development board with NodeMCU loaded lying around, and chose to use that to manage the device.

The hardest part here turned out to be the serial port needing to switch between two baud rates for loading code to the ESP8266 and for receiving data from the implantable tag reader. On boot, the ESP8266 expects to communicate at 115200 baud, and executes anything sent to it over the serial port. When receiving data from the reader, it needs to run at 9600 baud, and definitely not execute anything received… because ‘file.format’ is a cute name for a pig and we’ll want to support that. Since I’ll want to connect the device to the Internet later on, we accomplish this by keeping the default serial port settings while the device connects to Wi-Fi:

-- Connection parameters
station_cfg.ssid="SSID here"
station_cfg.pwd="password here"

-- Only run serial monitor once connected
mytimer = tmr.create()
mytimer:register(1000, tmr.ALARM_AUTO, function() if wifi.sta.getip()==nil then print("Connecting...") else dofile('serial.lua') end end)

Then after a Wi-Fi connection is established, we use the code below in a file named ‘serial.lua’ to switch the serial port settings so that it works at 9600 baud, and won’t try to execute anything received. We then start scanning:

-- initialize serial port to run at 9600 baud and not execute input
uart.setup(0, 9600, 8, uart.PARITY_NONE, uart.STOPBITS_1, 0)
data = ""

-- When serial data comes in, the data is preceded by an octothorpe, and split into two lines separated by a newline character. Strip those out.
uart.on("data", "#",
    data = string.gsub(data, "#", "")
    data = string.gsub(data, "\n", "")
    data = ""
    end, 0)

This creates a workflow roughly as follows, which I follow every time I’ve got a serial device to connect to an ESP8266:

  1. Set the baud rate of Esplorer to 115200
  2. While the device is connecting to Wi-Fi, send file.remove(“init.lua”) to the device and reset
  3. Load updated code to the device (init.lua and serial.lua)
  4. Set the baud rate of Esplorer to 9600 and reset
  5. See what happens, repeat as needed

When we now bring an implantable tag in contact with the reader, it correctly outputs the ID stored on it. The first thing I noticed is that it has a very short range – even shorter than a 13.56MHz RFID access card: a tag has to exactly touch the antenna to be read, and sometimes it takes two or three tries. Part of that is probably the questionable quality of my reader and tags, however the tiny antenna in the implantable tag is unlikely to compare favorably to the larger and better oriented antenna of an access card. Overall these implantable tags seem to be an incredibly short-range technology, even with higher frequency NFC systems.

That’s probably good news for any humans out there with these implants, because it’s harder for me to intercept communications on your device that requires surgery to remove. On the other hand, it makes it pretty useless for tracking livestock compared to the longer-range ear or ankle tags that are currently used.

Building a Prototype For the Customer to Say Yes

The next step was to clean it up for a demo. One thing I learned the hard way over the years, is that when someone asks you to demonstrate a prototype, they care about a very different set of things than you do. For all hardware demonstrations, I try to make the device a standalone, self-contained unit to avoid distractions. I have at a minimum a bright OLED screen, LiPo pouch cell, a USB charging circuit, and a jumper to connect power. The cell and charging circuit are trivial (it’s just a module and any spare pouch cell), and adding the OLED screen is pretty easy.

USB charger is on the reverse side of the top board. A second PCB is attached below it to cover the soldering work, and the antenna is on the verso of that second layer.

I also use two layers of green perfboard, so that solder traces are hidden, and brass spacers so it stands off whatever surface it’s on. Overall this shifts the focus from boring questions, like why it’s plugged into my computer via USB cable (just for power), to more interesting ones like performance and cost.

This Implant Is Not the Future

In the end, the prototype demonstrated that injectable RFID was not a superior way to track livestock due to the very short range of the system compared to existing solutions – the reader was fiddly even with a 0.5mm plastic spacer between it and the tag, whereas the ear and ankle tags currently used worked over tens of centimeters.

Still, I connected it to ThingsBoard because it was fun to have an Internet of Pigs device. Any suggestions on surgery-free alternate uses for my leftover injectable tags? Embedding one in an acrylic ring for low-security use comes to mind.

43 thoughts on “Following Pigs: Building An Injectable Livestock Tracking System

    1. There are a few antennas available that looked like they would improve performance. While the vendors seemed cagey on exactly (or even typically) how much they improved range, my napkin-and-pencil estimate was that it was going to be challenging to get over 15cm range (to the edges of the antenna if a big loop). The minimum I was looking for was 20 to 30cm, so my recommendation was to keep the system as status quo for now.

      Other avenues I investigated were higher frequency implantable tags, and larger implantable tags. The 13.56 Mhz tags seemed to typically offer a bit better range, and the tiny coil antenna in the rice-grain sized implantable tags doesn’t help either — there are a few larger ones out there (but still small) that ought to work at longer ranges. Again, details on exactly what range were very sparse.

      At this point though the cost per unit became an issue — it couldn’t be significantly more expensive than current deployments.

      At the end of the day it was fun and will probably result in some RFID jewellery or something.

    1. I live near several farms with probably 50K hogs within a mile so I am familiar with it to say the least.
      The biggest issue is labor. Currently they tag the ears with a tag that has a bar code and sometimes are color coded .
      If you have to deal with 10K pigs on a farm you need something that is quick and doesn’t require someone to clean a pig to read its information, ear tags work and are just plastic with a metal pin through the ear. Tell a worker I need pigs 457 thru 516 and they can visually sort out those pigs quicker than anyone could read through hundreds of tags with a reader. The only up side I see to doing it electronically is when you want to quickly record loading and unloading from trucks, and even then you can write down the numbers or enter the numbers in a terminal of some sort.
      I am an EE and I love the electronics field but sometimes old ways are best.

  1. Nedap Poiesz was providing these for dairy cattle back in the 70’s. Back then it was a “responder” (RFID) on a neck harness. It would ID the cow in the milking parlor and monitored how much milk was given, plus it handled feeding stations to provide a mix of feeds based on that individual’s exact point in the lactation cycle of pregnancy – birth – milk provided. It very much optimized milk production by tracking every animal individually, worked well.

  2. Did something similar for a grower and their landscaping division. Started off with an internal tracking project to monitor seed batches in their germination houses, then extended to another project to include a device that is embedded in the individual plant’s plastic container. After almost five years, the customer has determined:

    1. approx 8% internal loss due to (mostly employee) theft.
    2. approx 7% loss due to shipping ‘failures’.
    3. approx 5% loss due to retailers’ (illegal) transfer of plant to another container.
    4. embedded RFID can confuse some large-box retail systems.

      1. @Alan Do you know what WaveLength is ??

        Wavelength (λ) for electromagnetic radiation of frequency 125 KHz in Air is 2.391 km (Kilometer)

        The “bad idea” has nothing at all to do with anything.

  3. Don’t you also have to make sure the RFID tags don’t end up in the final meat products? Last thing you want is reading about consumers chipping their teeth on stray RFID tags.

    1. Pigs 001 to 101 got slaughtered and there’s the corresponding tags in the tag bowl at end of day. Or just implant under a not so delectable piece of meat, so nowhere near the bacon please! Some people will say they are devil pigs with Mark of the beast!

    1. Yeah this is the best current solution, and pretty much what I was comparing it against. My colleague said the pigs didn’t like those much, I wondered if the injectable solution could be implemented on budget with less discomfort to the animals, but unfortunately not.

  4. – Maybe it’s just implated shallow enough or in an area that ‘shouldn’t’ be processed, but how do you keep shards of these from ending up in hotdogs/sausage/dog food?

  5. You’re missing one of the huge markets for these which is in fish (and to a lesser extent wildlife) research. Yes, they’re short range but it’s not hard to get 30cm+ with a relatively low power reader and 1m+ if you really work at it. Check out the EM4095 chip if you’re interested in rolling your own.

    To boost your range look for HDX tags as opposed to FDX as the slower read time probably isn’t a big deal unless you’re tracking runners, racehorses, fish in spillways, etc. Also, tag size is directly related to read range. Look for 23mm tags vs 8-12mm versions for better range or even 32mm if you can find e’m (OregonRFID is a good place to start and the guy who runs it is a hardware hacker at heart).

    1. Oh, that’s interesting — I was wondering what the range of the bigger tags were. 23mm and low read speed is indeed acceptable for this application. Research has moved on, but if I get another request I’ll retry with EM4095. Thanks for the tip!

      I used to do wildlife tagging for threatened species a lifetime ago — we had even lower tech solutions. We would clip off a tiny amount of some part of the animal of negligible biological function (this was carefully considered and tested) in a binary pattern. That way if we catch them again we just needed our eyes to identify them, and we also had a sample for genetic sequencing. Tracking individuals over years this way helped us monitor the health of the population, and determine the conservation status of the species.

  6. Cameras have enough resolution, storage is cheap, could just visually id each animal optically. Its kind of crazy that hardware chip id is cheaper than getting someone to setup optical recognition software.

    1. I wondered about this. But biometrics on pigs might be quite difficult – they won’t be still, they won’t look into the camera, their faces will be dirty, and also they grow much faster than humans.

      1. Doesn’t have to be facial recognition, their whole body is statistically unique. Its how humans herd and sort livestock, which I’ve done with cows and pigs. Even if they are all a solid color without spots you can tell them apart. A camera system could do it, but the software doesn’t exist so we are starting to use the RFID ear tags and dna samples.

        1. For an animal like a pig I wonder if you could identify them by their surface venous pattern. Could be more machine identification friendly. The knowledge of which animal is “frank” and which one is “beans” does not transfer well between humans on opposite sides of a semi truck ride.

  7. Regarding the coding workflow, while tinkering with nodemcu i’ve come up with this:

    it’s a 4kb http server written in lua plus a 4k tiny web ide based on the ace editor, with buttons to restart the board, a small “terminal” and even support for websocket if needed. In this case it could have been used to avoid multiplexing the serial port during development, plus loading the code via wifi is faster. It’s a bit crude in places, but maybe someone could find it complementary to Esplorer

  8. Visual ID was what I was hired to do. They wanted an alternative to fees for the Nedap Poiesz rfid solution and thought it could be done with guernseys as they are white and black patterned. Got it working, but there were two problems. One is the only place on a guernsey that the pattern is reliably unique for every individual is on their butt. That was ok, still worked… but cows lie down in something cool, like mud, to get rid of the heat the ruminating process generates! Meant that instead of a paying guy in the milking parlor to type in the ear tag number of the cow they would now have to hire a guy to wash their butt off! We could still do it… but the goal was to reduce the manpower needs.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.