A force sensitive resistor (FSR) can be used to measure applied force or pressure. This particular FSR can measure force from approximately 0.25 pounds to 22 pounds. (Higher forces can be applied to the FSR, but the measurement will reach a maximum value.) The measurement is proportional to the amount of force applied, but it isn't accurate enough to serve as a scale.
The force sensitive resistor has 2 pins. One option is to insert these pins directly into different numbered rows on a breadboard. If you need longer leads, another option is to take 2 wires, line them up side by side so each wire makes contact with one pin, and then wrap this connection in electrical tape to hold them securely together, and then insert the other end of the wires into a breadboard. Either way, you will need to use 2 jumper wires and a resistor to then connect the breadboard rows to the Photon.
NOTE: One of the FSR pins will have two connections: it should connect to an analog I/O pin through a jumper wire, and it should also connect to ground (GND) through a resistor. In the breadboard row, the jumper wire for the analog I/O pin should be placed between the FSR pin and the resistor leg. Look at the example wiring diagram for the photocell as a visual reference, since it has identical wiring.
IMPORTANT: The FSR must connect to an analog I/O pin, such as: A0, A1, A2, A3, A4, A5.
The FSR does not require any special code library.
In the global variables, you should declare which pin is being used as the FSR analog input pin. The example below declares a variable called "forcePin" (but you could use a different variable name).
You will probably also want to declare an integer variable to store the reading from the FSR. This will make it easier to do something based on the measurement. The example below declares a variable called "forceReading" (but you could use a different variable name).
There isn't any code that you need to include in the setup()
function for the FSR.
IMPORTANT: Do not set a pin mode for the FSR.
You can measure the amount of applied force using an analogRead()
statement. This code would be most likely placed within the loop()
function or within a custom function.
The measurement will be a value ranging from 0-4095.
When there is less force detected, the reading will be lower. When there is more force detected, the reading will be higher.
This FSR can measure from 0.25 pounds to 22 pounds of applied force. (Higher forces can be applied to the FSR, but the measurement will max out at 4095.) The measurement is proportional to the amount of force applied, but it isn't accurate enough to serve as a scale.
You will need to add code to do something with the force reading (such as: display it on the OLED screen, send the data to your web app, run a custom function if the reading is more than a certain value, etc.).
RECOMMENDATION: Depending on the specific purpose of the FSR in your device, you may need to gather some data under different conditions to see how much force will actually be applied when your device is used. This will help you decide which values to use in your code to make decisions about what the device should do.
Force Sensitive Resistor
Photon Pin
One FSR pin (either one)
3.3V
Other FSR pin
(1) any analog I/O pin, (2) GND using resistor