Making a Force Sensitive Resistor more stable

Hey guys I am fooling around with a force sensitive resistor(FSR) as a button for my project. I am running into phantom presses though. the code I am wanting to run does an analogRead of the FSR and turns pumps on. I have not written the code for that yet as when I am just doing a general test of the FSR with an LED, I am getting phantom presses. The analog read reads 0 randomly, the FSR works by giving a random 1-1023 when not pressed and goes to 0 when pressed. I cannot have the pumps run for 10 minutes for every phantom press. When I let it run for a little while, it flickers every 5 minutes or so.

I have changed the wire and I have used 2 different breadboards with 2 different arduinos and the problem is the same. I have changed the pin of both items and I have changed the ground. ruling out bad connections.

would a capacitor help? or should I just stick with a tact button

#define sensePin A5
#define ledPin 12


void setup() {
  Serial.begin(115200); //start serial
  pinMode(ledPin, OUTPUT);

}

void loop(){
  
int value = analogRead(sensePin);
if(value == 0){ // if FSR pressed turn LED on
  digitalWrite(ledPin, HIGH);
}
if (value > 0){ //while FSR is not pressed keep LED off
  digitalWrite(ledPin, LOW);
}

Serial.println(value);
}

If you really want help, a circuit diagram is imperative! And what is the power for the board?

Paul

That’s strange - it’s pretty unusual to see reading of zero from the ADC.

I think you have it wired wrong, or your connections are loose.

You want:

5v----////----A5----(FSR)----GND

(or - just as good, but with the logic reversed)

Gnd----////----A5----(FSR)----5v

Resistor of resistance equal to or somewhat lower than the unpressed resistance of the FSR is appropriate to get the best range of measurements, but anything vaguely close to the unpressed resistance of the FSR will probably be good enough for your purposes (would just need to change the threshold in the sketch)

Either way, you need to pick a threshold at which you declare it to be pressed, as it isn’t ever going to be equal to zero (but with that sketch, since it prints the output, you can figure out the correct threshold)

I am strictly following an arduino guide for this hook up and have checked my working maybe 100 times. I have changed wires and breadboards and Arduino. Connections are good but nothing is impossible.

I am swapping the wiring so the FSR is always 0 and goes up when pressed. I'm going to test this. I won't need to figure out the random 0s if i make it do nothing at 0. I hope this works, thanks for the idea.

I am on my phone so will update when home with a wiring diagram and if the test worked.

Hi,
Have you got the resistir in circuit like @DrAzzy has asked.

Also do not expect a zero from the analog input with the force sensor, its resistance changes and doesn’t necessarily short to ground.

Try;

#define sensePin A5
#define ledPin 12

void setup() {
  Serial.begin(115200); //start serial
  pinMode(ledPin, OUTPUT);

}

void loop(){
 
int value = analogRead(sensePin);
if(value  < 500){ // if FSR pressed turn LED on
  digitalWrite(ledPin, HIGH);
  }
if (value > 500){ //while FSR is not pressed keep LED off
  digitalWrite(ledPin, LOW);
  }
Serial.println(value);

check in your serial monitor, you may have to adjust the 500 threshold I have added.

Tom… :slight_smile:

Yes I have a 10 k resistor and have used it as a pull up and pull down. Your sketch idea, while appreciated, does not fix any issues as 0 is < 500 and it would turn my pump on with every random 0 it gives. I think using the FSR at 0 when unpressed is my only solution. I think something is won’t with the FSR.

force___flex_FSRandLED.png

You should not get a true ‘0’ or a ‘1023’ with a FSR and 10k pull up (or down) resistor.
If you do, then there is something wrong with the wiring.
Post a REAL picture of the setup.

The if() statement should have a threshold number other than ‘0’.
So what values are you getting from the sensor.

Why didn’t you use the internal pull up of the pin.
Leo…

Hi,
Using this setup;
460f179542dbfd3a8c38ee34f2a8c997e0690e29.png
What do you get as your serial monitor reading for pressed and unpressed force sensor?

Can you post a picture of your project so we can see your component layout please?

Did you try my code I posted with the 500 threshold?
If not please try it.
Also place a 0.1uF capacitor between A0 and gnd, to reduce any noise.

Thanks… Tom… :slight_smile: