Ardumotive Arduino Greek Playground
  • Home
    • About us
    • Contact
    • License
  • Arduino
    • Tutorials
    • Workshop
  • Raspberry Pi
  • DIY 3D Printer
  • News
    • Events >
      • Unboxing & Review
    • Blog
The 1st Arduino Playground in Greece - Open Source Hardware

Flex Resistor

Available Languages
Greek
English

Introduction 

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.

What you will need - Hardware

For this tutorial you will need:
  • Arduino uno
  • Breadboard
  • Flex Sensor
  • Led
  • 10KOhm & 220 Ohm resistors
Picture

The Circuit

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

The code

Here's the code,

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);
​
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/* How to use a flex sensor/resistro - Arduino Tutorial
   Fade an LED with a flex sensor
   More info: http://www.ardumotive.com/how-to-use-a-flex-sensor-en.html
   Dev: Michalis Vasilakis // Date: 9/7/2015 // www.ardumotive.com  */
   

//Constants:
const int ledPin = 3;   //pin 3 has PWM funtion
const int flexPin = A0; //pin A0 to read analog input

//Variables:
int value; //save analog value

void setup(){
  pinMode(ledPin, OUTPUT);  //Set pin 3 as 'output'
  Serial.begin(9600);       //Begin serial communication
}

void loop(){
  value = analogRead(flexPin);         //Read and save analog value from potentiometer
  Serial.println(value);               //Print value
  value = map(value, 700, 900, 0, 255);//Map value 0-1023 to 0-255 (PWM)
  analogWrite(ledPin, value);          //Send PWM value to led
  delay(100);                          //Small delay
}
Download the code from here and open it with Arduino IDE. Open the serial monitor from tools menu of Arduino IDE to test it.
flexsensor_tutorial.zip
File Size: 0 kb
File Type: zip
Download File


​You can make your own modifications to the code, for example, you can change "700-900" values in map function.

Well done!

Picture
Picture
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.
​
Picture

Search Engine

Picture

Licence 

Picture

Help us to grow up!

Picture


Donate us
About us
License
Cookies policy

Visit the biggest Arduino Shop in Greece!

Picture
find us on dwrean.net
find us on Codebender
find us on Instructables
Developed and designed by Vasilakis Michalis Copyright © 2013 Ardumotive All Rights Reserved
All trademarks referenced herein are properties of their
Powered by Create your own unique website with customizable templates.
Design by DivTag Templates