stevetheipad
Posts: 12
Joined: Wed Jul 10, 2013 6:18 pm

Chicken Egg Detector

Tue Jul 16, 2013 8:19 pm

I have three chickens in a small chicken coop in my backyard and am getting a Pi later this month.

For a project I had the idea of setting up my Pi to detect when the chickens have layed an egg and send me an email that this has occurred. The chickens lay in the same spot every day but at different times. I would also need to program it to shut off in the night so when they lay down it does not confuse them for an egg.

My main issue here would be the actual detection of the egg. Any ideas?

PiGraham
Posts: 3940
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Chicken Egg Detector

Tue Jul 16, 2013 8:50 pm

That's an interesting and difficult challenge.
How big an area would you have to cover to detect eggs?
Will the eggs be present when the hens are away?
Will the eggs be on soft materials (straw?)
Will the eggs generally be visible from above?

Some quick thoughts:

Eggs contain water. Maybe the electrical properties of the water in the egg could be detected. 2.4GHz is absorbed by water. Perhaps a 2.4GHz radio signal would be altered enough by an egg to be detectable.

An egg weighs something, and much less than a hen. If you could weigh a laying platform perhaps you could detect when the weight goes up by a hen then down by a hen- an egg.

Eggs have hard shells. Perhaps the shell will reflect ultrasonic pulses more strongly than the nesting material they are in.

White eggs are quite bright and may show up well against straw, but brown eggs would probably be hard to see. Maybe egg shells fluoresce in ultraviolet light.

Freshly laid eggs will be warm. Maybe that warmth can be detected.

It's not going to be easy!

stevetheipad
Posts: 12
Joined: Wed Jul 10, 2013 6:18 pm

Re: Chicken Egg Detector

Tue Jul 16, 2013 8:56 pm

PiGraham wrote:That's an interesting and difficult challenge.
How big an area would you have to cover to detect eggs? Like 10 by 10 inches
Will the eggs be present when the hens are away? Yes
Will the eggs be on soft materials (straw?) Yes, but that is not necessary
Will the eggs generally be visible from above? Yep

Some quick thoughts:

Eggs contain water. Maybe the electrical properties of the water in the egg could be detected. 2.4GHz is absorbed by water. Perhaps a 2.4GHz radio signal would be altered enough by an egg to be detectable.

An egg weighs something, and much less than a hen. If you could weigh a laying platform perhaps you could detect when the weight goes up by a hen then down by a hen- an egg.

Eggs have hard shells. Perhaps the shell will reflect ultrasonic pulses more strongly than the nesting material they are in.

White eggs are quite bright and may show up well against straw, but brown eggs would probably be hard to see. Maybe egg shells fluoresce in ultraviolet light.

Freshly laid eggs will be warm. Maybe that warmth can be detected.

It's not going to be easy!
Yes you have quite a few interesting points. I intended for this to be a basic project so I do not want to purchase a binch of accessories and such so perhaps this isn't the best project to start with.

Knightlorish
Posts: 23
Joined: Fri Jun 21, 2013 4:21 pm
Location: Northumberland, UK.

Re: Chicken Egg Detector

Tue Jul 16, 2013 9:06 pm

Is image detection possible using the Pi camera board? Using a general egg shape of the smallest expected size for a match and searching a monochrome image of the nest box (to disregard colour)? Assuming that the egg isn't completely covered in straw, that is. My hens tend to form a nest shape in the straw and the egg stands out fairly clearly if looking from overhead. You'd need suitable illumination given that nesting boxes are normally dark and perhaps an on/off pressure switch to only look when the hen isn't in the nest box since the light may put them off laying (if they're anything like mine).

I'm keen to do the same for my mailbox which is some distance away from the house and I'd thought of a change in image from the empty mailbox: easier than detecting an egg though - although a clever chap has achieved facial recognition - as included on a main page news item not so long ago.

PiGraham
Posts: 3940
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Chicken Egg Detector

Tue Jul 16, 2013 9:26 pm

Knightlorish wrote:I'm keen to do the same for my mailbox which is some distance away from the house and I'd thought of a change in image from the empty mailbox: easier than detecting an egg though - although a clever chap has achieved facial recognition - as included on a main page news item not so long ago.
White paper fluoresces in UV (maybe brown does too). You could probably make a good mail detector with a few UV LEDs and photodiodes.

User avatar
aTao
Posts: 1093
Joined: Wed Dec 12, 2012 10:41 am
Location: Howlin Eigg

Re: Chicken Egg Detector

Tue Jul 16, 2013 10:23 pm

Technology meets animals = recipe for disaster.
I work on a farm, cows, pigs, chickens, sheep and turkeys. It is bewildering the amount of effort they all must put in to finding new ways to be contrary, sheep in particular seem to have a penchant for finding new ways to die. Chickens are also quite stubbornly unpredictable.
Having said that I would consider either sound (you try laying an egg the size of a beach ball (relative size) without making a racket) or infra-red image. A chicken will be warm but large, a freshly laid egg will be a sharp small(er) image that retains heat for considerably longer than the straw.

BTW, shouldnt chickens roost on a perch rather than in a nesting box?
>)))'><'(((<

stevetheipad
Posts: 12
Joined: Wed Jul 10, 2013 6:18 pm

Re: Chicken Egg Detector

Tue Jul 16, 2013 11:24 pm

aTao wrote:Technology meets animals = recipe for disaster.
I work on a farm, cows, pigs, chickens, sheep and turkeys. It is bewildering the amount of effort they all must put in to finding new ways to be contrary, sheep in particular seem to have a penchant for finding new ways to die. Chickens are also quite stubbornly unpredictable.
Having said that I would consider either sound (you try laying an egg the size of a beach ball (relative size) without making a racket) or infra-red image. A chicken will be warm but large, a freshly laid egg will be a sharp small(er) image that retains heat for considerably longer than the straw.

BTW, shouldnt chickens roost on a perch rather than in a nesting box?
Not always is it a disaster, just have to put in a little more effort to get things working for the creatures. :)

The sound idea is a good one but also my chickens are very chatty and tend to get really loud even when just a squirrel walks by so that may not work. But also laying an egg they get really loud so it may still work.

The infra-red image idea might work but I'm not very experienced in this area so it might be tricky for me.

My chickens have one box for laying and sleeping, it works for our small operation.

PiGraham
Posts: 3940
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Chicken Egg Detector

Wed Jul 17, 2013 6:06 am

If the hens lay in boxes I think you could weigh the boxes.
If a hen weighs 2 - 3 kg and an egg weighs 30 - 40 g and a cheap digital scale (just as an example of feasibility, not a recommendation for a device) has a resolution of 1g and range 5kg it seems possible to detect the difference in time-averaged weight of box, box + hen +egg and box + egg.

Pre-lay:
Delta1 = (Box + hen + egg) - Box
Post lay:
Delta2 = (Box + hen + egg) - (Box +egg)

Delta3 = Delta1 - Delta2 = egg

Measure weights, maybe every few seconds, exclude sudden and compute a rolling average of, say, the last hour. Subtract the average for the previous hour

A simple way to calculate a relatively stable trend value and reduce the effect of short-term variation is to calculate
X0 = a.X0 + (1-a).X1

X0 is the slow stabilised value
X1 is the new sample value
a = 0...1.0.

a close to 1.0 produces a slow response that ignores short-term variation.
Smaller values give a faster reponse more susceptible to erratic signals.

User avatar
aTao
Posts: 1093
Joined: Wed Dec 12, 2012 10:41 am
Location: Howlin Eigg

Re: Chicken Egg Detector

Wed Jul 17, 2013 7:49 am

Trouble with weighing the box is chicken poo and straw gets kicked out.
>)))'><'(((<

PiGraham
Posts: 3940
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Chicken Egg Detector

Wed Jul 17, 2013 8:04 am

aTao wrote:Trouble with weighing the box is chicken poo and straw gets kicked out.
That may not be a problem. Obviously the weight will flutuate. WHat you look for a drop where the hen leaves the box but the weight only drops by (hen-egg). If the hen is likely to leave the box and take an egg weight of straw and poo with it all at once the egg would not be detected, but if smaller amounts are kicked out over time it may still work. You would be measuring the hen weight every time it get on or off the box.

It needs some careful thought and maybe some observations/measurements.

Possible interface
http://jdesbonnet.blogspot.co.uk/2010/1 ... -cost.html

stevetheipad
Posts: 12
Joined: Wed Jul 10, 2013 6:18 pm

Re: Chicken Egg Detector

Thu Jul 18, 2013 7:50 pm

Actually I'm kind of liking the noise detector idea because they do make noise all day but not nearly as loud as when they're laying and it has a lot less room for incorrect detection than some of the other ideas. Plus it should be pretty easy.

Any recommendations for how to set it up?

Barytes
Posts: 1
Joined: Thu Jul 18, 2013 11:48 pm

Re: Chicken Egg Detector

Thu Jul 18, 2013 11:54 pm

I set my children the target of working out when the chickens had gone to bed, but I like the idea of the egg detection using shape recognition. I remember about 20 years ago some clever people I knew writing some software for counting cells and so it should be possible to count eggs in an image, but how?

Having a search around came up with Matlab and OpenCV, but both of these seem very complicated for a relatively simple sounding project - or is it harder than it seems?

Martin

stijn.ghesquiere
Posts: 26
Joined: Sat May 19, 2012 9:44 pm

Re: Chicken Egg Detector

Fri Jul 19, 2013 11:14 am

I've been thinking about making a eggs sensor myself.
I will use a capacity sensor that made to detect soil humidity.
Basically it consists of two small metal plates side to side (laying flat on surface) without making contact. You charge one with 5v or 3.3, whatever, the other is ground. Next you disconnect the loading and measure how low they keep charge. I'm not sure if a raspberry can do this fast enough, an arduino or a PIC processor can do so. You need to measure the very short times it takes to plates to unload.
The principle: you make a capacitor with this and you use the dielectric properties of water to 'store' a electric load. I'm sure you can even measure the size of the egg as larger eggs hold more water.
The actual implementation I'm heading for is to use a raster of metal plates to create what is actually a touch plate that can sense 'x-y' positions. I will use a PIC16f88 to do the actual timings and a serial connection to the raspberry pi to read the data and do things as calibration, position etc. in python.

PiGraham
Posts: 3940
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Chicken Egg Detector

Fri Jul 19, 2013 11:30 am

stijn.ghesquiere wrote:I've been thinking about making a eggs sensor myself.
I will use a capacity sensor that made to detect soil humidity.
Basically it consists of two small metal plates side to side (laying flat on surface) without making contact. You charge one with 5v or 3.3, whatever, the other is ground. Next you disconnect the loading and measure how low they keep charge. I'm not sure if a raspberry can do this fast enough, an arduino or a PIC processor can do so. You need to measure the very short times it takes to plates to unload.
The principle: you make a capacitor with this and you use the dielectric properties of water to 'store' a electric load. I'm sure you can even measure the size of the egg as larger eggs hold more water.
The actual implementation I'm heading for is to use a raster of metal plates to create what is actually a touch plate that can sense 'x-y' positions. I will use a PIC16f88 to do the actual timings and a serial connection to the raspberry pi to read the data and do things as calibration, position etc. in python.
That might work, I know such technology is used for material discrimination, but would the egg be masked by variations in moisture in the straw or variations in the distance to the egg?
How do the sensor conductors stand up to the chicken 'emissions'?
It seems it would take quite a bit of R&D to find out if it's possible (has anyone done it?)

If the eggs could be expected to touch the sense plate I think the chances of success would be much higher than if there is nesting material between.

stijn.ghesquiere
Posts: 26
Joined: Sat May 19, 2012 9:44 pm

Re: Chicken Egg Detector

Fri Jul 19, 2013 12:22 pm

Because of the possible variations like chicken waste, eggs to detector distance and such, I'm going for multiple sensors (aka simple touch screen/array). With for example, a 5x5 array, I have 25 sensor position. I suppose with some tweaking, I should be able to detect eggs. Perhaps even multiple eggs. The setup I've in mind is to use a heat laminator to create a mat with two layers of patches (the x-lines and the y-lines in checkboard layout). On top of that a thin rubber mat to protect both sensors and eggs and on that maybe a little bit of straw. Plastic eggs will not be readily detected, so I can use some of these to make the nests attractive to chickens to lay their eggs.
I'm planning to use copper tape with thin wires to connect the x and y lines of the sensor. Another option is conductive paint.
What I do like of these sensors, is that they are completely isolated, and so should be able to handle moisture and 'chicken poo' without problems like corrosion.

stevetheipad
Posts: 12
Joined: Wed Jul 10, 2013 6:18 pm

Re: Chicken Egg Detector

Fri Jul 19, 2013 11:22 pm

Are there any super cheap ways to measure sound levels with the Pi and easily get the value and use it in a Python script or something?

stevetheipad
Posts: 12
Joined: Wed Jul 10, 2013 6:18 pm

Re: Chicken Egg Detector

Mon Jul 22, 2013 1:06 am

Is that a no?

User avatar
aTao
Posts: 1093
Joined: Wed Dec 12, 2012 10:41 am
Location: Howlin Eigg

Re: Chicken Egg Detector

Mon Jul 22, 2013 3:53 am

stevetheipad wrote:Is that a no?
No, not a "no", more of a busy weekend on my part and maybe the dreaded analog electronics for other people....

For purely sound level I would use a cheap electret mic, minimal pre amp and a low pass filter before an A-D I2C converter. Tehre have been many projects here with such analogue inputs.,
>)))'><'(((<

stevetheipad
Posts: 12
Joined: Wed Jul 10, 2013 6:18 pm

Re: Chicken Egg Detector

Mon Jul 22, 2013 5:06 am

I'm not experienced in electronics at all so I don't know much about that. I was hoping for more of a simple plug into the USB for cheap and use it in a python script.

Twinkletoes
Posts: 210
Joined: Fri May 25, 2012 9:44 pm

Re: Chicken Egg Detector

Mon Jul 22, 2013 9:15 am

Could you feed the chickens with a mix of seeds and RFIDs, and then you'll get eggs with RFIDs built in. Unfortunately you won't be able to distinguish them from chickens...

Seriously though... Methinks an infrared camera would work best, with a motion detection algorithm to find hotspots that cool slowly and don't move.

PiGraham
Posts: 3940
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Chicken Egg Detector

Mon Jul 22, 2013 9:36 am

stevetheipad wrote:I'm not experienced in electronics at all so I don't know much about that. I was hoping for more of a simple plug into the USB for cheap and use it in a python script.
You can use USB for sound-in.
Cheap Webcam with mic
USB headset
USB microphone. The ones I've see are for high quality vocals and pricey.
USB soundcard + microphone (but be careful about signal levels. Some mics are *very* quiet on some soundcards. Good quality versions have mic pre-amps built-in, but are a bit expensive for the hen house.
Last edited by PiGraham on Mon Jul 22, 2013 9:42 am, edited 1 time in total.

PiGraham
Posts: 3940
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Chicken Egg Detector

Mon Jul 22, 2013 9:39 am

Twinkletoes wrote:Could you feed the chickens with a mix of seeds and RFIDs, and then you'll get eggs with RFIDs built in. Unfortunately you won't be able to distinguish them from chickens...

Seriously though... Methinks an infrared camera would work best, with a motion detection algorithm to find hotspots that cool slowly and don't move.
Motion detection isn't very effective at detecting things that change slowly and don't move. ;)
It would be a good solution, but thermal IR cameras are expensive. Near infra-red is no use for detecting body heat. (The Pi Cam with IR block filter removed can just about detect the IR glow of a soldering iron in a dark room).

stevetheipad
Posts: 12
Joined: Wed Jul 10, 2013 6:18 pm

Re: Chicken Egg Detector

Mon Jul 22, 2013 4:44 pm

Okay so a few questions...
1. Will any USB mic that is compatible with Linux work?

2. Do I need to buy a sound card and if so which one?

3. How do I incorporate the loudness into a script?

PiGraham
Posts: 3940
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Chicken Egg Detector

Mon Jul 22, 2013 5:04 pm

Sorry, I can't help you with that, but you may get some leads here:
http://stackoverflow.com/questions/8921 ... -in-python

Or Google https://www.google.co.uk/search?q=linux+sound+detector

Tzarls
Authorised Reseller
Authorised Reseller
Posts: 248
Joined: Tue Feb 26, 2013 6:59 am

Re: Chicken Egg Detector

Mon Jul 22, 2013 5:28 pm

Here´s an idea:

Have a camera point at the nest from above and take a picture every second or so. Divide the pictures in "areas" (small squares) and look for the general color of each area (you might want to round the color value to some preset values). If your eggs are white, then look for how many white areas you´ve got - you might want to check if all white areas are next to each other too. If your chicken are white too then you´ll have to set some kind of count threshold, so for example less than 10 white areas might mean eggs, but more white areas might mean the chicken is on the nest. Alternatively you could attach some kind of device to your chicken so you could actually know when the chicken is away from the nest and start checking for eggs.

Or you could try to teach you chicken to push a button every time they lay an egg. :D

Return to “Automation, sensing and robotics”