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

ChatGPT Image 20 jun 2025, 01_41_59.png

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

Flatwoodenbeam.jpg
MetalBeams.jpg
metalguards.jpg
Rail1.jpg
Rail2.jpg
Square wooden beam .jpg
woodenguides.jpg
WoodSupportBlocks.jpg
Baseboard.jpg

Hardware Components

  1. Raspberry Pi 4 Model B (4 GB)
  2. Used to run the GUI, control the motor, and receive the AI stream.
  3. Buy here
  4. 12V Power Supply (transformer)
  5. Powers the motor via the motor controller.
  6. Buy here
  7. Motor Controller Board (e.g. BTS7960 43A H-Bridge)
  8. Controls motor direction and speed with PWM from the Raspberry Pi.
  9. Buy here
  10. 12V DC Motor
  11. A strong motor to drive the conveyor. You can use a geared stepper motor or repurpose an old drill motor.
  12. Buy here
  13. 7-Inch HDMI Touchscreen
  14. Displays the GUI from the Raspberry Pi. Needs both HDMI and USB for touch.
  15. Buy here
  16. USB Hub
  17. Used to connect both the camera and Ethernet cable to your PC through a single hub.
  18. Buy here
  19. Trust Tanor 1080p Webcam
  20. Provides the live feed for fruit detection.
  21. Buy here
  22. USB-C Power Supply for Raspberry Pi
  23. Standard 5V 3A adapter to power your Pi.
  24. Buy here

Cables & Wiring

  1. HDMI Cable (for touchscreen)
  2. 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.
  3. Buy here
  4. USB Cable (for touchscreen touch input)
  5. Standard USB-A to micro-USB (included if you buy the screen from the link above)
  6. Buy here
  7. Jumper Wires
  8. For connecting Raspberry Pi GPIO pins to the motor driver.
  9. Buy here
  10. Motor Wires
  11. Use thick-gauge wires (e.g. 18 AWG or 16 AWG) for connecting the motor to the controller.
  12. Buy here
  13. Power Supply Cable (optional)
  14. If your 12V transformer doesn't come with a plug or screw terminals, you may need a compatible power cord or adapter.
  15. You can repurpose an old power cable by cutting and stripping the ends.
  16. Ethernet Cable (Cat5e or Cat6)
  17. Connects the Raspberry Pi to your PC for network communication.
  18. Buy here
  19. WAGO 221 Connectors
  20. Recommended for safe, clean, tool-free wiring connections.
  21. Buy here
  22. USB-C Extension Adapter (Optional)
  23. 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.
  24. 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

  1. 2x Metal L-Rails
  2. Used to build the main conveyor frame.
  3. (Make sure they’re straight and drill the holes yourself or let a professional do it.)
  4. See drawings: Rail 1 & Rail 2
  5. Wooden Baseplate
  6. Forms the bottom support for the entire conveyor.
  7. Dimensions: 1000 × 400 × 2 mm
  8. See drawing: Baseboard
  9. 2x Small Wooden Beams (Rectangle + Square)
  10. Glued together to form the side guides.
  11. 1 rectangular beam per side (flat on the bottom) 670 × 44 × 8 mm
  12. 1 square beam per side (glued on top for height) 670 × 15 × 15 mm
  13. See drawings: Flat wooden beam, Square wooden beam & Wooden guides
  14. 4x Upright Metal Beams
  15. Mounted vertically to hold up the electronics enclosure.
  16. See drawing: Upright metal beams
  17. 2x Small Horizontal Wooden Blocks
  18. Screwed between the upright metal beams — support for the enclosure.
  19. Dimensions: 164 × 24 × 24 mm
  20. See drawing: Wood support blocks
  21. Agricultural Velcro Strip
  22. Used to create the conveyor belt loop.
  23. The loop should be approximately 78 cm long — it doesn’t need to be exact, as you’ll apply tension manually during assembly.
  24. Metal Brackets
  25. Used to hold the wooden side guides tightly in place, without interfering with belt movement.
  26. See drawing: Metal guards
  27. Bolts, Nuts, Washers, and Spacers
  28. Needed to:
  29. Mount rails to the baseplate
  30. Secure rollers and beams
  31. Create clearance between drive cylinder and motor bracket
  32. Ensure smooth rotation with a nut between rail and roller
  33. You’ll need a mix of:
  34. 10 mm screws
  35. 8 mm bolts and nuts (used in multiple places)
  36. 4 mm bolts and nuts (for lighter components)
  37. 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.)

  1. Drive Cylinder
  2. Holds the motor-side bearing and connects to the motor shaft.
  3. Idle Cylinder
  4. Free-rolling; contains 2x 608ZZ bearings.
  5. Electronics Enclosure
  6. Holds the Raspberry Pi, screen, camera, and power supply.
  7. Camera bracket
  8. 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

20250618_155421274_iOS.jpg
20250618_155446433_iOS.jpg

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

20250618_155635232_iOS.jpg

Clean the support material off your 3D-printed rolls. Then:

  1. Insert 2 bearings into the idle cylinder (free-rolling one).
  2. Insert 1 bearing on the non-motor side of the drive cylinder.

Assembling the Conveyor Belt

20250618_155543236_iOS.jpg
20250618_155707965_iOS.jpg
20250618_155922618_iOS.jpg
20250618_161601385_iOS.jpg
20250618_161906451_iOS.jpg
  1. Mount one metal rail to the wooden baseplate.
  2. Attach the idle and drive cylinders to this rail:
  3. The idle cylinder (2 bearings) goes into the slotted holes.
  4. The drive cylinder goes on the opposite end.
  5. Place about 2 spacers between the drive cylinder and the rail on the motor side to align properly.
  6. Slip the belt over both cylinders.
  7. Now attach the second rail to the rollers, stretching the belt slightly. Use the slot holes to tension the belt properly.
  8. Once the second rail is secured, bolt it down to the baseplate.
  9. Ensure both rails are mounted at the same distance apart to keep the belt aligned.
  10. Use bolts and nuts to secure everything, including a nut between the rail and rollers to avoid friction.

Mounting the Upward Beams

20250619_165837107_iOS.jpg
20250619_165904158_iOS.jpg
20250619_200226052_iOS.jpg

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

20250618_154935611_iOS.jpg

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

20250618_162027083_iOS.jpg
20250618_162112770_iOS.jpg

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

20250619_201719713_iOS.jpg
20250619_191737044_iOS.jpg
wiringDiagram.png
20250619_195536922_iOS.jpg

After printing the electronics enclosure, follow these steps to mount and wire all components:

Mounting Components

  1. Attach the touchscreen to the front of the case using the pre-drilled holes.
  2. Insert the 12V power supply through the cable cutout.
  3. Mount the camera to the top bracket.
  4. Secure the Raspberry Pi inside the case using the built-in screw holes.

Power and Motor Wiring

  1. Connect the positive (+) terminal of the 12V power supply to the + screw terminal on the motor driver.
  2. Connect the negative (-) terminal of the power supply to the - screw terminal on the motor driver.
  3. 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)

  1. IN1 → GPIO17 (Motor direction A)
  2. IN2 → GPIO27 (Motor direction B)
  3. 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

  1. Connect the camera and an Ethernet cable to a USB hub inside the enclosure.
  2. Run the USB hub cable out through the case and plug it into your PC.
  3. Connect the other end of the Ethernet cable to the Raspberry Pi.
  4. Connect HDMI from the Pi to the touchscreen, routing it through the case.
  5. Plug USB from the screen to the Pi to enable touch functionality.
  6. Power the Raspberry Pi using a USB-C adapter.

Installing the Motor

20250619_172643894_iOS.jpg
20250619_202358649_iOS.jpg

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:

  1. Mount the motor firmly to the baseplate using a bracket or U-shaped metal strip.
  2. Ensure alignment with the belt drive and test for proper tension.

Final Assembly and Power Setup

20250619_202816449_iOS.jpg
20250619_202830518_iOS.jpg

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

  1. Place the electronics enclosure onto the wooden beams, supported by the metal uprights.
  2. Make sure it sits firmly and that all cables (HDMI, USB, Ethernet, etc.) are routed cleanly through the designated cutouts.

Power & Connectivity

  1. Connect the motor wires to Output A on the motor controller board.
  2. Use WAGO 221 connectors to make safe and clean connections — these are highly recommended for ease of use and reliability.
  3. Plug the USB hub (connected to the camera and Ethernet) into your PC.
  4. 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:

  1. My_Model/ – Contains all training-related scripts and pretrained model files.
  2. Final_code/ – Contains everything needed to run the real-time system.
  3. PC/ – AI segmentation, tracking, and streaming scripts: vision.py, videomain.py, network.py
  4. RPI/ – GUI and motor logic for the Raspberry Pi: main.py, motor.py
  5. Model/ – Stores the trained YOLOv8 segmentation weights used by the AI: best.pt

Installation & Dependencies

On both PC and Raspberry Pi:


  1. Clone the repo:
git clone https://github.com/howest-mct/2024-2025-projectone-ctai-MoorsArthur.git
cd 2024-2025-projectone-ctai-MoorsArthur
  1. Install required Python packages:
pip install ultralytics opencv-python numpy Pillow
  1. On the Raspberry Pi, also install GPIO support:
sudo apt install python3-rpi.gpio

You may also need to install Tkinter (for the GUI) if it’s not already installed:

sudo apt install python3-tk

Running the PC AI Classifier

On your PC in your terminal, navigate to:

cd Final_code/PC

Run:

python3 main.py

This script:

  1. Loads the YOLOv8 model from Final_code/Model/best.pt
  2. Uses vision.py to segment and classify apples/pears + defects
  3. Tracks fruit across frames using ByteTrack
  4. Streams annotated frames over UDP to the Pi for display

Configurable things:

  1. Change detection confidence or quality thresholds inside vision.py
  2. Modify IP/port in network.py if needed

Running the Raspberry Pi GUI

On the Pi in your terminal, go to:

cd Final_code/RPI

Run the GUI:

python3 main.py

This script:

  1. Opens a full-screen interface
  2. Receives and shows streamed video
  3. Displays FPS
  4. Allows motor toggling (calls motor.py)

Note: Make sure the Pi screen and motor driver are wired before launching.

Motor Control Details

Screenshot 2025-06-20 012500.png

Inside Final_code/RPI/motor.py, you can adjust:

  1. PWM frequency
  2. Default motor speed (in start_motor())
  3. 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)

Screenshot 2025-06-20 012619.png

You don’t have to retrain the model — it’s already trained and included at:

Final_code/Model/best.pt

But if you want to try training your own:

  1. Use your own dataset (YOLOv8 segmentation format).
  2. Train using the script located at:
My_Model/TrainSeg.py
  1. Example command to start training:
python3 TrainSeg.py

After training, take the resulting best.pt file and place it inside:

Final_code/Model/

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:

data="AI-based_fruit_identification_and_quality_detection-2-1/data.yaml"

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:

data="My_Model/data.yaml"

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!