Fruit sorting system based on STM32
By using a modular fruit sorting system based on STM32 and employing a variety of sensors and actuators, high-precision and stable fruit sorting is achieved, overcoming the shortcomings of traditional sorting systems in terms of accuracy and intelligence, and reducing operational complexity and cost.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Utility models(China)
- Current Assignee / Owner
- SOUTHWEST PETROLEUM UNIV
- Filing Date
- 2025-07-07
- Publication Date
- 2026-06-09
Smart Images

Figure CN224332796U_ABST
Abstract
Description
Technical Field
[0001] This utility model belongs to the field of fruit sorting technology, specifically relating to the design of a fruit sorting system based on STM32. Background Technology
[0002] With the rapid development of agricultural modernization and intelligent manufacturing technologies, the application of automated and intelligent equipment in agricultural production is becoming increasingly widespread. Fruit sorting, as a crucial link in agricultural product processing, cannot meet the demands of large-scale production using traditional manual sorting methods. Manual sorting is not only inefficient and prone to errors, but also relatively costly. Microcontrollers, as the smallest control unit, play a vital role in logistics management, vehicle control, cargo sorting, and safety monitoring, primarily due to their high integration, low power consumption, and flexible programmability.
[0003] Currently, most fruit sorting uses PLC-based automated sorting systems. However, PLC development is not widespread, and designing such systems is more expensive compared to developing with microcontrollers. Fruit sorting systems still need improvement in terms of sorting accuracy, stability, and level of intelligence. Utility Model Content
[0004] The purpose of this invention is to address the shortcomings of existing technologies in terms of sorting accuracy, stability, and intelligence, and to propose a fruit sorting system based on STM32.
[0005] The technical solution of this utility model is: a fruit sorting system based on STM32, including: a main control module, a data display module, a non-standard alarm module, a sorting execution module, a weight detection module, a diameter detection module, a power management module, and a system button module;
[0006] The main control module is connected to the data display module, non-standard alarm module, sorting execution module, weight detection module and diameter detection module through chip pins respectively;
[0007] The power management module is electrically connected to the main control module, data display module, non-standard alarm module, sorting execution module, weight detection module, diameter detection module, and system button module, respectively, and provides power to the main control module, data display module, non-standard alarm module, sorting execution module, weight detection module, diameter detection module, and system button module.
[0008] Preferably, the main control module uses an STM32F103C8T6 microprocessor.
[0009] Preferably, the data display module uses a 0.96-inch OLED display; the SCL pin of the 0.96-inch OLED display is connected to the PA8 pin of the STM32F103C8T6 microprocessor through the timing signal line of the I²C bus; the SDA pin of the 0.96-inch OLED display is connected to the PA9 pin of the STM32F103C8T6 microprocessor through the bidirectional data line of the I²C bus.
[0010] Preferably, the non-standard alarm module uses a low-level triggered active buzzer, which is connected to the PB15 pin of the STM32F103C8T6 microprocessor.
[0011] Preferably, the sorting execution module includes two SG90 servos; the SIG pins of the two SG90 servos are respectively connected to the PA2 and PA3 pins of the STM32F103C8T6 microprocessor.
[0012] Preferably, the weight detection module uses an HX711 integrated digital weighing sensor; the HX711 integrated digital weighing sensor is connected to the PA1 pin of the STM32F103C8T6 microprocessor via the DT pin; the HX711 integrated digital weighing sensor is connected to the PA0 pin of the STM32F103C8T6 microprocessor via the SCK pin.
[0013] Preferably, the diameter detection module uses a TOF10120 laser rangefinder; the SDA pin of the TOF10120 laser rangefinder is connected to the PB13 pin of the STM32F103C8T6 microprocessor; the SCL pin of the TOF10120 laser rangefinder is connected to the PB12 pin of the STM32F103C8T6 microprocessor.
[0014] Preferably, the system button module is connected to pins PB5, PB6, PB7 and PB8 of the STM32F103C8T6 microprocessor.
[0015] The beneficial effects of this utility model are:
[0016] This invention uses an STM32F103C8T6 as the core controller, and utilizes a laser sensor (TOF10120) and a digital weighing sensor (HX711) to detect the diameter and weight of the fruit. The sorting action is executed by a servo motor (SG90). The various parameters of the fruit and the quantity of fruit in the corresponding channel are displayed in real time on an OLED display screen. At the same time, a buzzer alarm is used to alert users to non-standard fruit. Through a modular and hierarchical design, a closed control framework of perception-decision-execution is constructed. Users can set the sorting threshold by pressing a button, which reduces the complexity of operation. Attached Figure Description
[0017] Figure 1 The diagram shown is a structural block diagram of a fruit sorting system based on STM32 provided in Example 1.
[0018] Figure 2 The diagram shown is a pin connection diagram of the STM32C8T6 microprocessor provided in Example 1.
[0019] Figure 3 The diagram shown is a pin connection diagram of a 0.96-inch OLED display screen provided in Example 1.
[0020] Figure 4 The diagram shown is a schematic of the low-level triggered active buzzer provided in Example 1.
[0021] Figure 5 The diagram shown is a schematic of the pin connection of the SG90 servo motor provided in Example 1.
[0022] Figure 6 The diagram shown is a pin connection diagram of the HX711 integrated digital weighing sensor provided in Example 1.
[0023] Figure 7 The diagram shown is a pin connection diagram of the TOF10120 laser rangefinder sensor provided in Example 1.
[0024] Figure 8 The diagram shown is a schematic of the power management module circuit provided in Embodiment 1.
[0025] Figure 9 The figure shown is a schematic diagram of the circuit pins of the system button module provided in Embodiment 1.
[0026] Explanation of reference numerals in the attached diagram: 1—Main control module, 2—Data display module, 3—Non-standard alarm module, 4—Sorting execution module, 5—Weight detection module, 6—Diameter detection module, 7—Power management module, 8—System button module. Detailed Implementation
[0027] Exemplary embodiments of the present invention will now be described in detail with reference to the accompanying drawings. It should be understood that the embodiments shown and described in the drawings are merely exemplary and are intended to illustrate the principles and spirit of the present invention, and are not intended to limit the scope of the present invention.
[0028] Example 1:
[0029] A fruit sorting system based on STM32 microcontrollers is constructed using a modular, layered design concept, building a closed-loop control architecture integrating perception, decision-making, and execution. The perception layer uses sensors to collect the diameter and weight parameters of the fruit in real time, standardizes the collected data, and transmits it to the decision layer. The decision layer uses an STM32 microcontroller to perform data fusion, threshold judgment, and generate corresponding instructions for subsequent processing by the execution layer. The electromechanical drive unit of the execution layer executes the sorting actions according to the instructions transmitted from the decision layer, and, combined with a human-machine interface module, displays current information and provides alarm reminders according to relevant requirements to achieve status feedback and user control. Finally, the system returns to the perception layer for a new cycle. The STM32-based fruit sorting system includes: a main control module 1, a data display module 2, a non-standard alarm module 3, a sorting execution module 4, a weight detection module 5, a diameter detection module 6, a power management module 7, and a system button module 8.
[0030] The main control module 1 is connected to the data display module 2, the non-standard alarm module 3, the sorting execution module 4, the weight detection module 5, and the diameter detection module 6 via chip pins.
[0031] The power management module 7 is electrically connected to the main control module 1, the data display module 2, the non-standard alarm module 3, the sorting execution module 4, the weight detection module 5, the diameter detection module 6, and the system button module 8, respectively, and provides power to the main control module 1, the data display module 2, the non-standard alarm module 3, the sorting execution module 4, the weight detection module 5, the diameter detection module 6, and the system button module 8.
[0032] In this embodiment, the main control module 1 uses an STM32F103C8T6 microprocessor. For example... Figure 2 As shown, the STM32C8T6 microprocessor comes with 37 multi-functional I / O ports, including 16 for PA / PB and 5 for PC / PD / PE. This microprocessor supports dual-channel 12-bit ADC, has a USB 2.0 full-speed interface, and also includes an independent temperature sensor, which can meet the signal acquisition needs of various scenarios. Its hardware design includes a clock management unit, low-power mode, and dual-mode debug interface (SWD / JTAG), which can be adapted to development environments such as Keil / IAR, thereby quickly achieving the deployment of industrial control algorithms.
[0033] In this embodiment, the data display module 2 uses a 0.96-inch OLED display screen, whose structure mainly consists of a substrate, organic functional layers, a carrier transport layer, a radiative recombination layer, and key components such as anode and cathode electrodes. Its photoelectric conversion mechanism is as follows: when the power supply is adjusted to an appropriate voltage, anode holes and cathode charges combine in the light-emitting layer, emitting light. This mechanism gives OLED devices self-emissive characteristics, distinguishing them from traditional backlit display technologies.
[0034] OLED display devices themselves do not have dedicated memory units. Therefore, the 0.96-inch OLED display comes pre-installed with an SSD1306 driver chip. This SSD1306 driver chip comes with a corresponding driver program, which, in practice, allows data transmission by loading into the main control module 1. The 0.96-inch OLED display relies on the SSD1306 driver chip to store display data. The SSD1306 driver chip has 128×64 bytes of storage space. Its physical structure uses a paging mechanism, dividing the entire storage area into eight logical pages. Each page has eight data channels, and each channel has a 128-byte storage unit, thus forming a 128×8×8-byte address space. The pixel array of this display system is arranged in a matrix of 8×8 pixels vertically and 128 pixels horizontally. The SSD1306 chip uses an 8-bit parallel drive mode to control the pixel units, and each refresh operation can process eight vertically arranged pixel units simultaneously. To achieve character display, character acquisition software must convert graphic information into binary dot matrix data. This data is stored in the chip according to a specific address sequence. The chip then scans the memory cells line by line according to a pre-set address pointer and maps the dot matrix information to the corresponding pixel areas via the data bus, thus achieving dynamic character display. The pin information for an OLED display is shown in Table 1.
[0035] Table 1 OLED Display Pin Information
[0036]
[0037] This embodiment uses the I²C bus protocol to achieve master-slave communication. The STM32F103C8T6 microprocessor has a built-in multi-protocol clock architecture, which includes two independent timing control units: I²C and SPI. During hardware connection setup, the serial clock interface (SCL) of the OLED display module is mapped to the timing signal line (SCL) of the I²C bus, and the serial data interface (SDA) is mapped to the bidirectional data line (SDA). This completes the physical interface of the bus protocol layer. This interface scheme effectively simplifies the physical layer interface specification between master and slave devices by utilizing the microcontroller's I²C peripheral resources.
[0038] like Figure 3As shown, the serial clock interface (SCL) of the 0.96-inch OLED display is connected to the PA8 pin of the STM32F103C8T6 microprocessor via the timing signal line (SCL) of the I²C bus; the serial data interface (SDA) of the 0.96-inch OLED display is connected to the PA9 pin of the STM32F103C8T6 microprocessor via the bidirectional data line (SDA) of the I²C bus; the GND pin of the 0.96-inch OLED display is grounded, and the VCC pin of the 0.96-inch OLED display is connected to a 3.3V power supply.
[0039] In this embodiment, the non-standard alarm module 3 uses a low-level triggered active buzzer (with a built-in oscillation circuit), which generates a fixed frequency sound wave through DC power supply. In the drive circuit, a transistor (Q1) constitutes a current amplification unit. When the microcontroller outputs an enable signal, the base current triggers the conduction state. That is, the conduction state of the transistor can be controlled by providing a connection pin signal through the STM32, thereby causing the buzzer to sound. Figure 4 As shown, the base of the transistor in the low-level triggered active buzzer is connected to the PB15 pin of the STM32F103C8T6 microprocessor.
[0040] In this embodiment, the sorting execution module 4 includes two SG90 servo motors. The servo motors mainly consist of a servo disc, a reduction gear set, a position feedback detector, a limit switch, a DC servo motor, and a control circuit board. The servo motor servo control system is built on a pulse width modulation (PWM) signal drive mechanism, and its angular positioning accuracy is linearly mapped to the pulse width parameter of the input signal. The system's control interface is configured with a dedicated signal channel for receiving and parsing PWM command signals. Typical servo motor drive signals have the following characteristic parameter system:
[0041] 1) Timing characteristics: The reference period is set to 20ms (corresponding to a 50Hz frequency), and the effective pulse width range is 0.5-2.5ms (taking a 180° servo as an example).
[0042] 2) Position calibration: A 1.5ms pulse width corresponds to the mechanical center position, and a pulse width deviation of ±0.5ms generates a ±45° angular displacement;
[0043] 3) Control algorithm: By adjusting the duty cycle ( , For effective pulse width, (For periodic purposes) to achieve precise angular positioning, with a positioning resolution of up to (Theoretical value).
[0044] This embodiment employs a closed-loop servo mechanism. When the microcontroller outputs a steady-state PWM signal, the position detection circuit inside the servo (typically a potentiometer or encoder) and the H-bridge drive circuit combine to form a negative feedback loop, thereby fixing the shaft at the target angle. This maintenance state is limited by the static holding torque of the actuator. If the external disturbance torque exceeds the design threshold, the system will experience angular deviation. Without a continuous control signal to maintain the position, the positioning error increases logarithmically over time due to nonlinear friction and load inertia. The pin information for the SG90 servo is shown in Table 2 below.
[0045] Table 2 Servo Pin Information Table
[0046]
[0047] like Figure 5 As shown, the VCC pins of the two SG90 servos are connected to a 5V power supply; the GND pins of the two SG90 servos are grounded; and the SIG pins of the two SG90 servos are connected to the PA2 and PA3 pins of the STM32F103C8T6 microprocessor, respectively.
[0048] In this embodiment, the weight detection module 5 uses an HX711 integrated digital weighing sensor. The HX711 integrated digital weighing sensor (resistance strain gauge weighing sensor) is designed based on a mechanical deformation-electrical signal conversion mechanism. It comes pre-installed with a corresponding driver program. In practice, those skilled in the art can load this driver program into the main control module 1 to achieve data transmission. When the elastic body is loaded, it causes a change in the resistance of the surface strain gauge, and the Wheatstone bridge outputs a microvolt-level differential voltage signal. The HX711AD integrated digital weighing sensor comes pre-installed with a programmable gain amplifier and a 24-bit analog-to-digital converter, enabling signal amplification and high-precision digitization. The pin information of the HX711 integrated digital weighing sensor is shown in Table 3.
[0049] Table 3 Pin Information for HX711 Integrated Digital Weight Sensor
[0050]
[0051] like Figure 6 As shown, the HX711 integrated digital weighing sensor is connected to the PA1 pin of the STM32F103C8T6 microprocessor via the DT pin; the HX711 integrated digital weighing sensor is connected to the PA0 pin of the STM32F103C8T6 microprocessor via the SCK pin.
[0052] In this embodiment, the diameter detection module 6 uses a TOF10120 laser rangefinder sensor. The TOF10120 laser rangefinder sensor works by emitting a laser of a specific frequency using SPAD (single-photon avalanche diode) technology. It calculates the phase difference between the emitted and reflected light waves based on the phase method, and then calculates the distance using a corresponding formula. The TOF10120 laser rangefinder sensor comes with a corresponding driver program. In practice, those skilled in the art can load this driver program into the main control module 1 to achieve data transmission. The pin information of the TOF10120 laser rangefinder sensor is shown in Table 4.
[0053] Table 4 Pin Information for TOF10120 Laser Ranging Sensor
[0054]
[0055] There are two communication methods for laser ranging: serial communication and I²C communication. This embodiment uses I²C communication. In the TOF10120, I²C communication is based on the I²C master-slave protocol for ranging command interaction and data transmission. After the master controller sends a start signal, it transmits a 7-bit device address (0x52) and a write operation bit, triggering the sensor to receive a single measurement command (0x01). After the measurement is completed, the master controller initiates a read request, receiving 16 bits of distance data (highest byte first) and a CRC-8 checksum (polynomial 0x07). If the checksum fails, a retransmission mechanism is triggered.
[0056] After adding a clock stretching function to the communication process, the device can automatically pull the SCL line low to increase the bus idle time, thereby synchronizing internal data processing. Bus timeout detection and CRC check work together to suppress the bit error rate to 1×10. -5 This ensures reliable communication in industrial environments.
[0057] like Figure 7 As shown, the SDA pin of the TOF10120 laser rangefinder is connected to the PB13 pin of the STM32F103C8T6 microprocessor; the SCL pin of the TOF10120 laser rangefinder is connected to the PB12 pin of the STM32F103C8T6 microprocessor; the GND of the TOF10120 laser rangefinder is grounded; and the VCC of the TOF10120 laser rangefinder is connected to a 3.3V power supply.
[0058] In this embodiment, the power management module 7 mainly consists of a power supply and a voltage regulator unit. The power supply uses a 12V high-capacity rechargeable lithium battery, which is lightweight and has stable output current and voltage, meeting the current power supply requirements for fruit sorting. The principle of the voltage regulator module is as follows: Figure 8As shown, the voltage regulator unit supports multiple power inputs, and its output voltage can be switched arbitrarily between 3.3V and 5V. The system designed in this invention also requires voltages of 3.3V and 5V.
[0059] In this embodiment, the system button module 8 serves as the core human-machine interface, enabling system power on / off, reset, and threshold setting for fruit diameter and weight via buttons, preparing for subsequent sorting. The system button module 8 employs a matrix button layout directly connected to the STM32's GPIO ports. It combines an interrupt triggering mechanism with a delay-based jitter reduction method. The delay method utilizes the 5-10ms jitter time generated when buttons are closed or opened to construct a highly reliable command input channel, capable of real-time response to user requests for multi-level dynamic calibration of fruit quality / diameter grading thresholds, start / stop control of the sorting process, and manual debugging mode switching. Figure 9 As shown, the system button module 8 uses a total of four independent buttons: Key1, Key2, Key3, and Key4. Each button has four pins, two of which are directly connected together (e.g., ...). Figure 9 In Key1, pins 1 and 2, and pins 3 and 4, are connected only when the button is pressed. Pin 1 is connected to pin 3 (and pins 2 and 4 are connected) only when the button is pressed. In this embodiment, only one end needs to be connected to the circuit, and the other end needs to be grounded. In this embodiment, the system button module 8 is connected to pins PB5, PB6, PB7, and PB8 of the STM32F103C8T6 microprocessor via four pins.
[0060] In this embodiment, a three-level sorting channel is also designed, which is connected to the SG90 servo motor of the sorting execution module 4. The three-level sorting channels correspond to grade A (poor quality), grade B (good quality), and grade C (excellent quality), respectively.
[0061] The specific working principle and process of this utility model are as follows:
[0062] Turn on the power by pressing the voltage regulator switch on the power management module 7. Use Key1 and Key2 on the system button module 8 to control the cursor position, and Key3 to confirm entry into the threshold setting sub-menu. After entering the threshold setting sub-menu, you can also use the same buttons to set the thresholds for each channel of the three-level sorting channel. After setting the thresholds for each channel, use Key1, Key2, and Key3 to enter the data monitoring interface. At this point, when fruit is placed in the system, the current fruit parameters (diameter and weight) will be displayed. After the data stabilizes, press Key4 to start fruit sorting. Fruits are sorted into the corresponding channels based on their weight and diameter. The flowchart is as follows. Figure 4As shown in Figure 2, the weight detection module 5 measures the weight of the target fruit using a weighing sensor and transmits the data to the main control module 1. The diameter detection module 6 uses a laser sensor to measure the distance difference between itself and the fruit to obtain the fruit's diameter, and then sends the data to the main control module 1. After receiving the signals from the weight detection module and the diameter detection module 6, the main control module 1 processes the signals accordingly and issues instructions to the subsequent data display module 2, non-standard alarm module 3, and sorting execution module 4. After receiving the signal from the main control module 1, the data display module 2 displays the current diameter and weight of the fruit on an OLED screen. After receiving the signal from the main control module 1, the non-standard alarm module 3 uses a buzzer to alert users to non-standard fruits. After receiving the signal from the main control module 1, the sorting execution module 4 controls the different directions of the detection platform by controlling the servo motor, sending the fruit into the corresponding sorting channel, thereby achieving fruit sorting.
[0063] Those skilled in the art will recognize that the embodiments described herein are intended to help the reader understand the principles of this invention, and should be understood that the scope of protection of this invention is not limited to such specific statements and embodiments. Those skilled in the art can make various other specific modifications and combinations based on these technical teachings disclosed in this invention without departing from the essence of this invention, and these modifications and combinations are still within the scope of protection of this invention.
Claims
1. A fruit sorting system based on STM32, characterized in that, include: Main control module (1), data display module (2), non-standard alarm module (3), sorting execution module (4), weight detection module (5), diameter detection module (6), power management module (7) and system button module (8); The main control module (1) is connected to the data display module (2), the non-standard alarm module (3), the sorting execution module (4), the weight detection module (5), and the diameter detection module (6) respectively via chip pins; The power management module (7) is electrically connected to the main control module (1), the data display module (2), the non-standard alarm module (3), the sorting execution module (4), the weight detection module (5), the diameter detection module (6), and the system button module (8), respectively, and supplies power to the main control module (1), the data display module (2), the non-standard alarm module (3), the sorting execution module (4), the weight detection module (5), the diameter detection module (6), and the system button module (8).
2. The fruit sorting system based on STM32 according to claim 1, characterized in that, The main control module (1) adopts an STM32F103C8T6 microprocessor.
3. The fruit sorting system based on STM32 according to claim 2, characterized in that, The data display module (2) uses a 0.96-inch OLED display screen; the SCL pin of the 0.96-inch OLED display screen is connected to the PA8 pin of the STM32F103C8T6 microprocessor through the timing signal line of the I²C bus; the SDA pin of the 0.96-inch OLED display screen is connected to the PA9 pin of the STM32F103C8T6 microprocessor through the bidirectional data line of the I²C bus.
4. The fruit sorting system based on STM32 according to claim 2, characterized in that, The non-standard alarm module (3) uses a low-level triggered active buzzer, which is connected to the PB15 pin of the STM32F103C8T6 microprocessor.
5. The fruit sorting system based on STM32 according to claim 2, characterized in that, The sorting execution module (4) includes two SG90 servos; the SIG pins of the two SG90 servos are respectively connected to the PA2 and PA3 pins of the STM32F103C8T6 microprocessor.
6. The fruit sorting system based on STM32 according to claim 2, characterized in that, The weight detection module (5) uses an HX711 integrated digital weighing sensor; the HX711 integrated digital weighing sensor is connected to the PA1 pin of the STM32F103C8T6 microprocessor through the DT pin; the HX711 integrated digital weighing sensor is connected to the PA0 pin of the STM32F103C8T6 microprocessor through the SCK pin.
7. The fruit sorting system based on STM32 according to claim 2, characterized in that, The diameter detection module (6) uses a TOF10120 laser rangefinder; the SDA pin of the TOF10120 laser rangefinder is connected to the PB13 pin of the STM32F103C8T6 microprocessor; the SCL pin of the TOF10120 laser rangefinder is connected to the PB12 pin of the STM32F103C8T6 microprocessor.
8. The fruit sorting system based on STM32 according to claim 2, characterized in that, The system button module (8) is connected to the PB5, PB6, PB7 and PB8 pins of the STM32F103C8T6 microprocessor, respectively.