automate a retractable landing gear

I tried the missing pulse code that you referenced but it is not complete and I am not a programmer so I don't know what to look for. I need something I can copy and paste into a sketch. That makes sense about waiting a second. Look, wait a sec and look again and compare the 2 variables. I guess I'll be learning a new language. haha
The code you referenced is way over my head. Think I could do this with pauses and variables?
 
I think I finally got it. Too late to video today, I'll try tomorrow.
I am using one sensor looking down and slightly aft. I have it set to 24", looking 8 times in 2 seconds.
24" is a little close but it seems to work this way. I don't know if that had something to do with the false triggers or not, but it is working the way it is and I am leaving it. I launch, and the gear goes up. I hover at about 10-12 feet and I get random triggers. I ascend to 50 feet, then 100, and the false triggers stop and the gear stays up. When I descend the quad has to pass 24" then the 8 count in 2 seconds and by that time it is very close to the ground. I have to land very slowly but I probably should be anyway. :)
I'll test it more tomorrow but I think I finally got it.
 
excellent, i want :)
 
well I consider my experiment both a success and a failure.
I got it to work reliably with zero false triggers looking for 2 feet 8 times in 2 seconds
2 feet seems to be the key, I tried all kinds of distances there.
BUT
and there is a big but here, 2 of them,
1. This stuff decreased my flight time by about 25%
2. I lose video at about 100 to 150 feet out.
I don't know anything about shielding and I don't even want to try with my flight time down like that. That is a deal breaker all by itself.
I think it eats the battery because the servos have to hold the gear up, fighting the props. If I could design some kind of latch, where it would mechanically hold itself up with no power, then again at the bottom. But I just don't have that kind of time, I'm done for a while. This project took way too much of my time.
So it's all coming back off and I am going back to stock.It was fun while it lasted.
It was a learning experience and now I know a little something about Arduinos. Think I'll make a rain sensor so my sprinklers don't turn on if it's raining. Stupid stuff like that.
:)
thanks again everyone
 
Can you please share the code please. Would greatly appreciate it. Thanks in advance
 
I believe this was my final edit.
I had to tweak the servo numbers to get the legs to look level when up and almost locked when down.

#include <Servo.h>
Servo servoLeft;
Servo servoRight;
#define echoPin 2
#define trigPin 3
#define MAX_DISTANCE 200
const int MATCH_COUNT = 8; // # of matches for distance we need in a row
int matches = 0; // running count of matches
const long READ_INTERVAL = 250; // how often to take a reading
long nextReading; // time for next reading

void setup() {
servoLeft.attach(5);
servoRight.attach(6);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
nextReading = millis(); // read right away
}

void loop() {
long duration, distance;
// time for a reading?
if ( millis() >= nextReading )
{
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration / 2) / 74; // 74=inches 29=cm

if (distance < 24) { // 160cm=5' 62cm=2' 60"=5' 24"=2'
matches++; // increment count
}
else {
matches = 0; // start over
distance = MAX_DISTANCE;
}
nextReading = millis() + READ_INTERVAL; // set time for next read
}
// if we got MATCH_COUNT in a row
if ( matches >= MATCH_COUNT )
{
servoLeft.write(75); //LANDING
servoRight.write(95);
}
else {
servoLeft.write(170); //FLYING
servoRight.write(0);
}
}
 

Members online

No members online now.

Forum statistics

Threads
143,066
Messages
1,467,358
Members
104,935
Latest member
Pauos31