Automatic Retractable landing Gear – DiY

 

 

 

Below is the code:

/*
Automatic Landing Gear Version: 5
by:BarbePramis

ECHO and TRIGGER = PIN7
SERVO = PIN9
SERVO1 = PIN6
*/

#include
#define led 13
int led1 = A0;

Servo myservo;

const int pos1 = 15;
const int pos2 = 176; //Adjust SERVO position HERE

const int pingPin = 7;
int trigger_altitude = 120; // Change Altitude HERE

void setup() {
Serial.begin (9600);
myservo.attach(9);

pinMode(led1, OUTPUT);
}

void loop() {

digitalWrite(led1, HIGH); // turn the LED on (HIGH is the voltage level)
delay(500); // wait for a second
digitalWrite(led1, LOW); // turn the LED off by making the voltage LOW
delay(500); // wait for a second

long duration, cm;

pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);

pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);

cm = microsecondsToCentimeters(duration);
Serial.print(cm);
Serial.print("cm");
Serial.println();

if (cm < trigger_altitude) { myservo.write(pos1); delay(15); digitalWrite(led, LOW); // turn the LED delay(100); } else if (cm > trigger_altitude)
{
myservo.write(pos2);
delay(15);
digitalWrite(led, HIGH); // turn the LED
delay(100);
}

delay(100);

}
long microsecondsToInches(long microseconds)
{
return microseconds / 74 /2;
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;

}

Parts required

2 Nos. Digital Servo (MG995 for big Copter)/ – Alternative

1 No. Ping Sensor

1 set. Tarot landing Gear or Tarot Retractable landing gear

1 No. Arduino Nano

Let me know you have difficulty in making this project.