Skip to content
experience

2 years of LoRa trough sensors on a dairy farm: what I stuffed up so you don't have to

Hamish Turner@hamish_on_the_farm

July 27, 2026 · 3 min read

Kia ora. Not a programmer, just a dairy farmer in the Waikato who got sick of driving round on the quad every morning checking troughs. 400 cows, 28 troughs, 3 tanks. That run took me about an hour and a half before milking, every day, rain or shine.

Two years ago I started teaching myself Arduino off YouTube. Now every trough and tank reports in over LoRaWAN and I get a ping on my phone if one is low. I've stuffed up most things at least once, so here's the list.

The setup

  • A RAK LoRaWAN gateway on the cowshed roof, on The Things Network (the free community one)
  • Heltec LoRa boards for the nodes, 3 lithium AAs each, in IP67 junction boxes from the electrical wholesaler
  • Float switches in the troughs, JSN-SR04T waterproof ultrasonic sensors in the tanks
  • Home Assistant on an old PC in the shed, pulling from TTN over MQTT

Stuff-up 1: ultrasonic in troughs

Started with the ultrasonic sensors in the troughs too. Condensation on the sensor face gave rubbish readings every frosty morning. Then the cows worked out the sensor was there and started licking it. One knocked the whole bracket into the water. Switched the troughs to plain float switches, just "ok" or "low". Cheap, cows can't hurt them, never wrong. The ultrasonics are only on the tanks now, with a little hood over them.

Stuff-up 2: spreading factor

To get range I had everything at SF12. Works over the hills, but at SF12 a tiny message takes over a second of airtime, and TTN's fair use is 30 seconds of uplink airtime per device per day. That's only about 20 messages a day. Fix was getting the gateway higher: up a 6 metre pole on the shed instead of on the roof. Now most nodes sit at SF9 or lower with ADR turned on, and they can report every 15 minutes no worries.

Stuff-up 3: water in the boxes

The first boxes filled with water through the cable gland. Wrong size gland for the cable, so it never sealed. Get glands that match your cable diameter, put a drip loop in the cable so water runs off before it reaches the box, and put a sachet of silica gel inside. The ones I built right have been bone dry for 18 months.

Stuff-up 4: lightning

Lost the gateway in a thunderstorm the first winter. Now there's a surge arrestor on the antenna feed and it's earthed properly to the shed earth. Sparky did that bit, not me.

Stuff-up 5: the alerts

At first only my phone got alerts. Then I was off the farm one day and a trough valve stuck. Now the missus gets them too, which means I get a phone call, which is honestly more reliable than any notification.

Was it worth it?

Yeah. I get that hour and a half back most mornings, I only drive to the troughs that need me. We caught a leaking trough valve in the first month that would've been pumping water into a paddock for weeks. Gateway was about NZ$400, each node about $45-60 all up. Paid for itself in diesel and time the first season.

The boxes are ugly, held together with cable ties and silicone, and I'm proud of every one of them. Happy to answer anything.

Get the best of #raspberry_pi_lab weekly

One email each Monday with the most useful posts. No spam; unsubscribe in one click.

Comments

11

Sign in to join the conversation.

Sign in to comment
Leo Chen 陈立@szhw_leo#8 in Pi Lab
SF9 with gateway on pole is the sweet spot. Also check every node antenna is for 915 MHz band, many cheap board ship with 868 antenna even when board is 915. Range difference is big.
7 net votes
Hamish Turner@hamish_on_the_farm#3 in Pi Lab
bugger, that might be the one at the back paddock that's always flaky. cheers Leo, I'll check it
5 net votes
Nguyễn Minh Hiếu@homelab_hieu#4 in Pi Lab
very good write up. the "ugly but working" boxes are the best kind :) how you get TTN data into Home Assistant, the MQTT integration or webhook?
9 net votes
Hamish Turner@hamish_on_the_farm#3 in Pi Lab
MQTT from TTN into Mosquitto on the shed PC, then HA reads that. took me a weekend and a lot of swearing but it's been sweet as since
3 net votes
Karthikeyan S@karthik_embedded#2 in Pi Lab
Float switch over ultrasonic: correct choice. Simple sensor wins in field only. In pump controllers also we keep a float switch as backup for the pressure sensor, because the float switch never lies.
9 net votes
Matt O'Brien@pi_tinker_matt#1 in Pi Lab
Mate this is brilliant. Cows licking the sensor is the best failure mode I've ever read. And "the missus gets the alerts, which means I get a phone call" is the most reliable monitoring architecture in the world. We'll talk about the rugby another time 😅
3 net votes
Hamish Turner@hamish_on_the_farm#3 in Pi Lab
nah you won't wanna talk about the rugby Matt, trust me eh
2 net votes
Graham Whitfield@greybeard_graham#7 in Pi Lab
Surge protection on the antenna feed, done by an electrician. That is the lesson every farm learns once, and the expensive way. Good man. Cheers, G.
6 net votes
Gwen Albright@gwenprints#4 in Pi Lab
Cows licking the sensor is the best failure mode I've ever read (and I've read many (I collect them)). Also the cable gland lesson is one every outdoor project learns exactly once. Lovely post Hamish.
5 net votes
S. Ramanathan@ramanathan_retd#6 in Pi Lab
Dear Hamish, "Not a programmer, just stubborn" is the most honest job description I have read. Most of the best engineers I worked with were exactly that. With regards, S. Ramanathan
6 net votes
Rhys Llewellyn@rhys_teaches_code2 rep in Pi Lab
Showing this to my Year 10s on Monday. Real-world IoT, with cows, written by someone who taught himself from YouTube. That's the whole lesson right there. Diolch Hamish!
9 net votes