Tutorial: Flex Sensor with Arduino

On this tutorial, we will use the Arduino to read a flex sensor. The flex sensor is a device that changes its resistance proportional to its form, like this:

If the sensor is straight, it outputs 30k, it is flexed, 50k. With an Arduino board, make this circuit:

The resistor makes a voltage divider to make the reading possible. The analog input A0 is our signal.

Open the Arduino IDE and upload the following code. This code shows how many degrees the sensor is flexed.

// Flex sensor test program

// Mike Grusin, SFE, 2011
// This program is free, use it however you wish!

// HARDWARE:
// Make the following connections between the Arduino and the flex sensor
// Note that the flex sensor pins are interchangeable

// Sensor pin - GND
// Sensor pin - Analog In 0, with 10K resistor to +5V

// INSTRUCTIONS:
// Upload this sketch to your Arduino, then activate the Serial Monitor
// (set the Serial Monitor to 9600 baud)

void setup()
{
    // initialize serial communications
    Serial.begin(9600); 
}

void loop()
{
    int sensor, degrees;

    // read the voltage from the voltage divider (sensor plus resistor)
    sensor = analogRead(0);

    // convert the voltage reading to inches
    // the first two numbers are the sensor values for straight (768) and bent (853)
    // the second two numbers are the degree readings we'll map that to (0 to 90 degrees)
degrees = map(sensor, 768, 853, 0, 90);
    // note that the above numbers are ideal, your sensor's values will vary
    // to improve the accuracy, run the program, note your sensor's analog values
    // when it's straight and bent, and insert those values into the above function.

    // print out the result
    Serial.print("analog input: ");
    Serial.print(sensor,DEC);
    Serial.print(" degrees: ");
    Serial.println(degrees,DEC);

    // pause before taking the next reading
    delay(100); 
}

Upload the code and open the serial monitor to see the results.

That's it!

References:

http://www.sparkfun.com/products/10264

http://www.sparkfun.com/datasheets/Sensors/Flex/flex22.pdf

http://www.sparkfun.com/tutorials/270

Views: 4229

Tags: arduino, flex, sensor, tutorial

Comment

You need to be a member of GarageLab (arduino, electronics, robotics, hacking) to add comments!

Join GarageLab (arduino, electronics, robotics, hacking)

Latest Activity

Christian Rheinnecker posted a status
1 hour ago
Christian Rheinnecker posted a status
1 hour ago
Shannon Bradley replied to Dennis Melamed's discussion Little Gem Amp Circuit problems
"Im not sure why people turn to IC's for sound or power. I had this little amp kicking around…"
17 hours ago
GarageLab posted blog posts
21 hours ago
Profile IconWoodison Germain, Weerapong Saipetch, Jasmin Ouellet and 8 more joined GarageLab (arduino, electronics, robotics, hacking)
22 hours ago
Numato Lab updated their profile
yesterday
Mark Harrison commented on Thulana Vimukthi's blog post GPS GUIDED AUTONOMOUS ROBOT
"Thulana, very excellent project! It is especially nice, as the hardware connections are relatively…"
yesterday
GarageLab posted a blog post

Make your Thor's Hammer

Rather than being a benign foam hammer, this Mjölnir can summon 80,000 volts of electricity thanks…See More
Wednesday
Profile IconMatthew Brown, David Shepard, Numato Lab and 3 more joined GarageLab (arduino, electronics, robotics, hacking)
Wednesday
Terry Ford updated their profile
Wednesday
GarageLab posted blog posts
Tuesday
Profile Icon►Shannon Code, salomão soares, Jeremy Nelson and 5 more joined GarageLab (arduino, electronics, robotics, hacking)
Tuesday
Paul hunt updated their profile
Tuesday
Terry White replied to Milton Vilela's discussion Firmware GRBL + CNC milling machine -> 3D Printer
"you can add a touch probe to cnc to digitize an object, just limited to issues with undercuts."
Tuesday
Shannon Bradley replied to Milton Vilela's discussion Firmware GRBL + CNC milling machine -> 3D Printer
"  Ya Terry,  Sorry, I don't know why I added CNC to 3D? above. A bit too far out of…"
Monday
Terry White replied to Milton Vilela's discussion Firmware GRBL + CNC milling machine -> 3D Printer
"if you could just use the spindle on/off to control a secondary arduino to run the extruder…"
Monday
Profile IconDavid Romero, Terry White, Kevin Reeve and 4 more joined GarageLab (arduino, electronics, robotics, hacking)
Monday
MrBurritoMan updated their profile
Sunday
Christian Rheinnecker posted a video

Arduino PrX : Sequencer AM808 VX3 - Video Update 12.05.2013 - New Mixer Engine

Neue Mixer Engine mit weniger Quellcode. New mixer engin with better sourcecode. Weiter Infos auf http://arduinoprx.de
Sunday
Christian Rheinnecker posted a status
"https://www.youtube.com/watch?v=awh2bSPhwGU New mixer engine with better sourcecode. Info @…"
Sunday

© 2013   Created by Marcelo Rodrigues.

Badges  |  Report an Issue  |  Terms of Service