Introduction: How to Use a Flex Sensor - Arduino Tutorial

Picture of 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

Picture of What You Will Need

For this tutorial you will need:

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

Step 2: The Circuit

Picture of 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!

Picture of 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!

Comments

gartwork (author)2017-04-05

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

basma2 (author)2017-03-15

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

AseemA (author)2016-03-31

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?

AseemA (author)2016-03-31

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?

kaegbert made it! (author)2015-12-09

easy tutorial thanks for sharing

ravindu123 (author)2015-07-09

nice how can i download this page

agis68 (author)ravindu1232015-12-01

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

braytonlarson (author)ravindu1232015-07-13

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

RoeeB (author)2015-07-10

I have made many Arduino Projects:

Example: Resistor Meter, Capacitor Meter, Piano and more see here:

http://www.electronics-freak.com/

Roee

Liamthe1st (author)RoeeB2015-07-16

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?

RoeeB (author)Liamthe1st2015-07-16

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

BrownDogGadgets (author)2015-07-09

Throw a video up for us to see!

Hi! https://youtu.be/uC6G_0z8Dmo

theorycircuit (author)2015-07-09

nice instructable ! can we use buzzer instead of LED? :-)

Hi! Thank you! Yes you can ;)

Just remember that you must use a tone() function instead analogWrite().

amy_rotfl (author)2015-07-09

Boss. Going to make soon

About This Instructable

38,453views

169favorites

License:

Bio: Arduino Tutorials by Codebender.cc Team
More by codebender_cc:How to use a magnetic door switch / sensor with ArduinoHow to Measure LUX With ArduinoHow to Control an RGB LED Strip - Arduino Tutorial
Add instructable to: