With the general idea for the patch decided and the sub components outlines, it’s time to start patching.
Starting the project. I have all the hardware I think I’ll need with me.
- A flex sensor
- My arduino with protoboard and prototype shield
- Access to an old ECE kit full of resistors and such
From the product page at sparkfun [http://www.sparkfun.com/products/8606] I got a hold of the sensor’s data sheet and with that applied the flat and flexed resistance values to some voltage divider equations I found on this site [http://protolab.pbworks.com/w/page/19403657/TutorialSensors scroll down a bit] to calculate the voltages that arduino will measure when the sensor is flat and when it is flexed. I just guessed the 1k ohm resistor value, but after chugging through the voltage divider equation, I’ll get around 2.1 volts difference between flat and flexed. That should suffice.
I cobbled together the circuit defined at the site above so I can start working with the arduino. Here’s my fritzing layout:
Taking the voltage divider setup and the AnalogInSerialOut sample sketch in the arduino software I have been able to see how the voltage signal from the flex sensor changes as it’s manipulated. Over the entire range of safe flexibility, the digital values reported from the arduino had a value range from 150 to 600. Since I want a range from 0 to 1024, I’ll remap the values using map() and then send them out as a formatted serial string.
For outputting, my method is super-simple just take the value and print it using Serial.print() in a set format. My printing code is as follows:
Serial.print(' '); // lead with a space Serial.print('F'); // print out value label Serial.print(' '); //another space Serial.print(outputValue); // the int flex value Serial.print(' '); // wow, another space Serial.print('r'); // "newline"
The code above ends up printing out things like ” F 730 ” which can be easily parsed in pure data which is what I’m going to work on next.