Check FSR connection status

Hi all,

I am using an FSR in my project to detect if someone has pressed a certain area of my product, using the analogRead() function. The force applied is then graded into bands by assessing the analogue value obtained.

At the same time, I would like to have some sort of check method to assess whether the sensor is connected to the pin it is connected to, without having to press the sensor first. Almost like a verification check to ensure the system is working as it should before shipping to a customer.

The following code works but I have to press the sensor first:

const int fsrPin = 2;  // The digital input pin connected to one leg of the FSR

void setup() {
  Serial.begin(9600);  // Initialize serial communication
  pinMode(fsrPin, INPUT_PULLUP);  // Set the pin as input with internal pull-up resistor
}

void loop() {
  int fsrState = digitalRead(fsrPin);  // Read the state of the FSR
  if (fsrState == LOW) {
    Serial.println("FSR is connected.");
  } else {
    Serial.println("FSR is not connected.");
  }
  
  delay(250);  // Delay before checking again

Any ideas on how to do this without pressing the sensor would be greatly appreciated. Thanks in advance!!

Is the FSR connected between 5V and a resistor to ground?

Hi @jim-p

Yes connected to 5V with a 1k resistor to GND.

I am thinking of reading the resistance and using the analogue reading and voltage divider formula.

1K seem low for most FSRs, which one are you using.

The problem is, whether the FSR is connected or not, the analog read value will be around zero

I am using an FSR05 from Ohmite.

Yes that is what I'm seeing, when the sensor is connected and not pressed the analog read is zero, thus the resistance turns out as infinity. Then when I press the resistance decreases as the analog value increases.

However when I disconnect the sensor from the read pin, both analog and resistance values are random as the pin is now floating.

If you disconnect the FSR and the 1K resistor it will be floating but if you just disconnect the FSR it should still read zero.

I have the connection point for the FSR and resistor on an external custom PCB. So wiring to the Arduino is 5V, GND and to the analog in pin to read the sensor.

This setup will be the same in the final product so that sensor replacement (if required) is easy and done by just removing that PCB and connector. I suppose this will mean the pin will be floating as you say when the PCB is removed.

So your original idea with the pullup should work without having to have to push the FSR


Thanks for your reply @jim-p
The code I attached only updates when I press down on the sensor. The image attached shows a snapshot of the serial monitor- it updates from not connected to connected if I press the sensor and activate it.

Are you sure the FSR is connected to 5V and not the 1K resistor?
fsr

This line of the code (PULLUP) expects you to connect the FRS between pin and ground.
Without resistor, or maybe a 10k resistor between pin and 5volt if needed.
1k sounds too low.

You should get A/D readings around 512 with average pressure applied.
The value of the pull up resistor used (or no resistor) should bring it within that range.

A disconnected sensor will read close to 1023.
Leo..

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.