void loop() {
// put your main code here, to run repeatedly:
int flexSensor=analogRead(A0);
int angle = (flexSensor - 450) / 1;
Serial.println(angle);
myservo.write(angle);
}
How to Calibrate Your Code:
Calibrating your code means making the degrees that your microservo turns higher or lower so that it is more closely aligned to the bending of your flex sensor.
To calibrate your code, we take this line of code: int angle = (flexSensor - 450)/1, and adjust the last two numbers. Open up your Serial Monitor in the top right corner of your screen, and take note of the highest and lowest values. The aim is to find the difference of these numbers, then find a number to divide this by to equal the closest to 180°. This sounds complicated I know, but it helps your finger match your movements perfectly! Remember the numbers will be different for everybody
Watch this video for a detailed explanation of the coding!