In previous post, we have discussed about how to work with Force Sensor using Arduino. Today we are going to talk about how to get flex measurements using Arduino Flex Sensor. Let’s get started.
What is Arduino Flex Sensor?
Arduino Flex Sensor is a sensor type which gives you flex
angle readings. It means if you bend the sensor, if gives angle measurements. That’s
very important when making things like smart gloves. It can get finger bend
measurements. Not only that, it can get door angle measurements, and etc.
Pinout and Circuit Diagram.
Below is the pinout.
Below is the circuit diagram.
Get Readings from Flex Sensor.
In this code’s beginning, I created an integer type variable
named sensorval to store sensor readings.
Then in the void setup, I set the serial monitor’s baud rate
to 9600. Then I initialized “A0” pin as an input.
In the void loop, I set the “A0” sensor readings to sensorval
variable. To do that, I have to use analoaRead function. You have learned about
it before. Then I got the output by putting Serial println function. It makes
serial print with line break. Then I added 100 milli seconds delay for making
more smoother running.
Add range to outputs.
You saw that its output range is about 64 to 12. You have to
convert it to get real value. To do that, you have to add map function.
This code is almost same as before code. I created a variable
named sensorval for storing sensor readings and make a map function from it.
Then inside the void setup, I have set the serial monitor’s baud
rate to 9600 for getting output to serial monitor. Then I initialized “A0” pin
as input in the last line of the void setup.
Then inside the void loop, I assigned “A0” pin readings to
sensorval. Then I made the map function. Indie the map function, I put the code
like this. “sensorval = map(sensorval, 64, 12, 0, 180);” In the first part, I reassigned
sensorval from mapped sensorval. Inside the map function, I added the value
what I want to shrink. Then I added the range what I have. Flex Sensor gives 64
to 12 output range with 2K resistor. So, first I added that value range. Then I
added the range what I want to convert. It’s about 0 to 180. Then in the next
line, I got the output from it. Inside the last line of void loop, I have put
100 milliseconds delay to make more smoother running.
Get absolute output.
You have noticed that its values are not the real values. You
can’t ignore that error. There isn’t any way to correct that error. But you can
get good output rather and Serial monitor. To do that, you have to put servo motor.
It makes good output. Below is the code.
This code is very much same as above. I added “Servo.h”
library at the first line. Then I created object from it. Then I initialized its
pin as 9 in the void setup. Then I got the output by putting myservo.write
function.