Hi! So first of ill try to explain the project I am making. I am building a quadcopter with retractable legs. I am using a sharp IR proximity sensor and just a standard dc motor. As motor controller i am using an H bridge and the arduino Uno. The idea is when the sensor picks up something the legs of the quad go down again, and retracts when nothing is detected. I believe this sensor goes to 80cm so with nothing I mean everything after 80cm. The plan afterwards is to also use the gear switch on my remote to manually rectract the legs but thats for later, first I want to figure this out. Baby steps! After doing research below is the code I came up with. However it doesn’t work, could someone please point me in the right direction or what I did wrong? Thanks in advance!
//Motor one
int enA = 6;
int inA = 2;
int inB = 3;
// Sensor
int sensorPin = 0;
int sensorVal;
void setup() {
pinMode(enA, OUTPUT);
pinMode(inA, OUTPUT);
pinMode(inB, OUTPUT);
}
void loop() {
digitalWrite(inA, LOW);
digitalWrite(inB, HIGH);
sensorVal= analogRead(sensorPin);
if(sensorVal<500)
{
digitalWrite(inB, HIGH);
}
else {
digitalWrite(inA, LOW);
}
}
[code]