newbie creating fsr voting system

I’m trying to build (what should be) a simple voting system, using a bunch of force sensing resistors that people tap, and a vote is cast. however, clicking either sensor is casting votes for both buttons. can someone tell me if my code is wrong or my wiring is off somehow? (as mentioned in the topic title, i’m very new to all this, so please bare with me)
thanks in advance for any help!

int fsrAnalogPin0 = A0; // FSR is connected to analog 0
int fsrAnalogPin1 = A1;
int fsrReading0; // the analog reading from the FSR resistor divider
int fsrReading1;
int delayInt = 1000;
int fsrPresses0 = 0;
int fsrPresses1 = 0;

void setup() {
   Serial.begin(9600);
}

void loop() {
  fsrReading0 = analogRead(fsrAnalogPin0);
  fsrReading1 = analogRead(fsrAnalogPin1);

  if( fsrReading0 != 0 ){
    fsrPresses0++;
    Serial.print("button0: ");
    Serial.println(fsrPresses0);
    Serial.println();
    delay(delayInt);  
  }
  if( fsrReading1 != 0 ){
    fsrPresses1++;
    Serial.print("button1: ");
    Serial.println(fsrPresses1);
    Serial.println();
    delay(delayInt);  
  }
}

Using a threshold of zero is not a good idea. Read the two sensors and print them out and come up with a better threshold than zero.

Grumpy_Mike The whole point was that I'm not able to read the two sensors separately right now. Thresholds aside, right now clicking either sensor is adding to both sensors' counts. I need to figure out how to read and record clicks/votes for each individual sensor. Thoughts?

I’m trying to have a simple voting system, reading from multiple force sensing resistors. I’m not sure if this is a hardware setup or code problem, but regardless of which fsr I press, the count for both variables gets added to. I didn’t think would be terribly complicated, but I’m new to all this and have been going in circles. Any and all help is greatly appreciated.

int fsrAnalogPin0 = A0; // FSR is connected to analog 0
int fsrAnalogPin1 = A1;
int fsrReading0; // the analog reading from the FSR resistor divider
int fsrReading1;
int delayInt = 1000;
int fsrPresses0 = 0;
int fsrPresses1 = 0;

void setup() {
   Serial.begin(9600);
}

void loop() {
  fsrReading0 = analogRead(fsrAnalogPin0);
  fsrReading1 = analogRead(fsrAnalogPin1);

  if( fsrReading0 != 0 ){
    fsrPresses0++;
    Serial.print("button0: ");
    Serial.println(fsrPresses0);
    Serial.println();
    delay(delayInt);  
  }
  if( fsrReading1 != 0 ){
    fsrPresses1++;
    Serial.print("button1: ");
    Serial.println(fsrPresses1);
    Serial.println();
    delay(delayInt);  
  }
}

The readings you get from the analog pins will almost always be non 0. try testing for >200 or somthing. You will have to try out different values.

Mark

The whole point was that I'm not able to read the two sensors separately right now.

Rubbish what makes you say that? Read the sensors and print out the results then you will see.

Because you have rubbish thresholds it appear your sensors are not working.

Thoughts?

If you ask for advice you should be prepared to take it.

Mark, Thanks for the quick reply. I'm still a little confused. I'm using FSR's, but quite frankly they are just acting as buttons, I don't actually care about the force anyone pushes them with. Currently, if I push sensor1, my sensor1count (fsrPresses0) incrementally adds 1, which is perfect. However, if I then push sensor2, it is adding 1 to the sensor1count AND adding 1 to the sensor2count (fsrPresses1). I obviously just want 1 added to the corresponding count. I can't tell if perhaps I've wired the board incorrectly (see the original post, I've attached an image of how everything is hooked up)? I feel like this should all be pretty basic, no?

Mike, First, this is obviously a board where there are plenty of user levels. If you feel you are above helping newcomers without berating them, just don't respond. We get it. You know what you are doing and we all pale in comparison to your mad skills. Next, if you are up for helping, I was simply asking what the thresholds had to do with the individual sensors? I am actually not trying to get an actual force reading, just that any touch was made (basically they are acting as simple buttons). That is why I had used 0 as my threshold. I can change these values, I just didn't understand what the purpose of raising the values actually did since in any of the FSR instances, I just need them to read "1" to (in theory) create a true statement to then enter the "if" statement loop and then pass a value on to Processing. Thank you for your patience and help.

Mike's advice in reply #1 was good, and I'm puzzled that you are unwilling to even try the experiment.

However, his advice was based on the assumption that you've wired the force sensitive resistor correctly, which would be to form a voltage divider with another resistor of the appropriate value. If you've done that, then it is literally impossible to read a 0 on the ADC, and for you to make any sense at all of what comes out, it is absolutely required to know what the reading is when the fsr is not being subjected to any forces, and also to know what a typical reading is, when someone taps the sensor.

I'm not unwilling to try, I am trying to understand, that is all. This is literally my first real "independent" Arduino project, so I was just hoping for some guidance.

With that said, jremington, can you tell from the picture I attached in the first post if I've wired the device correctly? I was feeling that I may have done it incorrectly, as pushing either sensor was adding to count variables that was "supposed" to be triggered by the analog inputs that they are matched up to.

I will modify my code to grab the thresholds and see what I can determine from there.

Thanks J

No, from that picture I can't tell where all the wires are going. It is much better to post a schematic diagram (not Fritzing) or a link to the one you are following.

I do see the two resistors and the two fsr pads. As I said, if you have correctly wired the resistive divider, powered by 5V and are measuring the voltage at the junction (relative to ground), it is impossible to read 0.

Edit: resistive voltage dividers are most effective when the fixed resistor and the variable resistor (the fsr) are approximately the same value. In that case, the voltage at the junction will be about Vcc/2 or about 2.5 volts in your case. Check that with a multimeter. If you don't have one, now is the time to buy. They are essential trouble shooting and learning tools.

jmarx34, something to try, just connect an FSR from any pin to ground. Enable the internal pullup resistor and treat it as you would a push button, i.e. a digital input, not analog. Debounce like any other switch.

I have a project that has several tactile button switches and this FSR: https://www.sparkfun.com/products/9376

My first impulse was also to read it with the ADC, but I only needed to know whether there was pressure on it or not. So on a lark I tried using a digital input and to my amazement it worked perfectly. Your project is a bit different so YMMV but definitely worth a try.

I use a debounce library that I wrote. The only thing I do differently is to use 100ms debounce time for the FSR; I usually use 20-25ms for tact buttons. If you don't have favorite debounce code, give it a try: https://github.com/JChristensen/Button.

You could use one of the example sketches to see if it will work with your FSR, just change the debounce time from 20 to 100: https://github.com/JChristensen/Button/blob/master/Examples/SimpleOnOff/SimpleOnOff.pde

If you feel you are above helping newcomers without berating them, just don't respond.

I am not above helping newcomers at all, that is what the board is all about. But when you give them good advice and they come back with the sort of response that you did I feel it is necessary to remind them that it is they who are asking the questions.

I was simply asking what the thresholds had to do with the individual sensors?

No you were not, you said:-

jmarx34: The whole point was that I'm not able to read the two sensors separately right now. Thresholds aside, right now clicking either sensor is adding to both sensors' counts. I need to figure out how to read and record clicks/votes for each individual sensor.

You did not say something like "I don't understand why you are saying this I thought my problem was not being able to read the sensors independently". That would have shown you were thinking and were ready to learn. The only reason you thought you could not read the sensors independently was that you have made a mess of what you did with the results.

Therefore I suggested something that would make you see that you in fact are reading them independently or to show to me that you were not when you reported back the results.

And the only reason I am continuing to answer your questions is in an attempt to educate you, to make you better at not only asking questions but also responding to the answers.

I am not sure what you expected from asking a question, I could have responded with a piece of code that would have done what you wanted but what is the point of that. I can do that, you can't. My self appointed task is to try and make you able to do that, for you to learn some fault finding techniques and be more successful.

Hey cross posting wastes time. You have already been given these answers by others. http://forum.arduino.cc/index.php?topic=230969.msg1670238#msg1670238

Threads merged.

G_M & All,
Let me try to start over.
First, I apologize if somehow I offended anyone with my responses. None of them were meant to be dismissive of anyone’s responses. They were purely asking more questions in an attempt to clarify both information I was trying to provide, as well as lead me down better logic in my programming. As I mentioned before, this is my first real, independent Arduino project, and I’m really excited about it, but do need some hand-holding to understand what I should be doing.

So I’m more or less back at square 1.
G_M, in your initial response, you said to read the thresholds of the two sensors. My response was more trying to figure out how these values would be used to differentiate between the two sensors. If I push sensor1 and it returns 800 the first time, but then I push it softer the next time and it returns 300. And then I push sensor2 softly and it reads 300, what is that proving? I literally just need to know that sensor1 was pushed versus sensor2, then send a value through Serial.write() that Processing is going to look for to graph. (For testing purposes I’m also Serial.println the a count that should be associated to each fsr.)

void loop(){
  fsrReading0 = analogRead(fsrAnalogPin0);
  fsrReading1 = analogRead(fsrAnalogPin1);

  if( fsrReading0 >= 1 ){
    fsrPresses0++;
    Serial.write(0);
    Serial.println("fsr0presses: ");
    Serial.println(fsrPresses0);
    delay(delayInt);
  }

  if( fsrReading1 >= 1 ){
    fsrPresses1++;
    Serial.write(1);
    Serial.println("fsr1 presses: ");
    Serial.println(fsrPresses1);
    delay(delayInt);
  }
}

Currently the monitor is displaying both the fsr0 and fsr1 counts increasing when I push either fsr.

If you see something that looks blatantly wrong/missing in here, please let me know. Otherwise, I’ll assume that I have something wired incorrectly. If it does look like it’s a wiring issue, what do you guys typically use to draw schematic drawings? I’m happy to sketch it out to verify the hardware.

Thank you in advance for your patience and help.

If I push sensor1 and it returns 800 the first time, but then I push it softer the next time and it returns 300. And then I push sensor2 softly and it reads 300, what is that proving?

Do it and you will see. Does that actually happen? It should not if you have your wiring correct. So do the test and see if you get repeatable results.

That is how you do projects, you do small stuff, then you test it. My guess is that you will see that you do not see the readings you are expecting. When we know the actual values you are reading from the sensors pressed and unpressed then we can plug sensible values into your software. Until you know what readings you actually get it is pointless writing any software to do stuff with those readings.

As to your code, again the thresholds are silly. Do the experiment, and report back. Either you or I are going to be surprised.

you said to read the thresholds of the two sensors.

No I didn't I said read the thresholds I said print out the readings from the sensors.

G_M, Thanks for sticking with me.

Ok, just to be sure I am doing this correctly, here is the code I just used to test the readings of the two FSRs:

int fsrAnalogPin0 = 0; // FSR is connected to analog 0
int fsrAnalogPin1 = 1;
int fsrReading0; // the analog reading from the FSR resistor divider
int fsrReading1;
int delayInt = 1000;
int fsrPresses0 = 0;
int fsrPresses1 = 0;

void setup() {
   Serial.begin(9600);
}


void loop() {
  fsrReading0 = analogRead(fsrAnalogPin0);
  fsrReading1 = analogRead(fsrAnalogPin1);

  if( fsrReading0 > 200 ){
    fsrPresses0++;
    Serial.println("0: ");
    Serial.println(fsrReading0);
    Serial.write(0);
    delay(delayInt);
  }

  if( fsrReading1 > 200 ){
    fsrPresses1++;
    Serial.println("1: ");
    Serial.println(fsrReading1);
    Serial.write(1);
    delay(delayInt);
  }
}

And here is what is returned in the Monitor upon presses (please note that I pushed fsr0 1st and it returned "1: 220", then I pushed fsr1, and it returns "0: 210" AND "1: 229" on the single press).

1: 
220
0: 
210
1: 
229

While that code tells you the value for a press it does not tell you the off value. I was thinking something more like this:-

int fsrAnalogPin0 = 0; // FSR is connected to analog 0
int fsrAnalogPin1 = 1;
int fsrReading0; // the analog reading from the FSR resistor divider
int fsrReading1;
int delayInt = 500;
int fsrPresses0 = 0;
int fsrPresses1 = 0;

void setup() {
   Serial.begin(9600);
}


void loop() {
  fsrReading0 = analogRead(fsrAnalogPin0);
    Serial.println("0: ");
    Serial.println(fsrReading0);
    Serial.write(0);
    delay(delayInt);

  fsrReading1 = analogRead(fsrAnalogPin1);
    Serial.println("1: ");
    Serial.println(fsrReading1);
    Serial.write(1);
    delay(delayInt);
}

then I pushed fsr1, and it returns "0: 210" AND "1: 229" on the single press).

Yes it will does that surprise you?

In your code the force sensor will be read then printed out every time the reading is over 200. If you keep your finger on the sensor then it will continue to print out values. If you are saying that the second reading happens when you have removed your finger then it points to the way you are wiring things up or the sensor's recovery time.

How is the resistor and sensor wired up and what value resistor are you using? Note that mechanically it will take some time for the force sensor to recover it's unpressed value because the plastic has to spring back to the none pressed position.

G_M,
Ok, thanks for the quick replies. This is starting to make a lot more sense now.
So at this point, should I be wrapping my Serial.write lines in ‘if’ statements so that there is not a continuous flow of data being sent to Processing? This is where I was initially just setting the conditional to be fsrReading > 0, so I’m still confused as to what the conditional should be.

I’ve also cleaned up my board a lot, so here’s a pic of what I’m working with from the hardware setup perspective (wires running off to the right of the screen are connected to the FSRs).