Real time motor control with collision avoidance

Just some observations regarding my experiments controlling two motors with ultrasonic crash detection and automatic avoidance, in the case change direction.

Each motor direction and speed is controlled by a Blynk joystick. The Arduino code measure distance from the front and rear ultrasonic sensors and compares the calculations with a limit and increments / decrements a counter so that three consecutive comparisons are required to toggle a crashFlag. When crashFlag is set then the motor direction is reversed.

This works well for one sensor but the sensor handling and reverse override has to be done in the loop. If placed in the Blynk_Write routines the delay in actioning each write is to long, and the vehicle will crash. For two sensors although it works OK the delay between a joystick movement and action becomes a problem.

My only solution I can think of is two add a small ATtiny for sensor processing and just connect to the ESP8266 on two digital pins