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!
2 People Made This Project!
- JScoobyCed made it!
- kaegbert made it!
21 Comments
Question 6 months ago
Hey, i'm doing this with an esp32 but still using the Arduino software. I've changed it a bit there's no LEDs and the only thing that is meant to happen is that the serial monitor should print out the flex sensor's value. However I've been having some trouble as the only value that keeps being displayed on the serial monitor is 4095 on a loop. I'm not sure why this is happening.
Question 10 months ago on Step 1
Where did you source your flex sensor from?
Question 3 years ago
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??
Answer 2 years ago
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
Reply 2 years ago
Hello! I'm currently doing a similar project, can I contact you on email too?
Question 2 years ago on Step 1
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?
3 years ago
Hi! What if I use a vibe motor instead of a LED as the output, what codes can I use?
3 years ago
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
4 years ago
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?
4 years ago
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?
5 years ago on Introduction
nice how can i download this page
Reply 5 years ago
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
Reply 5 years ago
I suppose you could download the .html file but why...?
5 years ago on Introduction
I have made many Arduino Projects:
Example: Resistor Meter, Capacitor Meter, Piano and more see here:
http://www.electronics-freak.com/
Roee
Reply 5 years ago on Introduction
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?
Reply 5 years ago on Introduction
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
5 years ago on Introduction
Throw a video up for us to see!
Reply 5 years ago on Introduction
Hi! https://youtu.be/uC6G_0z8Dmo
5 years ago on Introduction
nice instructable ! can we use buzzer instead of LED? :-)
Reply 5 years ago on Introduction
Hi! Thank you! Yes you can ;)
Just remember that you must use a tone() function instead analogWrite().