Hi every one hopefully you can help me out
I recently purchased a sharp GP2Y0A21YK0F from adafruit
And I basically wanted it to trigger a servo to go all the way to the right when it was 26 inches a way or roughly 74cm
I made a test code that was essentially a modified version of The example pot but it didn't work
#include <Servo.h>
int IRpin = 1; // analog pin for reading the IR sensor
Servo myservo;
int val;void setup() {
myservo.attach(9);
pinMode (IRpin,INPUT);}
void loop() {
val= analogRead(IRpin);
val = map(val,10,300,0,179);
myservo.write (val);
delay(15);
}
When I tried this sample program it worked
as far as reading the sensor values however I know this code is
just to show you the serial data of the IR sensor
int IRpin = 1; // analog pin for reading the IR sensor
void setup() {
Serial.begin(9600); // start the serial port
}void loop() {
float volts = analogRead(IRpin)0.0048828125; // value from sensor * (5/1024) - if running 3.3.volts then change 5 to 3.3
float distance = 65pow(volts, -1.10); // worked out from graph 65 = theretical distance / (1/Volts)S - luckylarry.co.uk
Serial.println(distance); // print the distance
delay(100); // arbitary wait time.
}
Any help on how I can get the sensor to turn the servo all the way right when its 76cm away would be really appreciated