Coding + Explanation

Before you enter your code, you have to check your board, processor, and port are connected correctly...

  1. Your board should be: "Arduino Nano"
  2. Your processor should be the one with: "(Old Bootloader)"
  3. Your port the one that says: "USB Serial"

Now you're ready to code!

Here is the code that you will put into your Arduino file:

//Include nServo Library

#include <Servo.h>

Servo myservo;

void setup() {
myservo.attach(9);
pinMode(A0, INPUT_PULLUP);
Serial.begin(9600);
}

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!