I am new to this site. I am new to Arduinos. I have been into it for 2 weeks now.
I am sorry if I put this post in the wrong forum. I wasn't sure if it should be in programming questions, troubleshooting, sensors, or robotics, so I thought I would start with programming.
I am new to programming also, actually I'm not a programmer. I copy and paste and steal and cheat. Then I tweak a little. I am figuring it out but I hit a wall.
I have a quad copter, a drone. I added a retractable landing gear to it and even before I started this project, I knew I wanted to automate it. I wanted to "mod my mod". I added an Arduino Nano and a HC-SR04 ultrasonic sensor. I have the sensor looking down to the ground and when the quad is less than 3 feet from the ground the landing gear comes down.
It works very reliably when it is less than 3 feet from the ground. My problem is when it is hundreds of feet in the air, the landing gear triggers by itself. I found out the ultrasonic sensor is "seeing" my rotor wash, turbulence from the props. I think I need to add something like "look, wait for a second then look again". If the two answers match, then perform an action. Does this make sense?
I don't have a clue how to do this and I don't know where to start. Here?
Here is my code so far, again none of this is mine. I copied and pasted from the internet.
Any help will be greatly appreciated and if you are a programmer and can fix this for me I will fly around Southern California with a banner proclaiming your greatness! for a week or so anyway.
Here's my code, let me know your thoughts...
#include <Servo.h>
Servo servoLeft;
Servo servoRight;
#define echoPin 2
#define trigPin 3
void setup() {
servoLeft.attach(5);
servoRight.attach(6);
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
long duration, distance;
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 < 36) { // 160cm=5' 62cm=2' 60"=5' 24"=2'
servoLeft.write(80);
servoRight.write(90); //LANDING
}
else {
servoLeft.write(180);
servoRight.write(0); //FLYING
}
delay(2000);
}