FruitCheck AI – AI-Based Fruit Identification and Quality Detection
by ArthurMoors in Circuits > Sensors
29 Views, 0 Favorites, 0 Comments
FruitCheck AI – AI-Based Fruit Identification and Quality Detection

In this project, I built a real-time fruit inspection system that uses YOLOv8 segmentation combined with ByteTrack to detect apples and pears, identify defects, and classify each fruit by quality. As fruit passes through the center of the camera’s view on a moving conveyor belt, it's assigned a persistent ID, its defect ratio is calculated, and a freshness label (Fresh, Usable, Partially Spoiled, or Spoiled) is shown live on screen.
A custom-built GUI on a Raspberry Pi displays the video stream, classification results, and live statistics — while the PC handles AI processing and streams the output. The entire system is mounted on a DIY conveyor made from wood, metal, 3D printed parts, and powered by a motor controller.
This tool is perfect for automating quality control in small-scale fruit operations, orchards, or even educational and maker settings. Ready to build your own? Let’s get started!
Supplies









Hardware Components
- Raspberry Pi 4 Model B (4 GB)
- Used to run the GUI, control the motor, and receive the AI stream.
- Buy here
- 12V Power Supply (transformer)
- Powers the motor via the motor controller.
- Buy here
- Motor Controller Board (e.g. BTS7960 43A H-Bridge)
- Controls motor direction and speed with PWM from the Raspberry Pi.
- Buy here
- 12V DC Motor
- A strong motor to drive the conveyor. You can use a geared stepper motor or repurpose an old drill motor.
- Buy here
- 7-Inch HDMI Touchscreen
- Displays the GUI from the Raspberry Pi. Needs both HDMI and USB for touch.
- Buy here
- USB Hub
- Used to connect both the camera and Ethernet cable to your PC through a single hub.
- Buy here
- Trust Tanor 1080p Webcam
- Provides the live feed for fruit detection.
- Buy here
- USB-C Power Supply for Raspberry Pi
- Standard 5V 3A adapter to power your Pi.
- Buy here
Cables & Wiring
- HDMI Cable (for touchscreen)
- Connects the Raspberry Pi to the 7" display. Make sure to get a mini HDMI to full HDMI if you're using a Pi 4.
- Buy here
- USB Cable (for touchscreen touch input)
- Standard USB-A to micro-USB (included if you buy the screen from the link above)
- Buy here
- Jumper Wires
- For connecting Raspberry Pi GPIO pins to the motor driver.
- Buy here
- Motor Wires
- Use thick-gauge wires (e.g. 18 AWG or 16 AWG) for connecting the motor to the controller.
- Buy here
- Power Supply Cable (optional)
- If your 12V transformer doesn't come with a plug or screw terminals, you may need a compatible power cord or adapter.
- You can repurpose an old power cable by cutting and stripping the ends.
- Ethernet Cable (Cat5e or Cat6)
- Connects the Raspberry Pi to your PC for network communication.
- Buy here
- WAGO 221 Connectors
- Recommended for safe, clean, tool-free wiring connections.
- Buy here
- USB-C Extension Adapter (Optional)
- To extend the USB hub cable from your PC to a more accessible spot, use a USB-C male to female adapter combined with a USB-C to USB-C cable.
- Buy here
Materials for Building the Conveyor
You can find most of these materials at do-it-yourself (DIY) stores, hardware shops, or metal/wood specialty stores.
I don’t recommend buying them online, as sizes and sturdiness can vary a lot — it’s best to see and feel the parts in person.
You can find the dimensions for all parts in the photos.
Structural Materials
- 2x Metal L-Rails
- Used to build the main conveyor frame.
- (Make sure they’re straight and drill the holes yourself or let a professional do it.)
- See drawings: Rail 1 & Rail 2
- Wooden Baseplate
- Forms the bottom support for the entire conveyor.
- Dimensions: 1000 × 400 × 2 mm
- See drawing: Baseboard
- 2x Small Wooden Beams (Rectangle + Square)
- Glued together to form the side guides.
- 1 rectangular beam per side (flat on the bottom) 670 × 44 × 8 mm
- 1 square beam per side (glued on top for height) 670 × 15 × 15 mm
- See drawings: Flat wooden beam, Square wooden beam & Wooden guides
- 4x Upright Metal Beams
- Mounted vertically to hold up the electronics enclosure.
- See drawing: Upright metal beams
- 2x Small Horizontal Wooden Blocks
- Screwed between the upright metal beams — support for the enclosure.
- Dimensions: 164 × 24 × 24 mm
- See drawing: Wood support blocks
- Agricultural Velcro Strip
- Used to create the conveyor belt loop.
- The loop should be approximately 78 cm long — it doesn’t need to be exact, as you’ll apply tension manually during assembly.
- Metal Brackets
- Used to hold the wooden side guides tightly in place, without interfering with belt movement.
- See drawing: Metal guards
- Bolts, Nuts, Washers, and Spacers
- Needed to:
- Mount rails to the baseplate
- Secure rollers and beams
- Create clearance between drive cylinder and motor bracket
- Ensure smooth rotation with a nut between rail and roller
- You’ll need a mix of:
- 10 mm screws
- 8 mm bolts and nuts (used in multiple places)
- 4 mm bolts and nuts (for lighter components)
- 8 mm anti-slip washers or spring lock washers (to prevent loosening under vibration)
3D Printed Parts
I’ve included 3MF project files for all 3D printed parts. These are ready to be sliced for your specific printer — just open them in your slicer and adjust the settings as needed. (I use an Ender 3 V3 SE myself.)
- Drive Cylinder
- Holds the motor-side bearing and connects to the motor shaft.
- Idle Cylinder
- Free-rolling; contains 2x 608ZZ bearings.
- Electronics Enclosure
- Holds the Raspberry Pi, screen, camera, and power supply.
- Camera bracket
- Holds the camera in place in the electronics enclosure
For detailed prices and extra purchase links, check the full Bill of Materials (BOM)
Creating the Belt


Cut a loop of agricultural Velcro to the needed length, based on your frame. Stitch it securely into a loop. This forms the actual conveyor belt.
Assembling the Rolls

Clean the support material off your 3D-printed rolls. Then:
- Insert 2 bearings into the idle cylinder (free-rolling one).
- Insert 1 bearing on the non-motor side of the drive cylinder.
Assembling the Conveyor Belt





- Mount one metal rail to the wooden baseplate.
- Attach the idle and drive cylinders to this rail:
- The idle cylinder (2 bearings) goes into the slotted holes.
- The drive cylinder goes on the opposite end.
- Place about 2 spacers between the drive cylinder and the rail on the motor side to align properly.
- Slip the belt over both cylinders.
- Now attach the second rail to the rollers, stretching the belt slightly. Use the slot holes to tension the belt properly.
- Once the second rail is secured, bolt it down to the baseplate.
- Ensure both rails are mounted at the same distance apart to keep the belt aligned.
- Use bolts and nuts to secure everything, including a nut between the rail and rollers to avoid friction.
Mounting the Upward Beams



Attach the upright metal beams to the base frame using bolts and nuts. Then fasten 2 wooden blocks horizontally to these beams, like in the picture—these will support your electronics/camera enclosure above the belt.
Making the Sideguards

To build each sideguard, glue together one rectangular wooden beam and one square wooden beam. The larger, rectangular piece should sit flat on the bottom, and the square piece should be centered and glued directly on top of it — as shown in the photo. Make sure the pieces are aligned straight before letting them dry fully.
Securing the Sideguards in Place


Place the finished sideguards between the metal rails and the moving belt. Then secure them by mounting a metal bracket across the top. Do it like shown in the photo to ensure proper positioning and pressure without interfering with the belt's motion.
Installing & Wiring the Electronics




After printing the electronics enclosure, follow these steps to mount and wire all components:
Mounting Components
- Attach the touchscreen to the front of the case using the pre-drilled holes.
- Insert the 12V power supply through the cable cutout.
- Mount the camera to the top bracket.
- Secure the Raspberry Pi inside the case using the built-in screw holes.
Power and Motor Wiring
- Connect the positive (+) terminal of the 12V power supply to the + screw terminal on the motor driver.
- Connect the negative (-) terminal of the power supply to the - screw terminal on the motor driver.
- Link the GND pin on the motor driver’s yellow header to a ground pin on the Raspberry Pi to share a common ground.
GPIO Connections (Raspberry Pi to Motor Driver)
- IN1 → GPIO17 (Motor direction A)
- IN2 → GPIO27 (Motor direction B)
- EN → GPIO18 (PWM motor speed control)
You can check pinout.xyz to confirm GPIO pin locations for your Pi model. A wiring diagram is included above for clarity.
Camera, Screen, and Network Connections
- Connect the camera and an Ethernet cable to a USB hub inside the enclosure.
- Run the USB hub cable out through the case and plug it into your PC.
- Connect the other end of the Ethernet cable to the Raspberry Pi.
- Connect HDMI from the Pi to the touchscreen, routing it through the case.
- Plug USB from the screen to the Pi to enable touch functionality.
- Power the Raspberry Pi using a USB-C adapter.
Installing the Motor


I'm using a modified drill motor. I screwed a bolt into the 3D-printed cylinder so I can attach the motor chuck like a drill bit. If you use a standard 12V DC or stepper motor, the cylinder is designed to fit most shafts.
In the picture, you can see the threaded insert I screwed into my cylinder — I made it myself using a hangerbolt and an angle grinder to shape one end.
Once connected:
- Mount the motor firmly to the baseplate using a bracket or U-shaped metal strip.
- Ensure alignment with the belt drive and test for proper tension.
Final Assembly and Power Setup


Now that all components are mounted and wired inside the enclosure, it's time to put everything together and get the system ready to run.
Mounting the Electronics Enclosure
- Place the electronics enclosure onto the wooden beams, supported by the metal uprights.
- Make sure it sits firmly and that all cables (HDMI, USB, Ethernet, etc.) are routed cleanly through the designated cutouts.
Power & Connectivity
- Connect the motor wires to Output A on the motor controller board.
- Use WAGO 221 connectors to make safe and clean connections — these are highly recommended for ease of use and reliability.
- Plug the USB hub (connected to the camera and Ethernet) into your PC.
- Power the 12V supply and plug in the Raspberry Pi's USB-C adapter.
With everything assembled and connected, your system is now ready to move on to the next phase: downloading and running the code.
Code Structure Overview
Your repository is organized into the following folders:
- My_Model/ – Contains all training-related scripts and pretrained model files.
- Final_code/ – Contains everything needed to run the real-time system.
- PC/ – AI segmentation, tracking, and streaming scripts: vision.py, videomain.py, network.py
- RPI/ – GUI and motor logic for the Raspberry Pi: main.py, motor.py
- Model/ – Stores the trained YOLOv8 segmentation weights used by the AI: best.pt
Installation & Dependencies
On both PC and Raspberry Pi:
- Clone the repo:
- Install required Python packages:
- On the Raspberry Pi, also install GPIO support:
You may also need to install Tkinter (for the GUI) if it’s not already installed:
Running the PC AI Classifier
On your PC in your terminal, navigate to:
Run:
This script:
- Loads the YOLOv8 model from Final_code/Model/best.pt
- Uses vision.py to segment and classify apples/pears + defects
- Tracks fruit across frames using ByteTrack
- Streams annotated frames over UDP to the Pi for display
Configurable things:
- Change detection confidence or quality thresholds inside vision.py
- Modify IP/port in network.py if needed
Running the Raspberry Pi GUI
On the Pi in your terminal, go to:
Run the GUI:
This script:
- Opens a full-screen interface
- Receives and shows streamed video
- Displays FPS
- Allows motor toggling (calls motor.py)
Note: Make sure the Pi screen and motor driver are wired before launching.
Motor Control Details

Inside Final_code/RPI/motor.py, you can adjust:
- PWM frequency
- Default motor speed (in start_motor())
- Cleanup behavior for GPIO shutdown
Motor functions are triggered from main.py and run via GPIO17, GPIO27, and GPIO18 (PWM).
Training the Model (Already Done)

You don’t have to retrain the model — it’s already trained and included at:
But if you want to try training your own:
- Use your own dataset (YOLOv8 segmentation format).
- Train using the script located at:
- Example command to start training:
After training, take the resulting best.pt file and place it inside:
This will replace the default model with your newly trained one.
If You Retrain: Update the data.yaml Path First
Before running the training script, make sure to update the path to your dataset YAML file.
By default, the script contains:
This is just an example path — it probably won’t match your folder structure.
You need to change it to the actual path where your data.yaml is located. For example:
If you skip this step, the training will fail with a FileNotFoundError.
Once that’s set correctly, you're ready to train your own model.
Final Thoughts
That's it — your AI-powered fruit inspection system is ready to go!
Whether you're using the default model or training your own, this project combines real-world hardware with computer vision in a super practical way. It’s perfect for learning, experimenting, and even scaling into something more advanced.
Don’t be afraid to tweak things, test new ideas, or break something and fix it again — that’s what making is all about.
If you get stuck or have questions, feel free to reach out via the comment section. I’d love to see how your version turns out!
Good luck and have fun building!