lørdag den 4. april 2015

Retractable landing gear

Ok wanted to share with you this prototype of an automatic retractable landing gear, as always much of the info on-line is always based on people with knowledge of electronics so the information that is given is far out, for a guy like me. Took me a while to figuire it out, but hey, now it works...

Stuff you will need....most of it is found quite cheap on ebay...

HC-SR04 sonar sensor Link
PC Pro Mini Module Atmega168 5V 16M For Arduino Compatible With Nano link
Any old servo you have lying around
Wires or Servo extension cables
FTDI USB TTL serial board adapter module to program the Arduino board link
Find your favourite seller, these are just the first ones that I came across.

Here is how I connected it all together.

You need to download Arduino from here, Choose either the Windows installer or Windows Zip

If you chose windows installer, install the program by running the installer.
If you downloaded the Zip, unpack the program in your desired directory.

Download the following code or save the code at the bottom of the page in a text file  named retracts.ino 

Start arduino, either from the program menu or directly from the folder if you unpacked it from the zip file
Under tools - board choose Arduino Nano w/ ATmega168

Under tools - Programmer choose USBasap
Under tools - Serial Port choose the correct serial port, your FTDI unit must be at this point plugged in the USB with the correct drivers installed.

So far so good, navigate to file - open and navigate to the downloaded code and open.

The code should appear on screen, you can adjust the height in which the servo activates the default is 30 cm, You can use a value of up to 300cm.

Okay now you can program the Arduino board, if all goes well you should see a message upload ok when the process finishes.

Plug in all the components and you should be good to go.

A short video of the system.

The finished product, ready to be mounted

The whole unit seems to function with a small servo, but when testing the unit with a servoless retract the servo does not react. On a standard servo tester the servoless retract function as it should but upon installing in this system it ceases to function. This is probebly some kind of power issue as the retracts require 4.5 ~ 5.5 volts and about 500 - 800 mA to make it function. I have tried connecting the servo to a direct power source and it still won' t work. So if you have any ideas let me know.

Finally figured it out, to make it work with a servoless retract you need two separate power supplies, one for the Arduino unit running on a ubec at 5v and a separate 6v ubec for the servo, they have to share a common ground. So as illustrated you must branch the ground from the servo battery and connect it to the ground in the Arduino circuit to make it run.

/* Auto Landing gear sketch by Benbojangles 2015

This sketch is to allow you to connect your landing gear to an arduino
so that the arduino will trigger the landing gear to activate at a user defined altitude.
I have used a HC-SR04 sensor as sonar which, for me, seems to measure from 0cm-to-300cm, 
depending on your landing gear trigger needs this may not be acceptable and you might want
to research other sonar senors with greater range.

to set trigger altitude change "int trigger_altitude = 30" to your desired alt itude in cm
   The circuit:
    *HC-SR04 Vcc connection attached to +5V Arduino
    *HC-SR04 GND connection attached to gnd Arduino
    *HC-SR04 Trig + Echo connection both attached to digital pin 7

   This example code is in the public domain.

#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 
Servo myservo2;
const int pos1 = 15;    // variable to store the servo position 
const int pos2 =90;
const int pos3 = 165;    // variable to store the servo position 
const int pos4 =90;
//data Pin number of the Arduino:
const int pingPin = 7;
int trigger_altitude = 30; //here we define the height in cm that we want to trigger

void setup() {
  // initialize serial communication:
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo2.attach(8);  // attaches the servo on pin 9 to the servo object

void loop()
  //distance in centimeters:
  long duration, cm;

  // The sensor is triggered by a HIGH pulse of 2 or more microseconds.
  // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
  pinMode(pingPin, OUTPUT);
  digitalWrite(pingPin, LOW);
  digitalWrite(pingPin, HIGH);
  digitalWrite(pingPin, LOW);

  // The same pin is used to read the signal from the sensor: a HIGH
  // pulse whose duration is the time (in microseconds) from the sending
  // of the ping to the reception of its echo off of an object.
  pinMode(pingPin, INPUT);
  duration = pulseIn(pingPin, HIGH);

  // convert the time into a distance
  cm = microsecondsToCentimeters(duration);

 if (cm < trigger_altitude)
 else if (cm > trigger_altitude)


long microsecondsToInches(long microseconds)
  // According to Parallax's datasheet for the sensor, there are
  // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
  // second).  This gives the distance travelled by the ping, outbound
  // and return, so we divide by 2 to get the distance of the obstacle.
  // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
  return microseconds / 74 / 2;

long microsecondsToCentimeters(long microseconds)
  // The speed of sound is 340 m/s or 29 microseconds per centimeter.
  // The ping travels out and back, so to find the distance of the
  // object we take half of the distance travelled.
  return microseconds / 29 / 2;