Introduction: Flex Sensor Controlled Robot

Hello,

My name is Seth and this robot is a project I worked on in my high school robotics class. This was the first robotics class I have ever taken, so I started the year with no knowledge. By the end of the year, I was able to turn the basic programming skills I picked up to finish a challenging project. I spent about 2 months on this project, but I had had no experience with bluetooth and nothing to guide me with this project. I hope this tutorial will make it easier for even beginners to struggle through this project, or it will give more experienced roboticists inspiration to copy or improve this robot. This video shows me controlling my robot by moving my fingers that have flex sensors attached to the glove.

Supplies

- 2 Flex sensors

- Jumper Wires

- 2 HC-05 Bluetooth Modules

- 2 Breadboards

- A pair of gloves

- A robotic platform (I used a Tetrix Max)

- 2 microcontrollers (I used Arduino Nano and Tetrix Prizm)

- 2 47k Ω resistors

Step 1: Get a Robot

I used a Tetrix Max for this project, but any robot that uses 2 wheel drive would work. A photo of the robot I used is above

Step 2: Communication Between Bluetooth Modules

Prior to this project, the most I had ever used Bluetooth was connecting my phone to my portable speaker. This video explained perfectly how to initiate conversation between the 2 modules and establish their roles as transmitter and receiver. After following this video, the hardware part of the Bluetooth aspect of my robot was complete.

Step 3: Wiring the Flex Sensors

https://learn.sparkfun.com/tutorials/flex-sensor-h...

This website explains how flex sensors work and provides a wiring diagram for how to set them up. There is example code that allows the flex sensor to read values. Attach both flex sensors to the same breadboard.

Step 4: Attach Flex Sensors to Gloves

I used an old pair of soccer goalie gloves because I knew they were never going to be used again. I taped the sensor to the finger of my glove, and wrapped around it with tape a couple of times after to ensure I would get consistent values. The pins of the flex sensor do not always work with jumper wires, so I suggest soldering the jumper wires to the pins, like in the picture above. I used heat shrink to prevent the 2 pins from touching one another. The other picture shows the final product of the glove, or transmitter side of the project. If you are soldering, make sure the jumper wires you attach to the glove on the other hand are long enough to plug into the breadboard when you are wearing them.

Step 5: Transmitter Code (Glove)

By now, you should have a robot, a pair of gloves with wired flex sensors on them, and be able to communicate via Bluetooth between the transmitter (glove) and the receiver (robot). If you have that, you are ready to upload code. Because there are two components of this project, it required 2 separate sets of code; one for the Arduino on the glove with the flex sensors, and one for the robot. I cut certain parts of the example code out so my code is slightly different, but the final code that I uploaded to the flex sensor gloves looks like this:

const int FLEX_PIN = A1; // Pin connected to voltage divider output
const int FLEX_PINO = A2; const float VCC = 4.98; // Measured voltage of Ardunio 5V line const float R_DIV = 47500.0; // Measured resistance of 3.3k resistor const float STRAIGHT_RESISTANCE = 37300.0; // resistance when straight const float BEND_RESISTANCE = 90000.0; // resistance at 90 deg

#include <SoftwareSerial.h> SoftwareSerial Bluetooth(11, 10);

void setup() { pinMode(FLEX_PIN, INPUT); pinMode(FLEX_PINO, INPUT); Bluetooth.begin(9600); Serial.begin(9600); }

void loop() { int leftglove = analogRead(FLEX_PIN); int rightglove = analogRead(FLEX_PINO); Serial.println("leftglove"); Serial.println(leftglove); Serial.println("rightglove"); Serial.println(rightglove); if (leftglove >= 500 && leftglove < 700){ Bluetooth.print('0'); } if (leftglove < 500 && leftglove >= 475){ Bluetooth.print('1'); } if(leftglove < 475 && leftglove >= 450){ Bluetooth.print('2'); } if(leftglove < 450 && leftglove >= 425){ Bluetooth.print('3'); } if(leftglove < 425 && leftglove >= 400){ Bluetooth.print('4'); } if(leftglove < 400 && leftglove >= 375){ Bluetooth.print('5'); } if(leftglove < 375 && leftglove >= 350){ Bluetooth.print('6'); } if(leftglove < 350 && leftglove >= 325){ Bluetooth.print('7'); } if(leftglove < 325 && leftglove >= 300){ Bluetooth.print('8'); } if(leftglove < 300){ Bluetooth.print('9'); } if(rightglove >= 240 ){ Bluetooth.print('a'); } if(rightglove < 240 && rightglove >= 230){ Bluetooth.print('b'); } if(rightglove < 230 && rightglove >= 220){ Bluetooth.print('c'); } if(rightglove < 220 && rightglove >= 210){ Bluetooth.print('d'); } if(rightglove < 210 && rightglove >= 200){ Bluetooth.print('e'); } if(rightglove < 200 && rightglove >= 190){ Bluetooth.print('f'); } if(rightglove < 190 && rightglove >= 180){ Bluetooth.print('g'); } if(rightglove < 180 && rightglove >= 170){ Bluetooth.print('h'); } if(rightglove < 170 && rightglove >= 160){ Bluetooth.print('i'); } if(rightglove < 160){ Bluetooth.print('j'); } }

This code reads values from 2 flex sensors and prints them to the Serial Port so you can see the range of values you receive. It then sends the value across the Bluetooth port. Because the HC-05 sends a certain type of data that can not be received by the other HC-05, I assigned numbers and letters to the range of values I got from each sensor. I then send that number and letter to the robot, where it is received.

Step 6: Receiver Code (Robot)

This code defines the values coming over Bluetooth as strings, and then reads the letter or number. Depending on the letter or number received, the motors move at a different speed. The wheels drive faster the more flexed the sensor is. I use numbers to control the left wheel independently with my left hand, and letters to control the right wheel independently from the left one. This allows me to steer and control the speed of my robot just by moving my fingers.

#include <PRIZM.h> // include PRIZM library
PRIZM prizm; #include <SoftwareSerial.h> SoftwareSerial Bluetooth(9, 2); char leftglove=0; char rightglove=0;

void setup() { Bluetooth.begin(9600); Serial.begin(9600); Serial.println("Hello, world?"); prizm.PrizmBegin(); prizm.setMotorInvert(1,1); }

void loop() { if(Bluetooth.available() > 0){ leftglove = Bluetooth.read(); rightglove = Bluetooth.read(); Serial.println(leftglove); Serial.println(rightglove); }

if (leftglove == '0') { prizm.setMotorPower(1,0); } else if (leftglove == '1') { prizm.setMotorPower(1,11); } else if (leftglove == '2') { prizm.setMotorPower(1,22); } else if (leftglove == '3') { prizm.setMotorPower(1,33); } else if (leftglove == '4') { prizm.setMotorPower(1,44); } else if (leftglove == '5') { prizm.setMotorPower(1,55); } else if (leftglove == '6') { prizm.setMotorPower(1,66); } else if (leftglove == '7') { prizm.setMotorPower(1,77); } else if (leftglove == '8') { prizm.setMotorPower(1,88); } else if (leftglove == '9') { prizm.setMotorPower(1,100); } if (rightglove == 'a') { prizm.setMotorPower(2,0); } else if (rightglove == 'b') { prizm.setMotorPower(2,11); } else if (rightglove == 'c') { prizm.setMotorPower(2,22); } else if (rightglove == 'd') { prizm.setMotorPower(2,33); } else if (rightglove == 'e') { prizm.setMotorPower(2,44); } else if (rightglove == 'f') { prizm.setMotorPower(2,55); } else if (rightglove == 'g') { prizm.setMotorPower(2,66); } else if (rightglove == 'h') { prizm.setMotorPower(2,77); } else if (rightglove == 'i') { prizm.setMotorPower(2,88); } else if (rightglove == 'j') { prizm.setMotorPower(2,100); } }

Step 7: It Works! (Hopefully)

Hopefully your robot is functional at this point. If not, go back through my instructions and make sure you read everything carefully. If it still does not work, try to locate the problem and look up how to fix it. I hope this tutorial helped!