The servo position does make the sensor head hit the LCD at full left and right positions on my Sparki, but I don’t have the range problem you describe.
This is a sketch I wrote that displays the range detected using both static positions and degrees. I used the sparki.ping function for this; what function are you using that returns the incorrect value?
[code]/*******************************************
Servo and Ultrasonic Rangefinder Test
by 8-Bits Updated: 20140223
Move the servo using position functions (left, center, right)
and degrees (-90, 0, +90).
Record the distance value (cm) detected at each of the positions
and display the results on the LCD.
********************************************/
#include <Sparki.h> // include the sparki library
void setup()
{
sparki.servo(SERVO_CENTER); // center the servo
}
int cm = 0;
void loop()
{
sparki.servo(SERVO_LEFT); // position servo left using function
cm = sparki.ping(); // detect the distance of object
if(cm != -1) { // test for valid response
sparki.clearLCD();
sparki.print(“Funct Left: “);
sparki.print(cm);
sparki.println(” cm”);
sparki.updateLCD(); // display test results
delay(5000); }
sparki.servo(SERVO_CENTER); // position servo center using function
cm = sparki.ping(); // detect the distance of object
if(cm != -1) { // test for valid response
sparki.clearLCD();
sparki.print(“Funct Center: “);
sparki.print(cm);
sparki.println(” cm”);
sparki.updateLCD(); // display test results
delay(5000); }
sparki.servo(SERVO_RIGHT); // position servo right using function
cm = sparki.ping(); // detect the distance of object
if(cm != -1) { // test for valid response
sparki.clearLCD();
sparki.print(“Funct Right: “);
sparki.print(cm);
sparki.println(” cm”);
sparki.updateLCD(); // display test results
delay(5000); }
sparki.servo(-90); // set servo to -90 degree position (left)
cm = sparki.ping(); // detect the distance of object
if(cm != -1) { // test for valid response
sparki.clearLCD();
sparki.print(“Posit -90: “);
sparki.print(cm);
sparki.println(” cm”);
sparki.updateLCD(); // display test results
delay(5000); }
sparki.servo(0); // set servo to 0 degree position (forward)
cm = sparki.ping(); // detect the distance of object
if(cm != -1) { // test for valid response
sparki.clearLCD();
sparki.print(“Posit 0: “);
sparki.print(cm);
sparki.println(” cm”);
sparki.updateLCD(); // display test results
delay(5000); }
sparki.servo(90); // set servo to +90 degree position (right)
cm = sparki.ping(); // detect the distance of object
if(cm != -1) { // test for valid response
sparki.clearLCD();
sparki.print(“Posit +90: “);
sparki.print(cm);
sparki.println(” cm”);
sparki.updateLCD(); // display test results
delay(5000); }
delay(1000);
} [/code]