Quadcopter Collision Avoidance Using Sharp IR Sensors

This is a moderately easy project which will help you to learn how to interface arduino and sensors with any multirotor flight controller.

Things you need:

  1. Sharp IR Sensors (GP2Y0A02YK0F) x4
  2. Arduino(Any) x1
  3. Jumper Wires
  4. A multirotor

Here’s how it works:

The IR sensor measures the distance between the sensor itself and the object and sends it to the arduino in the form of analog signal (value range: 0 to 1023). We should make a setpoint say 40cm from the IR sensor so if the setpoint reaches below 40cm the PID algorithm in the arduino will start its work by sending out the correction value to the stabilization board.

Most of you know what PPM and PWM signals are and how it is used in RC universe and this is how it is used in our project.

The normal range is 1000us to 2000us and 1500 us is the center or neutral value for roll pitch and yaw. We are going to use only range from 1200us to 1800us since we don’t want to flip the quad if the quad is a bit closer to the wall. You will be having the full control of the Quadcopter. So , When the quadcopter goes near any obstacle the arduino will takeover the controls and moves the quadcopter away from the obstacle .

Step 1: Step 1: Connecting the Arduino, Senors and the Flight Controller

Connect the Sensors, Arduino, Flight controller and RC receiver . Check and double check the connections.

Proceed to the next step where we will be uploading the sketch to the Arduino.

Step 2: Step 2: Uploading the Sketch

You need to add the RC library to your Arduino IDE . You can download the Library From HERE


Download the Code from HERE

After uploading the Sketch open the serial monitor and check if all the sensors readings and the RC values are present

After this final check you are ready to Fly.



    • Growing Beyond Earth Maker Contest

      Growing Beyond Earth Maker Contest
    • Classroom Science Contest

      Classroom Science Contest
    • Games Contest

      Games Contest

    8 Discussions

    sarthak dambare

    3 months ago on Step 2

    Dude code doesn't work....
    What should I do..?
    I ordered 4x sharp ir for this project and seems like it's just a waste..

    1 reply

    2 months ago

    Bro what if I just use 2 sensors with kk 2.1.5 will it work


    1 year ago

    how this work with PIXHAWK


    2 years ago

    I am trying to make quad copter collision avoidance system using adriuno Uno, hc sr04 ultra sonic sensor and kk2 flight controller for my college project plz help me with sketch and connections plz ... Plzz contact me at harishf305@gmail.com

    The robotics fan

    2 years ago

    and also another question. What if you connect a fifth sensor to it the up side. i mean if you fly your drone in doors, it will crash if it touches the ceiling.

    if possible please tell us how to do it.

    If it is OK please give us your Email address to be in touch with you.

    mine is rashedsadeed2012@yahoo.co.uk

    thanks in advance.

    The robotics fan

    2 years ago

    Hey there. I really like your system and i plan on making it. but since i am new to robotics and don't have any idea on how to write codes for the arduino i need some help and i hope you have the answer to my questions

    1. is it OK to use (GP2Y0A21YK0F) sharp sensor, or do i have to modify the code for that?

    2. As shown in the figure you used a flight controller in your schematics, but i am going to build a quadcopter and i am going to use an arduino uno as my flight controller (schematics are found below). So my question is how to connect the system to my arduino (flight controller) once i have made the quadcopter and what modifications do i have to make for the quad's code?

    Your kind response is really appreciated

    Thanks in advance


    Good idea. If your quadcopter crashes into the wrong thing, it is finished. Something like this could greatly increase its life span.