

Instead of a potentiometer, I used a stretch sensor just to keep things interesting. It wasn’t really that difficult, besides reading the slightly odd values returned by the sensors. Tom Igoe’s code worked handily after adding a few println commands to compare values between the sensor and mapping function.
Here’s the loop statement snippet I modified for a 4″ sensor. (the values will still be wrong since I broke the sensor and had to fix it):
void loop() {
analogValue = analogRead(analogPin); // read the analog input
pulse = map(analogValue,45,30,minPulse,maxPulse); // convert the analog value
Serial.println(analogValue);
Serial.println(pulse); // to a range between minPulse
// and maxPulse.
// pulse the servo again if rhe refresh time (20 ms) have passed:
if (millis() - lastPulse >= refreshTime) {
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(pulse); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
lastPulse = millis(); // save the time of the last pulse
}
}