I can get it to spit out ranges from the sensors
however i am unsure of how to get it to change directions based on ranges
or is it that i should us IF statements?
"if" statements are the easiest way. Take a look at a sketch that I did with Ping sensor and servos.
I also recommend the "NewPing" library.
Download Documentation#include <Servo.h>
#define trigPin 8
#define echoPin 9
Servo righteyelid;
Servo lefteyelid;
int pos = 0;
void setup() {
Serial.begin (9600);
righteyelid.attach(50);
lefteyelid.attach(52);
pinMode(trigPin,OUTPUT);
}
void loop() {
int duration, distance;
digitalWrite(trigPin, HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
if (distance <= 10)
{
//Serial.print(distance);
Serial.println("servo on");
righteyelid.write(65);
lefteyelid.write(135);
}
else {
Serial.print(distance);
Serial.println(" cm");
righteyelid.write(95);
lefteyelid.write(96);
}
delay(5);
}