These instructions guide you to build a DIY payload delivery drone system that can be mounted on your drone/quadcopter and used to deliver a package to any address. The smart, low-cost delivery solution uses GPS to find its destination and then employs an ultrasonic sensor to measure the ground clearance. Depending on your drone capabilities, this payload system can lift up to 2kg freight. A servo motor is used to release the payload at the desired location. This guide also provides a solution to the sensor integration problem. You can integrate GPS, servo, and ultrasonic sensors without any serial interference.
Components
Take the breadboard and affix the Arduino to its one side, as shown in the picture. Now, take the HC-SR04 ultrasonic sensor and attach it to the lower side of the breadboard.
Make the connections as shown in Figure 1. Connect the pins as follows:
Run the following code to check if the ultrasonic sensor is functional.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
/* DIY Drone Instructable that Delivers a Payload */ const int trigPin = 8; //declare pin number for trig pin const int echoPin = 9; //declare pin number for echo pin long duration; int dis; void setup() { pinMode(trigPin, OUTPUT); // declaring trigPin as output pinMode(echoPin, INPUT); // declaring echoPin as input Serial.begin(9600); // serial communication at 9600 baud rate } void loop() { digitalWrite(trigPin, LOW); //intializing trigPin delayMicroseconds(2); // setting trigPin high digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // reading the echoPin duration = pulseIn(echoPin, HIGH); // calculating distance dis= duration*0.034/2; // displaying distance on Serial Monitor Serial.print("Distance: "); Serial.print(dis); Serial.println(" cm"); } |
The Serial Monitor will show the following output:
Take the NEO-6M GPS module and insert its pins into the breadboard.
Make connections as shown in Figure 2. Don’t forget to download TinyGPS++ library if missing. Connect the pins as follows:
Run the following code and check if the GPS sensor is functional. DON’T FORGET to remove the TX pin of GPS module from pin 0 of Arduino; otherwise, your code won’t upload. Once the code is uploaded, first open Serial Monitor; then, connect the TX pin of GPS to pin 0 to view the current location of drone, time, and date.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
/* DIY Drone Instructable that Delivers a Payload */ #include <TinyGPS++.h> static const int RXPin = 0, TXPin = 1; //defining RX and TX pins static const uint32_t GPSBaud = 9600; //defining GPS baud rate TinyGPSPlus gps; void setup(){ Serial.begin(9600); //baud rate Serial.begin(GPSBaud); } void loop(){ while (Serial.available() > 0){ gps.encode(Serial.read()); if (gps.location.isUpdated()){ // Displaying latitude (degrees) Serial.print("Latitude= "); Serial.print(gps.location.lat(), 6); // Longitude in degrees (double) Serial.print(" Longitude= "); Serial.println(gps.location.lng(), 6); // displaying the date Serial.print("Day (DD/MM/YYYY) = "); Serial.print(gps.date.day()); Serial.print("/"); Serial.print(gps.date.month()); Serial.print("/"); Serial.println(gps.date.year()); // Displaying the time Serial.print("Time (HH:MM:SS) = "); Serial.print(gps.time.hour()); Serial.print(":"); Serial.print(gps.time.minute()); Serial.print(":"); Serial.print(gps.time.second()); Serial.println(" UTC"); Serial.println("----------------------------------------"); delay(1000); } } } |
The Serial Monitor will show output:
Now, take a bottle cap to prepare the payload-releasing mechanism. The mechanism itself is simple. You hook the payload on the hairpin inside the bottle cap, and when the servo moves it pulls off the hairpin from the bottle cap, resulting the payload to drop.
Make holes on both sides of the cap. Attach the cap on the lower side of the breadboard, as shown in the pictures.
First, take a hair pin and connect it to the limb of the servo using a staple, as shown in the picture.
Take the servo and attach it under the breadboard such that the hair pin passes through both the holes of the bottle cap.
Connect the Servo with Arduino in the following way, as shown in Figure 3.
It will look like this when you attach the whole system to your drone.
Run the following code to check if the servo is functional.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
/* DIY Drone Instructable that Delivers a Payload */ #include <Servo.h> Servo servo; int angle=10; void setup() { servo.attach(14); //attach PWM pin of sg90 to pin 2 of Arduino servo.write(angle); } void loop(){ for(angle = 180; angle > 10; angle--) { servo.write(angle); delay(25); } } |
Make sure you make all the connections as shown in Figure 4. You’ll integrate the sensors without using SoftwareSerial library. Employing hardware serial ports of your Arduino will minimize serial interference between libraries; hence, eliminating the servo vibration.
Open the Arduino window and paste the following code. In the code, set the desired GPS coordinates (latitude, longitude) where you need to drop off the basket. Once the desired location is added, click Upload. Again, don’t forget to remove the TX pin of GPS from pin 0 before uploading the code.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
/* DIY Drone Instructable that Delivers a Payload */ #include <TinyGPS++.h> #include<Servo.h> //define TX and RX pins for GPS static const int RXPin = 0, TXPin = 1; //defining RX and TX pins of Arduino static const uint32_t GPSBaud = 9600; //defining GPS baud rate TinyGPSPlus gps; //destination to drop payload int des_lat= 33; int des_lng= 73; //declaring pins for ultrasonic sensor const int trigPin = 8; //declare pin number for trig pin const int echoPin = 9; //declare pin number for echo pin long duration; int dis; Servo servoMain; // defining Servo void setup(){ Serial.begin(9600); //baud rate Serial.begin(GPSBaud); //GPS receiving values at Serial0 Serial1.begin(9600); //Ultrasonic receiving values at Serial1 pinMode(trigPin, OUTPUT); // declaring trigPin as output pinMode(echoPin, INPUT); // declaring echoPin as input servoMain.attach(14); // attach servo's PWM to Arduino's digital pin 14 servoMain.write (180); //initializing servo } void loop(){ while (Serial.available() > 0){ gps.encode(Serial.read()); if (gps.location.isUpdated()){ // Displaying latitude (degrees) Serial.print("Latitude= "); Serial.print(gps.location.lat(), 6); // Longitude in degrees (double) Serial.print(" Longitude= "); Serial.println(gps.location.lng(), 6); // displaying the date Serial.print("Day (DD/MM/YYYY) = "); Serial.print(gps.date.day()); Serial.print("/"); Serial.print(gps.date.month()); Serial.print("/"); Serial.println(gps.date.year()); // Displaying the time Serial.print("Time (HH:MM:SS) = "); Serial.print(gps.time.hour()); Serial.print(":"); Serial.print(gps.time.minute()); Serial.print(":"); Serial.print(gps.time.second()); Serial.println(" UTC"); digitalWrite(trigPin, LOW); //intializing trigPin delayMicroseconds(2); // setting trigPin high digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); // reading the echoPin duration = pulseIn(echoPin, HIGH); // calculating distance dis= duration*0.034/2; // displaying distance on Serial Monitor Serial.print("Ground Clearance: "); Serial.print(dis); Serial.println(" cm"); //dropping off payload at desired destination if (gps.location.rawLat().deg== des_lat && gps.location.rawLng().deg==des_lng && dis<=15) { Serial.println("Reached desired location"); Serial.print("Package delivered to: Latitude="); Serial.print(gps.location.lat(), 6); Serial.print(" , Longitude="); Serial.print(gps.location.lng(), 6); Serial.print(" at time:"); Serial.print(gps.time.hour()); Serial.print(":"); Serial.print(gps.time.minute()); Serial.print(":"); Serial.print(gps.time.second()); Serial.println(" UTC"); servoMain.write(20); // Turn Servo Right to 180 degrees } else if (dis>=15) { servoMain.write(180); // Turn Servo Right to 180 degrees } Serial.println("----------------------------------------------------------------------------------------"); delay(1000); } } } |
Upload the code on your Arduino and click the Serial Monitor icon in the top right corner. You’ll see the current GPS coordinates of your drone. Let your drone fly to the desired location.
When your drone reaches the desired address, bring it closer to the ground. The ultrasonic sensor will calculate the ground clearance. When it’s about 15 cm, the servo releases the payload. The serial monitor prompts you when the package is delivered, and records the time as well.
After dropping the payload, fly your drone back to its initial point.
Precaution
DO NOT put more than 2 kg load in the basket otherwise it will damage the assembly. Also be sure to check the spec of your drone so you will know how much weight that drone can handle.