Home-made FSR sensor for servo control

I am using an Arduino Uno with version 1.8.12

My project is a robotic hand. I have home made a FSR sensor by running a current through two copper plates connected by electrostatic foam touching it with (a) force appled and (b) no force applied.

void setup() {
  Serial.begin(57600);
}
void loop() {
  
int sensorReading1 = analogRead(A0);

float FSR1;

FSR1 = sensorReading1;

  Serial.println (FSR1);

  delay(100); 
}

The graph I is what the signal looks like when a force is not applied (blue) and when a force is applied (red). Along with the circuit for my sensor & what the setup looks like.

I have been trying for 2 days now with trying to get the signal to have clean patterns, to diagnosing every physical aspect/combination with it, and various forms of code but I can't get it to work. I have been using various if, elseif, millis() commands.

My main problem is that the motor jitters and flips between servo commands.

What I'm trying to achieve with this is something like

servo.write(0) as hand open -> after x amount of time it checks if the signal is within force applied zone -> servo.write(180) to close the hand

Basically once the arduino starts and then when force is applied to the sensor the hand will then close around the object. Or it closes around the object, checks if its in a range, then the servo positions itself to open hand posiition.

graph.JPG

My main problem is that the motor jitters and flips between servo commands

It sounds like you need to do some reading on the subject of hysteresis and then to implement it in your program to prevent the servo hunting between its two positions

UKHeliBob:
It sounds like you need to do some reading on the subject of hysteresis and then to implement it in your program to prevent the servo hunting between its two positions

I looked into it and tried to apply it but it goes back to the same problem: it's a big wave where only the peaks change when a force is applied. Using this hystereses code it still created the same issue only this time its sq.uare waves instead of wavy ones.

Is it impossible to create clearly the command I described with a FSR sensor creating an analog wave?

It looks like that hystereses would only work if the signal wasn't continously going through the same values for no force and force applied with the only difference being force applied has a higher wave peak.

uint16_t getOutputLevel( uint16_t inputLevel ) {
  
  //% between two end points
  const uint16_t margin = 10 ;   //  +/- 10

  // Output levels = 2, 1 for 0 degress, 1 for 180 degrees .
  const uint16_t numberOfLevelsOutput = 3 ;  //

 //450 avg max of no force applied, 550 avg max of force applied
  const uint16_t endPointInput[ numberOfLevelsOutput + 1 ] = { 0, 300, 450, 550 } ;

  // initial output level (usually zero)
  const  uint16_t initialOutputLevel = 0 ;

 // the current output level is retained for the next calculation.
  static uint16_t currentOutputLevel = initialOutputLevel ;

  // get lower and upper bounds for currentOutputLevel
  uint16_t lb = endPointInput[ currentOutputLevel ] ;
  
    if ( currentOutputLevel > 0 ) lb -= margin  ;   // subtract margin

  uint16_t ub = endPointInput[ currentOutputLevel + 1 ] ;
  if ( currentOutputLevel < numberOfLevelsOutput ) ub +=  margin  ;  // add margin

 // is input is between the outer margins for current output value
  if ( inputLevel < lb || inputLevel > ub ) {
    // determine new output level by scanning endPointInput array
    uint16_t i;
    for ( i = 0 ; i < numberOfLevelsOutput ; i++ ) {
      if ( inputLevel >= endPointInput[ i ] && inputLevel <= endPointInput[ i + 1 ] ) break ;
    }
    currentOutputLevel = i ;
  }
  return currentOutputLevel ;
}

void setup() {
  Serial.begin(57600);
}
void loop() {

  Serial.println(  getOutputLevel( analogRead(A0) ) ) ;

  delay(80); 
}

Try making your FSR using double sided FR4 and grounding the outside copper. Right now you have a nice antenna with a high resistance to ground. (guessing).

Paul

Please post a circuit diagram.

The servos must be powered separately from the Arduino, with a more-than-adequate power supply, or power supply voltage fluctuations will be a problem. Don't forget to connect all the grounds.

jremington:
Please post a circuit diagram.

The servos must be powered separately from the Arduino, with a more-than-adequate power supply, or power supply voltage fluctuations will be a problem. Don't forget to connect all the grounds.

I had gotten to this hurdle and solved it which is why I am specifically talking about the finger sensor.

I am using a 5V-30A transformer and supplying it to 5-6 motors in parallel to share the amps.

I included a fritzing schematic photo for you.

Paul_KD7HB:
Try making your FSR using double sided FR4 and grounding the outside copper. Right now you have a nice antenna with a high resistance to ground. (guessing).

Paul

That sounds about right. Disturbences in the area around the sensor I found had an effect on the signal like when i placed a redbull can near it. I will add in the use of double sided FR4 into my final project report, that is interesting to note. It's too late to go back and re-do the finger sensors, my comp sci friend told me something like;

Are there same amounts of readings for each waves (I found it was 34 - 36 time values between each wave), at what point is the gradient 0, see if number of points before gradient is 0 (is it the same for each of the waves?),

if at x point (when gradient is 0), then y = blah blah blah, then servo.write (red wave)
else if then servo.write(0) (blue wave)

Would that if statement work for Arduino coding structure?

I had a previous post on this subject but I have a new question that is pretty straight forward.

My input is a home-made force resistance sensor

With the application of hystereses, every 42 exceutions of serial.println with delay(80) & serial.begin(9600) has the same pattern.

When there is force applied every 42nd execution is 2
When there is no force applied every 42nd execution is 3.

I want to utilize this to move a servo where it has 2 commands to position, each command having 2 conditions to meet; (1) that it is either 2 or 3 (2) to check if it is 2 or 3 every 42nd execution of serial.println()

if (sensorReading1 = 2) && (x = ) {servo.write(140};
else if (sensorReading1 = 3) && (x = ) {servo.write(30)};

I don't know how to define the x

Picture included is a snippet of 3 clear force applied and 3 no force applied cycles.

Capture.JPG

I want to utilize this to move a servo where it has 2 commands to position, each command having 2 conditions to meet; (1) that it is either 2 or 3 (2) to check if it is 2 or 3 every 42nd execution of serial.println()

unclear

can you be more specific about what the commands are and the conditions. write each on in separate sentences

Picture included is a snippet of 3 clear force applied and 3 no force applied cycles.

what is 3?

Do note that you have used = where you need ==. i.e. this:

if (sensorReading1 = 2)

should be:

if (sensorReading1 == 2)

" I have home made a FSR sensor by running a current through two copper plates connected by electrostatic foam touching it with (a) force appled and (b) no force applied."

I have not really seen DIY FSRs working very well. If you are you trying to measure the force, that will be sketchy. On the other hand if you can get by with using the FSR as a contact switch, then you have a better chance of getting something working. You might move the servo until the finger is applying sufficient force to "grip" and check the output of the FSR, then use that value or less/more(?) as the stop value for the servo.

zoomkat:
" I have home made a FSR sensor by running a current through two copper plates connected by electrostatic foam touching it with (a) force appled and (b) no force applied."

I have not really seen DIY FSRs working very well. If you are you trying to measure the force, that will be sketchy. On the other hand if you can get by with using the FSR as a contact switch, then you have a better chance of getting something working. You might move the servo until the finger is applying sufficient force to "grip" and check the output of the FSR, then use that value or less/more(?) as the stop value for the servo.

That is exactly what I am trying to do but I am having problems using that value as it is a variable within a range that is a wave. With and withotu force are within each others ranges. I have tried hysteresis but it resulted in the same problem.

gcjr:
unclear

can you be more specific about what the commands are and the conditions. write each on in separate sentences

what is 3?

3 is the minimum value of the analog wave reading with force applied

i dont know how to be more specific about it. the minimum value of the wave without force is 2 and the minimum value of the wave with force is 3. I want them to both be commands. Every 42 value points recorded through serial.println() gives the same wave shape. At the end of the wave pattern the value is either 2 or 3 and that is the 42nd (last) value before the wave pattern repeats.

When there is force applied every 42nd execution is 2
When there is no force applied every 42nd execution is 3.

do you mean the measurement has a value of 3?

I want them to both be commands

it's not clear what you mean by commands.

Every 42 value points recorded through serial.println() gives the same wave shape.

what does "value points" mean? do you mean the pattern of values repeats every 42 values?

do you want the code to perform some action when the measurement <= 2 and and different action when >= 3

We have no idea how to solve your problem because we can't see it. Please post your entire sketch. There is some chance that your code will be easier to understand than your descriptions.

This is a duplicate post. If you had continued this discussion in your previous thread,
Home-made FSR sensor for servo control - Programming Questions - Arduino Forum it would be easier to understand you.

@canadiancookhouse

TOPIC MERGED.

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum.