Egg Sense
The egg sorter that just makes sense!
GENG 349 FINAL - BREANNA PATZ
Advisor: Dr. Madgy Abdullah-Eissa
Every egg counts. Whether you’re managing a handful of backyard hens or overseeing a full commercial line, it is important to put only your best, most uniform eggs forward, whether that is into an incubator or into the carton. Shape, size, and weight all determine your quality as a seller and even the smallest variations can cut into your bottom line... but when you're forced to hand-sort hundreds of eggs, your accuracy drops, breaks rise, and your most valuable asset - time - goes down the drain. Most farmers still rely on quick visual checks that are inconsistent, error-prone, and impossible to scale. That means higher breakage rates, misgraded eggs, and preventable losses that add up fast.
EggSense eliminates the guesswork.
That’s exactly where this machine steps in. Our automated sorting system delivers commercial-grade precision without the commercial cost. Simply place your eggs by the dozen into the top of the unit, and the system funnels them into a single-file conveyor where a Micro:bit processor captures weight, length, and height through load cell and time-of-flight sensors. Real-time processing then drives a servo-powered diverter that sorts and “grades” each egg quickly and efficiently. All components are enclosed in a durable, custom-designed housing with a light funnel and dual collection bins, creating a compact, reliable egg grader designed to make your life easier.


Engineering Journey
Read about our journey on how EggSense came to be! From initial concepts, to prototyping, we've created a product we can be proud of.
Behind the Scenes
The Problem and Early Stages of Brainstorming

Empathize
As a small-scale farmer or breeder, you need a way to sort eggs quickly, accurately, and with no room for cracks. You may not have the space or budget for a commercial grader, but you still need consistency for graded eggs, hatching, or profit - manual sorting takes too much of your time and leads to mistakes
.
This system is designed for you. It brings automated, reliable egg grading in a simple setup that fits your farm and gives you back your time every day.

Define
Right now, you’re stuck choosing between slow manual checks or equipment built for operations far bigger than yours.
This project sets out to solve that gap by creating a compact system that moves eggs single-file, measures their weight, length, and height with precise sensors, and automatically sorts your eggs. All of it is enclosed in a durable housing as well.
The goal is to replace the inconsistency of visual sorting with a dependable, automated process you can trust.

Ideate
We hear you! The first thing we did was research ideas for the weight, length, and width measurements - the fundamental part of any grade system! The goal became to create a machine with two time-of-flight sensors and one load cell, all powered by a simple MicroBit controller. We also knew it had to be automated and enclosed - no broken eggs to be found.
These initial concepts formed the backbone of a practical, automated grader built just for breeders like you.
On Paper Design
Planning and Sketches Before Starting




Design Logs












11/20/2025
System Design
A preliminary sketch was made. The size was determined, a model of the conveyer belt system was made and sent to the 3D printer.
11/22/2025
Conveyer Assembly
It was determined that paperclips will fit within the link sheath. Spent 3 hours molding paperclip wires and assembling the links. Will need more links for the conveyer, along with wood and motor shaft.
11/25/2025
Conveyer Assembly
More links were 3D printed and assembled. Conveyor belt is now made to size. Research was done into the time-of-flight sensors and programming code is started.
12/08/2025
Conveyer Assembly
Conveyer was sent to the 3D printing lab and should finish tomorrow morning. CAD models were finished for the funnel, and almost finished for the sorter.
12/10/2025
Conveyor Assembly & Code
Stepper motor was attached and wired up properly. Got code set up for the stepper motor. It moves extremely slow, but does turn the conveyor belt. Worked to attach the motor to the main conveyor belt system as the screws are not strong enough.
CAD models were finished for the funnel and sorter and sent to Wyatt, ETA on the print is Friday morning.
12/05/2025
Conveyer Assembly
Wooden conveyor system was assembled. The motor shafts are too flexible - it is not possible to achieve the tension needed on the belt without compromising the motor shafts. Working on a CAD model of a spacer piece to stabilize the structure and keep the belt flat.
12/06/2025
Sensors
Spacer piece was printed and assembled, but the piece doesn't accommodate the TOF sensors. It was decided to create a complete 3D printed conveyer.
TOF sensors were soldered and tested. Both sensors work properly. A new program module, called Rangefinder, was added to the MakeCode directory, and programming was started for the sensors. Program able to display distance on MicroBit.
12/11/2025
Code
Complete code was written up, and preliminary trials of the TOF sensors. Data is logged appropriately. The speed of the conveyor was measured with the initial stepper motor and found to be 1.43 mm/s, which is extremely slow. It takes 3.5 minutes to run an egg through the conveyor if it doesn't get stuck.
Tried running the stepper loop in a separate function and removed the pauses; it sped up the time to 1.63 mm/s. Still incredibly slow but slightly faster.
12/12/2025
Assembly
All parts were finished printed and got assembled. They fit together well. Working on updating code, and added a section to log the eggs on the computer.
12/15/2025
Finishing Touches
Switched motors to a more powerful motor, updated some small pieces in code to accommodate that. Ran wires to the proper places and drilled an additional hole to be able to fit the battery housing. Just fine-tuning details and getting it to run smoothly.

Technical Deep Dive
See exactly what the EggSense is made of. From product specifications to mechanics and software, these are the fine-tuned details.
About the Mechanical Parts
The Muscles Behind the Machine
Final CAD Files:




Materials and Components:
CAD Components:
(All CAD components made from ABS plastic, at 25% - 100% infill)
-Sorter Arm (x1)
-Diverter Base (x1)
-Conveyor Base (x1)
-Funnel (x1)
-Conveyor Links (x125)
-Motor Mounts (x2)
-Gears (x2)
As-Bought Components:
-VL53L0X Time-of-Flight (ToF) Ranging Sensor Breakout 2.8-5V Sensors (x2)
-SG90 Servo Motor (x1)
- DC Motor 3-12VDC 2 Flats Shaft (x1)
-Paperclips (x150)
-0.15" Welding Rod
-9V Battery & Battery Holder (x1)
About the Electrical Parts
The Wiring Behind the Machine
Final Circuit Diagram:
Bill of Materials:
-VL53L0X Time-of-Flight (ToF) Ranging Sensor Breakout 2.8-5V Sensors (x2)
-SG90 Servo Motor (x1)
- DC Motor 3-12VDC 2 Flats Shaft (x1)
-Micro:Bit Controller
-GPIO Extension Board

About the Software
The Brains Behind the Machine
Final Code:

Program Overview:
This program controls an egg sorting machine using two VL53L0X time-of-flight (TOF) sensors and a servo-driven sorting gate. One sensor measures egg width and the other estimates egg length based on belt speed and detection time. Eggs are classified into size categories and sorted accordingly, with results logged to the computer over serial as CSV data.
On Start: System Initialization
At startup, the program initializes all state variables and places the system in a known, safe state. Flags indicating whether an egg is currently being measured (inEggWidth, inEggLength) and whether measurements are complete (widthDone, lengthDone) are set to false. The detection threshold (thresholdChange) is defined in millimeters and represents the minimum change in TOF distance required to detect an egg.
The servo controlling the sorting gate is moved to its neutral position so that eggs initially pass straight through. The system phase is set to Phase 1, meaning the program will begin by measuring egg width.
Both TOF sensors are then read once while the conveyor belt is empty to capture baseline distances (baselineWidth and baselineLength). These baseline values represent the normal distance from the sensor to the belt with no egg present and are used as a reference for detecting when an egg enters and leaves each sensor’s field of view.
To avoid I2C conflicts, only one TOF sensor should be enabled at a time during this process using the XSHUT control pins.
Main Loop:
The forever loop acts as a simple state machine that controls the order of operations. When the system is in Phase 1, the width sensor is read and processed. When the system transitions to Phase 2, the length sensor is read and processed. After each update cycle, the program checks whether both width and length measurements are complete and, if so, classifies the egg and actuates the sorting servo.
ReadWidth:
This function enables the width TOF sensor using its XSHUT control pin while disabling the length sensor to prevent I2C address conflicts. The VL53L0X sensor is then initialized and queried for its current distance reading in millimeters. The measured value is stored in the variable widthDistance.
This function is responsible only for reading the sensor and does not perform any detection or decision logic.
ReadLength:
This function mirrors the behavior of readWidth, but for the length TOF sensor. The width sensor is disabled, the length sensor is enabled, the sensor is initialized, and a distance reading in millimeters is stored in lengthDistance.
As with the width function, this block only handles sensor selection and reading.
UpdateLength:
The updateLength function determines egg length based on how long the egg blocks the length sensor while moving on the conveyor belt. When the system is not currently measuring an egg and the distance changes by more than the threshold, the program records the current runtime as the start time and marks that length measurement has begun
.
While the egg remains under the sensor, no additional action is taken. Once the distance returns close to the baseline, the program records the end time and calculates the duration that the egg was detected. The egg length is then calculated by multiplying this duration by the conveyor belt speed.
All units must be consistent. If the belt speed is defined in millimeters per second and the duration is in milliseconds, the duration must be divided by 1000 before multiplication to avoid a 1000× error.
After calculating the length, the length measurement is marked complete and the system returns to Phase 1 in preparation for the next egg.
UpdateWidth:
The updateWidth function detects when an egg enters, passes under, and exits the width sensor. If the system is not currently tracking an egg, the function compares the current distance reading to the baseline. When the distance changes by more than the defined threshold, the program recognizes that an egg has arrived and begins tracking it.
While the egg is under the sensor, the function continuously updates the stored width measurement, typically keeping the minimum distance observed, which corresponds to the widest part of the egg. When the distance returns close to the baseline value, the program determines that the egg has left the sensor. At this point, the final width measurement is saved, the width measurement is marked as complete, and the system advances to Phase 2 to begin length measurement.
This logic assumes that the presence of an egg causes the measured distance to decrease. If the physical geometry causes distance to increase instead, the comparison logic must be inverted.
ClassifyEgg:
The classifyEgg function runs only after both width and length measurements are complete. It compares the measured values against predefined size ranges to determine the egg category. Based on the classification, the servo is moved to the appropriate angle to direct the egg into the correct output lane.
Once the servo has moved and the egg has been sorted, the program logs the egg data over serial, pauses briefly to allow the egg to clear the gate, and then returns the servo to its neutral position. All measurement flags and temporary variables are reset so the system is ready to process the next egg.
The servo angles used here are specific to the mechanical setup of the sorting gate and are intentionally limited to the 0–40 degree range as measured during calibration.
LogEgg:
The logEgg function outputs one line of CSV-formatted data for each egg.
The format is:
eggID,widthMeasured,lengthMeasured,eggType
Each call increments the egg counter and sends a single line over the serial connection. This format is intended for direct logging into a spreadsheet or data acquisition program on the connected computer.
Conclusion:
The software codes the entire functional automated egg sorting system that integrates time-of-flight sensors, conveyor-based motion, and servo-controlled actuation to measure and classify eggs in real time. A structured state-machine approach allows the system to reliably detect egg presence, estimate egg dimensions, and direct eggs to appropriate output paths while logging data for analysis. Despite hardware limitations associated with multiple sensors on a shared I2C bus, the system provides a solid proof of concept and a strong foundation for future improvements in accuracy, robustness, and scalability.









Acknowledgements
I would like to thank Professor Madgy Abdullah-Eissa for overseeing this project as part of the course

