The flex sensor glove is a glove that uses a flex sensor attached above each finger to track the bending of the finger and a gyroscope on top of the hand to track rotation. These sensors are read by a microcontroller (Arduino) and then passed onto Unity via serial communication. Unity handles animating and rendering the virtual hand and its interactions with the virtual reality. The exact materials used are listed at the bottom of the page under Resources.

I used a nitrile glove, with the flex sensors hot glued on top. The gyroscope was attached to a perfboard where all the circuitry was soldered onto. The perfboard is then attached to the microcontroller using male header pins.

MPU-6050 gyroscope and accelerometer soldered onto a perfboard
Flex sensors hot glued onto the nitrile glove

Flex Sensors

Flex sensors are a type of variable resistor whose resistance increases as they are bent. For this project I used a 26 kΩ, 2.2" flex sensor.

Flex Sensor, Image source: https://www.sparkfun.com/products/10264
A schematic of the flex sensor in a voltage divider circuit. The output voltage between the two resistors is sent to pin A0 in the figure. A0 is one of the 6 analog input pins on an Arduino. For each of the 5 flex sensors, use a different analog input pin (Pins A0 - A5 for Arduino Uno). Image source: https://learn.sparkfun.com/tutorials/flex-sensor-hookup-guide/all

The location of the flex sensors on the glove were chosen through trial and error. I used 2.2" flex sensors which were fairly short, thus I positioned them such that I could capture the bending of the 2nd knuckle. Capturing the bending of the other knuckles are not as important, as we aren't discriminating between the bending of each knuckle - we are more interested in the bending of the entire finger itself.

A picture of the glove when forming a fist.


I am using a MPU-6050 accelerometer and gyroscope. For this project I am only using the gyroscope, but the code and schematic provided allows for use of the accelerometer as well.

MPU-6050 6-axis accelerometer and gyroscope. Image source: https://www.amazon.ca/HiLetgo-MPU-6050-Accelerometer-Gyroscope-Converter/dp/B01DK83ZYQ

A schematic of the MPU-6050 connected to the Arduino Uno. The SDA and SCL pins on the Arduino was used instead of the A4 and A5 pins. However, I had not realized that these pairs of pins were the same pins (A4 = SDA. A5 = SCL, in other words you cannot use both the A4 and SDA pins at the same time). Thus I was not able to measure the output of one of my 5 flex sensors as there are only 6 analog input pins on the Arduino Uno, 2 of which are used by the MPU-6050, which leaves only 4 analog input pins for the 5 flex sensors. Thus in the future, I would recommend using a board with more analog input pins, a minimum of 7, or the use of a multiplexer. Image source: https://www.electroniclinic.com/mpu6050-arduino-wiring-library-and-code-to-find-the-angle/

Demonstration Video

Presentation Slides

Software and Code

Arduino Code

Download the Arduino code HERE

The Arduino is responsible for reading the outputs of the flex sensors and converting these to the angle that the finger is bent, and reading the outputs of the gyroscope sensor. The Arduino then sends this information through serial communication. Each iteration of the loop() will read the output voltage from each of the 5 flex sensors, and will return the angle bent as the following serial output: Left:Index:11.00 The deliminaters in the string are the ":".The first element corresponds to which hand we are reading from ("Left" in this case"). Note we are only using 1 flex sensor glove for this project, but the code has been written for the use of 2 flex sensor gloves if one wishes; with minimal changes required. The second element corresponds to which part of the hand we are reading from ("Index" in this case refers to the index finger, Another example would be "RotateX" - which corresponds to the rotation about the x-axis). The third element corresponds to the respective value of the previous element. If the previous value was the index finger, this value would be the angle that that finger was bent. If the second element was "RotateX" then this would be the angle that the hand was rotated about the x-axis (in degrees). In this case we have the value "11.0", which all together corresponds to a bending angle of 11 degrees of the left index finger.
The input pins for the flex sensors are set to be from A0-A4 as seen below:
// input pins from the flex sensors
const int THUMB_PIN = A0;
const int INDEX_PIN = A2;
const int MIDDLE_PIN = A1;
const int RING_PIN = A3;
const int PINKY_PIN = A4;
If you would like to change the pins used, these constants can be changed and are found inlines 11-14.
The resistance of the flex sensor and R2 in the voltage divider are entered on lines 18-20:
const float R_DIV = 14000; // Measured resistance of R2 in Ohms
const float NOMINAL_RES = 26000; // resistance when straight
const float BENT_RES = 60000.0; // resistance at 90 deg
These 3 constants should be changed to the corresponding resistances used, if your flex sensor and/or R2 resistor used are different.


Download the Unity project HERE

Unity is responsible for rendering and animating the virtual model of the hand. Creating the virtual simulation in Unity was quite an involved process and this documentation page is not meant to be a tutorial on Unity. Thankfully all the work in Unity has been done for you! I have listed many of the helpful resources I had used under the resources section for the reader to get started with if this is something they wish to modify or change. To use this simulation, unzip the contents of the file and set the the correct serial port for the microcontroller that you are using. This can be done by navigating to the grab.cs file under flex sensor glove\Assets\ and changing line 31:
private string COM_PORT = "COM6";
Here my arduino is on COM6, this value should be changed to the corresponding port of your microcontroller. Afterwards save the file. Next run flex sensor glove.exe.

A screenshot of parent directory of the Unity project, with the file to run circled in red.

Note that this project requires Unity version 2019.4.21f1 Personal and Windows operating system to work.

TinkerCAD demonstrations

TinkerCAD is a great resource for simulating various electronics. I have modified a potentiometer circuit made by Jim Holland on TinkerCAD, to incorporate the use of an Arduino and a battery. A link to these can be found here: Arduino version and Battery version. These can be shown to students, or allow them to build these themselves to explore how a variable resistor can dim an LED.
First click on the "Simulate" button on the bottom left.
Next click on the "Start Simulation" button on the top.
Now the simulation is running. You can interact with the circuit by clicking on the potentiometer and turning it clockwise/counter-clockwise.
Next to explore the use of a voltage divider, I have created a simple voltage divider circuit with the potentiometer. I have the Arduino reading the output voltage and returning the resistance of the potentiometer. This simulation can be found here: voltage divider circuit.
Follow the same steps as above in the previous simulation and afterwards click on the "code" button at the top.
Now click on the "serial monitor" button at the bottom to show the serial output of the Arduino.
Now you will see the serial printout from the Arduino of the resistance values of the potentiometer.