Skip to the content
2 layers78 × 130 mmLofence, the printed circuit board in 3D

LoFence is a LoRaWAN capable IoT electric fence monitoring system running on the The Things Network.

Size
78 × 130 mm
Copper layers
2
Thickness
1.6 mm
Parts
65
Nets
46
Pads
202
Tracks, vias
403, 49
Pours
2
Routed
Yes
KiCad
KiCad 5 (file 20171130)
Created
25 Mar 2019
Updated
28 Mar 2022

Overview

Lofence is an open-source printed circuit board by kiu, from the kiu/lofence repository on GitHub, published under the MIT licence. It is a 2-layer board of 78 × 130 mm with 65 parts on 46 nets, routed with 403 tracks and 49 vias.

It is built around the ATMEGA328PB-AU and MIC5504-3.3YM5. Its parts include 21 resistors, 14 capacitors, 8 diodes, 8 connectors and 5 ICs. It belongs with the AVR (ATmega, ATtiny) boards of this library.

Main components

2

README

README.md

LoFence

LoFence is a LoRaWAN capable IoT electric fence monitoring system running on the The Things Network.

lofence

Backstory

A friend of mine is herding cattle and sheep on a small scale as a hobby. His setup is quite clever as his property has a creek running through, which enables him to let the animals live quite autonomously with minimal supervision. Unfortunately, he got called by the police a few times due to his sheep pulling a prison break. In theory a low maintenance system, but in reality things do happen. The car battery powering the electric fence energizer runs out of juice, a falling tree branch tears the fence down, or a tractor plows down a pole of the fence.

Obvious solution

We need a monitoring system!

Measuring

There are lots of ways to measure an electric fence. Try to hack the energizer’s built-in fault detection, measure current or do some fancy wave analysis of reflections on the line.

Too complicated for the initial build, let’s keep it simple by measuring voltage. Well, not a little voltage, but all the way up to 12 kV. Difficult, but a voltage divider with an op-amp will do fine. With this setup, we can measure any disconnects on the line between the energizer and the LoFence measuring point, even short circuits after the measuring point. Your mileage may vary though. This setup is heavily dependent on weather conditions, e.g. having dry soil will provide a different readout than after heavy rain.

Connectivity

The more difficult challenge in a rural/agricultural area is connectivity. Cell coverage is quite spotty and of course it requires a monthly payment of some kind. Further, it’s such a 90’s solution to use a GSM module.

A few years ago LoRa appeared on the stage operating in the freely available ISM bands offering low speed, long range communication. Perfect for...sigh...IoT devices like the LoFence. While LoRa is great for point-to-point communication, LoRaWAN got established and offers a full suite of protocols enabling a standardized way to build communication networks based on LoRa. While there are commercial network operators like Sigfox where you have to pay for their services, there is a global initiative called The Things Network to run an open LoRaWAN network that any device can join and use for free. Bingo.

Checking their coverage map of course showed that the area of interest has no gateways in reach, but setting up a simple gateway - in our case a TTIG for ~80 Euro - easily solved the coverage problem. According to their Fair Access Policy our use-case of sending a few bytes of measurement data every few hours is perfectly fitted for their service. Let’s roll.

There are quite a few options to integrate LoRaWAN into your device. From the super cheap RFM95W chipset where your firmware has to do most of the action (e.g. used by the Adafruit Feather), up to the "expensive" turnkey solution like the RN2483 which I chose. It does all the magic and will actively prevent you from breaking ISM band regulations regarding radio utilization. Nice.

Build

The build is quite unspectacular. Spinning up a board with some AVR, put an antenna and the RN2483 on it, a big resistor divider with an op-amp and some resistors, debug LEDs and pin headers, an 18650 battery and a waterproof case. Et voila.

Data Extraction

Having a node reporting its measurements to The Things Network is nice, but actually I want to do something with the data. Like sending an alert.

Extracting the data from TTN is easy, but I did it wrong anyways. First thing I stumbled upon was the HTTP Integration. Everytime an uplink message is received from a node, the HTTP integration will trigger a POST message to a webserver of your choice. Great. So I wrote a Java service on my end to parse these messages and store them in a database for grafana to consume later on. My implementation parses the uplink message, extracts the payload, stores the RSSI, SNR, number of gateways, etc. It can be found here: ttn-http.

Later, I found out that there is a way nicer MQTT Integration, which also includes a ready to use Java implementation. A couple of hours could have been saved here.

The other thing I didn't figure out immediately is the Payload Formats option in the TTN console. It lets you write simple javascript running inside The Things Network to decode your payload data and assign them to key-value pairs. When receiving a message through the HTTP Integration (or MQTT), that message will include the key-value pairs as json for easy consumption. Quite clever and easy to parse.

Nitty-Gritty Details

Checkout the pics and hardware section including BOM, Schematic, PCB layout, firmware, etc.

TTN

If you are inspired by this hack to build a LoRaWAN project on your own and join the The Things Network effort, register on their site and join their maker community on slack.

Parts

65
QtyValueFootprintReferences
8100nFCapacitors_SMD:C_0805_HandSolderingC1, C5, C6, C7, C8, C9, C10, C11
6100kResistors_SMD:R_0805_HandSolderingR7, R10, R16, R17, R18, R21
6MountingHoleMounting_Holes:MountingHole_2.7mm_M2.5MH1, MH2, MH3, MH4, MH5, MH6
5LEDLEDs:LED_0805_HandSolderingD3, D4, D5, D6, D7
5RResistors_SMD:R_0805_HandSolderingR8, R11, R13, R14, R15
21.0uFCapacitors_SMD:C_0805_HandSolderingC2, C3
210M 6KVResistors_ThroughHole:R_Axial_DIN0516_L15.5mm_D5.0mm_P20.32mm_HorizontalR1, R2
210uFCapacitors_SMD:C_1206_HandSolderingC13, C14
21MResistors_SMD:R_0805_HandSolderingR12, R19
2232RResistors_SMD:R_0805_HandSolderingR5, R6
2BAV70LTTO_SOT_Packages_SMD:SOT-23D2, D8
110uFCapacitors_SMD:CP_Elec_4x5.7C4
11M 700VResistors_ThroughHole:R_Axial_DIN0207_L6.3mm_D2.5mm_P10.16mm_HorizontalR3
11uFCapacitors_SMD:C_0805_HandSolderingC12
132768 HzCrystals:Crystal_Round_d3.0mm_VerticalY1
13k9Resistors_SMD:R_0805_HandSolderingR4
147RResistors_SMD:R_0805_HandSolderingR20
14k7Resistors_SMD:R_0805_HandSolderingR9
1868kiu-footprint:U.FLJ7
1ATmega328PB-AUHousings_QFP:TQFP-32_7x7mm_Pitch0.8mmU3
1Battery_Cellkiu-footprint:18650HolderTHTBT1
1DEBUG LEDPin_Headers:Pin_Header_Straight_1x03_Pitch2.54mmJ5
1DEBUG MCUPin_Headers:Pin_Header_Straight_1x04_Pitch2.54mmJ6
1DEBUG RNPin_Headers:Pin_Header_Straight_1x04_Pitch2.54mmJ4
1D_SchottkyDiodes_SMD:D_SMA_HandsolderingD1
1Fence+Measurement_Points:Measurement_Point_Square-SMD-Pad_BigJ1
1Fence-Measurement_Points:Measurement_Point_Square-SMD-Pad_BigJ2
1ISPPin_Headers:Pin_Header_Straight_2x03_Pitch2.54mmJ3
1MCP125xHousings_SSOP:MSOP-8_3x3mm_Pitch0.65mmU5
1MIC5504-3.3YM5TO_SOT_Packages_SMD:SOT-23-5_HandSolderingU2
1Opamp_Dual_GenericHousings_SOIC:SOIC-8_3.9x4.9mm_Pitch1.27mmU1
1PWRPin_Headers:Pin_Header_Straight_1x03_Pitch2.54mmJ8
1RESETButtons_Switches_SMD:SW_SPST_B3SL-1002PSW1
1RN2483kiu-footprint:RN2483_serialU4

More from kiu/lofence

1
  • 2 layers99.7 × 49.5 mmLofence, the printed circuit board in 3D

    Lofence

    kiu/lofence

    LoFence is a LoRaWAN capable IoT electric fence monitoring system running on the The Things Network.

    48 parts142MIT

Similar boards

  • 2 layers52.1 × 37.4 mmConsolizer, the printed circuit board in 3D

    Consolizer

    orangeglo/PS2PSP

    Board to connect a PS2 controller to a PSP 2000 (PSP Consolizer)

    25 parts38GPL-3.0
  • 2 layers30 × 40 mmFlight computer, the printed circuit board in 3D

    Flight computer

    wFairmanOlin/OlinRocketryClub

    Repo for a self-designed flight computer

    38 parts6
  • 2 layers189.6 × 31.8 mmArm interface board panel, the printed circuit board in 3D

    Arm interface board panel

    Roboy/Arm_interface_board

    Board containing all the control units and power distribution for the servos in the arms.

    129 parts1
  • 2 layers102 × 81.5 mmC64pico, the printed circuit board in 3D

    C64pico

    silvervest/c64pico

    This is a tiny emulated C64 running on a Raspberry Pi Pico! Full details of the build can be found at https://www.youtube.com/watch?v=hgLhGpbC6E4

    97 parts86
  • 2 layers58.4 × 34.3 mmSIO2SD, the printed circuit board in 3D

    SIO2SD

    c0pperdragon/SIO2SD

    An Arduino-based floppy drive emulator for the atari 8 bit computers.

    26 parts83
  • 2 layers200 × 100 mmRegalodilara, the printed circuit board in 3D

    Regalodilara

    valerionew/very-good-uc-doggos

    A special graduation present for a special friend. Six microcontrollers in one devboard

    91 parts50
  • 2 layers88.9 × 50.8 mmBLDC BIZ CARD, the printed circuit board in 3D

    BLDC BIZ CARD

    ageppert/Brushless-Motor-Biz-Card

    A brushless motor and driver built in to a business card form-factor for learning and experimenting!

    82 parts38MIT
  • 2 layers67.3 × 54 mmJeep radio, the printed circuit board in 3D

    Jeep radio

    latonita/jeep-canbus

    Projects around CAN BUS in Chrysler Jeep - VES enabler, other small features

    52 parts30MIT

Questions

How big is the Lofence PCB?

It measures 78 × 130 mm and has 2 copper layers, 1.6 mm thick.

What parts does the Lofence use?

65 parts, built around the ATMEGA328PB-AU and MIC5504-3.3YM5. The full list of its parts is on this page, with links to each part's symbol and footprint where PCBKit's library has them.

Where can I download the Lofence KiCad files?

From the kiu/lofence repository on GitHub, at the commit this page was made from: the board is rev_b/hardware/kicad/lofence.kicad_pcb. PCBKit opens the board in the browser, with nothing to install.

Can I use the Lofence design in my own project?

Its repository publishes it under the MIT licence: you may reuse it on that licence's terms (keep the author's notice, and for a copyleft licence share your changes alike).