Unmanned aerial vehicle (UAV) variable-rate spraying technology, as the development direction of aviation for plant protection in the future, has been developed rapidly in recent years. In the actual agricultural production, the severity of plant diseases and insect pests varies in different locations. In order to reduce the waste of pesticides, pesticides should be applied according to the severity of pests, insects and weeds. On the basis of explaining the plant diseases and insect pests map in the target area, a pulse width modulation variable spray system is designed. Moreover, the STMicroelectronics-32 (STM32) chip is invoked as the core of the control system. The system combines with sensor technology to get the prescription value through real-time interpretation of prescription diagram in operation. Then, a pulse square wave with variable duty cycles is generated to adjust the flow rate. A closed-loop Proportional-Integral-Derivative (PID) control algorithm is used to shorten the time of system reaching steady state. The results indicate that the deviation between volume and target traffic is stable, which is within 2.16%. When the duty cycle of the square wave is within the range of 40% to 100%, the flow range of the single nozzle varies from 0.16 L/min to 0.54 L/min. Variable spray operation under different spray requirements is achieved. The outdoor tests of variable spray system show that the variable spray system can adjust the flow rapidly according to the prescription value set in the prescription map. The proportion of actual droplet deposition and deposition density in the operation unit is consistent with the prescription value, which proves the effectiveness of the designed variable spray system.