How to Use a Flex Sensor - Arduino Tutorial

44,457

170

23

Posted

Introduction: How to Use a Flex Sensor - Arduino Tutorial

In this "How to" tutorial you will learn how to use a flex sensor with Arduino uno.

A flex sensor uses carbon on a strip of plastic to act like a variable resistor. The resistance changes by flexing the component.

The sensor bends in one direction, the more it bends, the higher the resistance gets.

In this example we will use a flex sensor to fade an led.

So, let's get started!

Step 1: What You Will Need

For this tutorial you will need:

  • Arduino uno
  • Breadboard
  • Flex Sensor
  • Led
  • 10KOhm & 220 Ohm resistors

Step 2: The Circuit

The connections are pretty easy, see the image above with the breadboard circuit schematic.

Step 3: The Code

Here's the code, embedded using codebender!

A flex sensor has a range from about ~10K to ~35K, that means it won't give us a full 0-5 volt range (or 0-1023 analog value). Try to use the serial monitor below to find out what analog value you will take while you bending the sensor. It supposed to be between 700 to 900.

How it works:

Read analog value from flex sensor
-> value=analogRead(flexPin);

Map analog values 700-900 to pwm values 0-255
-> value = map(value, 700, 900, 0, 255);

Send pwm value to led
-> analogWrite(ledPin, value);

Try downloading the codebender plugin and clicking on the Run on Arduino button to program your Arduino with this sketch. And that's it, you've programmed your Arduino board! Press connect button to start serial communication with your Arduino board.

You can make your own modifications to the code by clicking the "Edit" button. For example, you can change "700-900" values in map function.

Step 4: Well Done!

You have successfully completed one more Arduino "How to" tutorial and you learned how to use a flex sensor with Arduino.

I hope you liked this, let me know in the comments.

There will be more of them, so make sure to click Follow button!

Share

Recommendations

  • Microcontroller Contest

    Microcontroller Contest
  • Science of Cooking

    Science of Cooking
  • Pocket-Sized Contest

    Pocket-Sized Contest
user

We have a be nice policy.
Please be positive and constructive.

Tips

2 Questions

Would it be possible to use this sensor in a stress ball? so that it could be used as a game controller for a simple game?

hey hello, I have been working with a projwct on sign language ,
for hat im using aflexsensor,
now im really stuck at how should i interface lcd and flexsensor using ardino?
anyone can??

Have you done with your project about sign languange? I do this project now, can we discuss? please contact me gilangenigma@gmail.com. thank you

15 Comments

Hi! What if I use a vibe motor instead of a LED as the output, what codes can I use?

hello thanks a lot for sharing

I learned from you

but the light doesn't turn off when I don't touch the sensor... not sure why

i tried this out using a 4 inch flex sensor but i was getting a range that barely went below 1010. since it is a 4 inch sensor compared to the 2 inch you are using, should i be increasing or decreasing the resistance before the sensor?

also i encountered another problem, my LED fade stopped working. even when i run a basic fade-in fade-out it doesnt work. it blinks instead, can i fix this or do i have faulty material?

i tried this out using a 4 inch flex sensor but i was getting a range that barely went below 1010. since it is a 4 inch sensor compared to the 2 inch you are using, should i be increasing or decreasing the resistance before the sensor?

also i encountered another problem, my LED fade stopped working. even when i run a basic fade-in fade-out it doesnt work. it blinks instead, can i fix this or do i have faulty material?

nice how can i download this page

you can save it as PDF file with printing it not in physical printer but in any pdf printer...I do this for all instructables i like

I suppose you could download the .html file but why...?

As you say you have done lots may I ask, can you make a sensor to turn my TV over to my security camera from the source TV program being watched ? What would be the best sensor to use?

I didn't understand your question.
Do you want the TV to TURN, or do you want the channel to be changed - like pressing INFRA-RED remote of your TV?
Thx,
R