#include < Servo.h>
//includes the servo library
Servo myservo;
//creates the servo object so you can control the servo through the code
void setup() {
myservo.attach(2);
//attaches the servo to the pin board, number two
pinMode(A0, INPUT_PULLUP);
//configure flex sensor pin
Serial.begin(9600);
}
void loop() {
int flexSensor = analogRead(A0);
int angle = (flexSensor - 400)/1.7;
//Values from sensor are about 400 -> 700; we need to convert this about 0-> 180 to make the servo turn 180 degrees. My code was calibrated with 1.7 but yours may be different so adjust the value in small increments to effectivley calibrate your finger.
Serial.println(angle);
myservo.write(angle);
//Set servo position
}