CxD Archive
Internet of Things Project
Internet of Things Project
  • IoT Project Background
  • IoT Project Challenge
  • IoT Project Outline
    • 1-1 Smartphone Research
    • 1-2 Smart Thermostat Research
    • 1-3 Smart Device Research
    • 1-4 Introduction to Photon Kit
    • 1-5 Build Smart Lightbulb
    • 1-6 Generate Project Ideas
    • 1-7 Build Smart Thermostat
    • 2-1 Evaluate Project Ideas
    • 2-2 Plan User Research
    • 2-3 Compile Research Data
    • 2-4 Construct Personas
    • 2-5 Construct Journey Map
    • 2-6 Define Value Proposition
    • 2-7 Define Design Requirements
    • 3-1 Generate Solution Ideas
    • 3-2 Evaluate and Refine Solution Ideas
    • 3-3 Create System Model of Solution
    • 3-4 Create Wireflow for Web App
    • 3-5 Create Storyboard for Solution
    • 3-6 Evaluate Solution Design
    • 3-7 Present Project Proposal
    • 4-1 Track Progress and Issues
    • 4-2 Build Smart Device
    • 4-3 Create Photon App
    • 4-4 Create Web App
    • 4-5 Conduct Integration Testing
    • 4-6 Create Product Demo Video
    • 4-7 Create Product Marketing Website
    • 5-1 Evaluate Smart Device and Web App
    • 5-2 Evaluate Product Marketing Website
    • 5-3 Improve Solution Based on Evaluations
    • 6-1 Create Project Poster
    • 6-2 Present Project to Public
    • 6-3 Write Personal Reflection
  • References for Wiring & Coding
    • Creating Circuits
    • Wiring Programming Language
    • Particle Cloud
    • Hello World App for Photon
    • LED Light
    • Push Button
    • Micro OLED Display
    • Humidity and Temp Sensor
    • Speaker
    • Servo Motor
    • Motion Sensor
    • Magnetic Switch
    • Potentiometer
    • Photocell
    • Moisture Sensor
    • Accelerometer
    • RFID Reader
    • Fingerprint Scanner
    • GPS Receiver
    • Camera
    • Microphone
    • Force Sensitive Resistor
    • Keypad
    • Continuous Rotation Servo Motor
  • Glossary
  • Updated Project Guidebook
  • Updated Code Guidebok
Powered by GitBook
On this page
  • Code for Force Sensitive Resistor
  • Library
  • Global Variables
  • setup( ) function
  • Measuring Amount of Force
Export as PDF
  1. References for Wiring & Coding

Force Sensitive Resistor

PreviousMicrophoneNextKeypad

Last updated 6 years ago

A force sensitive resistor (FSR) can be used to measure applied force or pressure. 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.

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

IMPORTANT: The FSR must connect to an analog I/O pin, such as: A0, A1, A2, A3, A4, A5.

Code for Force Sensitive Resistor

Library

The FSR does not require any special code library.

Global Variables

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).

// if necessary, change data pin number to match your wiring
int forcePin = A0;

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).

// global variable
int forceReading;

setup( ) function

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.

Measuring Amount of Force

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.

forceReading = analogRead(forcePin);

// add code to do something based on value of forceReading

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.

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 as a visual reference, since it has identical wiring.

photocell
This particular FSR
Force Sensitive Resistor