Brazil is an agricultural nation whose process of spraying pesticides is mainly carried out by using aircrafts. However, the use of aircrafts with on-board pilots has often resulted in chemicals being sprayed outside the intended areas. The precision required for spraying on crop fields is often impaired by external factors, like changes in wind speed and direction. To address this problem, ensuring that the pesticides are sprayed accurately, this paper proposes the use of artificial neural networks (ANN) on programmable UAVs. For such, the UAV is programmed to spray chemicals on the target crop field considering dynamic context. To control the UAV ight route planning, we investigated several optimization techniques including Particle Swarm Optimization (PSO). We employ PSO to find near-optimal parameters for static environments and then train a neural network to interpolate PSO solutions in order to improve the UAV route in dynamic environments. Experimental results showed a gain in the spraying precision in dynamic environments when ANN and PSO were combined. We demonstrate the improvement in figures when compared against the exclusive use of PSO. This approach will be embedded in UAVs with programmable boards, such as Raspberry PIs or Beaglebones. The experimental results demonstrate that the proposed approach is feasible and can meet the demand for a fast response time needed by the UAV to adjust its route in a highly dynamic environment, while seeking to spray pesticides accurately.