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
- Flex Sensor
- 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
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!