Need help on connection between Arduino and APM 2.8 for simple Sonar Obstacle avoidance

Hello there,

Currently I am doing a project using APM 2.8 and i wish to add a simple obstacle avoidance system to it using cheap sonar like HC-SR04, i just need the copter to back off when the sonar detects and object in front.

Directly connecting the sonar onto the APM would not be a choice as there is no more space in the memory to accommodate new commands. The only way to do it is to use an external processor/controller like Arduino or raspberry pi. currently i have an Arduino Mega 2560.

What I understand from many hours of reading forums, is that there are a few ways to do it. Either using I2C connection, UART or sending pwm signal to the input on APM like how the RC sends the signal to the APM. But i couldn’t find a guide on how to set up the connection and how to even send and read messages through MAVLink.

Please can anyone guide me on this? Many thanks in advance. :slight_smile:

Regards,
Jack Kee