How do I connect/code to use a flex sensor?



  • I bought two flex sensor before and would like to know how connect them and if possible a sample code for two sensors.



  • @Cliff-Karlsson

    A flex sensor is like an LDR, you would connect to an analog pin as part of a voltage divider. The senjor will give analog readings dependent on the voltage supplied and the range of flex in your application. How you code it would depend on what you are trying to sense. If you want to get an incremental measurement along the entire range of flex, you could use the map function to convert it from the analog read to a 1-100 scale as V_PERCENTAGE. If you were just looking for it to provide an alert when the sensor flexed past a certain level, you could set the level in your code and send it as a V_STATUS using S_BINARY or S_LIGHT. Either way, you need to determine the analog values of your sensor within the working environment of your application before you can finalize your code. E.g. What is the analog read when nothing is happening to the sensor and what is the reading when the sensor is at maximum expected flex.



  • How would the code look like If I want a way to monitor the different values wireless when the sensor is placed in the desired place?



  • @Cliff-Karlsson

    It might be easier if you explained your intended application.

    The code can be written to read the sensors continuously and only send when a significant change is detected, or it can read the sensors on a time interval and send the value as a percentage or custom value. If you want to continuously read the value at your controller, you will flood your wireless network with messages.

    I would suggest first hooking the sensor up to a Arduino and read the analog values of your sensor through the serial monitor to see what range and fluctuation your application generates.



  • @Dwalt said:

    I would suggest first hooking the sensor up to a Arduino and read the analog values of your sensor through the serial monitor to see what range and fluctuation your application generates.

    I would like to use two flex sensors under my bed to try out of they are good as bed occupancy sensors. But I do not know how much "flex" is generated when the sensors is placed underneath the bed. Would the resistance chage be usable even if the flex sensor is just bent a couple of degrees?



  • Does those "button" force sensors work in the same way?



  • @Cliff-Karlsson

    No sure on the button force sensors, I have not used them.

    To test the force sensors under a mattress, I would wire them up to an Arduino with a sketch that simple reads the analog pin and serial prints the result. Place the sensor under the mattress and see what the serial monitor readings are when the bed is unoccupied and occupied. This would give you the unique range for you particular need. Might be tricky if your computer and bed are in different rooms. After you have the range, you could write a sketch with S_BINARY to trigger V_STATUS whenever the reading approached the high end of your tested range.

    If you cannot reach you bed while connected to serial, you could write a sample mySensors sketch to send the analog reading every few seconds to your controller as V_LEVEL. This video helps explain how to wire up the sensor and select the static resistor for the voltage divider. video


Log in to reply
 

Suggested Topics

  • 3
  • 10
  • 2
  • 1
  • 2
  • 2

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts