Force Sensitive Resistor Resetting?

Hello!

I am working on a project that uses a force sensitive resistor and I am running into an issue with the analog values I am reading. From my understanding, the values should range from 0-1023 because I have a 10 bit ADC. However, as I apply more pressure, the sensor resets at about 260 and I am not sure why. I am printing the analog reading to the serial port in Arduino and I can see the value steadily rise as I apply more force but once it hits about 260, the reading goes back to 0 and continues to count up again.

I am using XBee's to send the analog value wirelessly so I am not sure if that would cause an issue either.

Does anyone have any experience with this or know what would cause this issue? Thank you!

Likely you're storing the value in a variable with the byte data type, which only goes from 0-255:

The solution is to use an appropriate data type, such as unsigned int:

For more specific help, you would need to post your code.

That was my initial thought as well but I have them stored as a float so I am not sure what the issue is. I have posted my code below:

#include <XBee.h>
#include <SoftwareSerial.h>
#include <AltSoftSerial.h>
#include <SPI.h>
#include <SD.h>
//import the xbee, software serial, SPI, and SD card libraries

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
Rx16IoSampleResponse rx16 = Rx16IoSampleResponse();

//define the two pins used for data transmission
//Dout on the XBee goes to pin 2 and Din goes to pin 3
#define ssRX 2
#define ssTX 3
SoftwareSerial lcd(ssRX, ssTX);
AltSoftSerial xbeeserial;

//variables for each of the four sensor values, the SD card, and the button
float data = 0;
float data2 = 0;
float data3=0;
float data4=0;
float front=0;
float back=0;
const int button1Pin = 4; // pushbutton 1 pin
int button1State;
const int chipSelect = 10;

void setup() {
// Set up the pushbutton and sd card pins:
pinMode(button1Pin, INPUT);
pinMode(chipSelect, OUTPUT);
// start serial
Serial.begin(9600);
// and the software serial port
lcd.begin(9600);
// now that they are started, hook the XBee into
// Software Serial
xbeeserial.begin(9600); //new
xbee.setSerial(xbeeserial);
lcd.print(" ");
Serial.println("starting up!");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("Card failed, or not present");
// don't do anything more:
return;
}
Serial.println("card initialized.");
}

void loop() {
xbee.readPacket();
//Serial.println("test");
if (xbee.getResponse().isAvailable()) {
// got something
Serial.println();
Serial.print("Frame Type is ");
Serial.println(xbee.getResponse().getApiId(), HEX);

if (xbee.getResponse().getApiId() == RX_16_IO_RESPONSE) {
xbee.getResponse().getRx16IoSampleResponse(rx16);
//prints the analog values from each of the sensors
data = rx16.getData(4);
data2=rx16.getData(6);
data3=rx16.getData(8);
data4=rx16.getData(10);
//data=data3.0/265.0;
//data2=data2
3.0/265.0;
//data3=data33.0/265.0;
//data4=data4
3.0/265.0;
front=data + data2;
back=data3+data4;
float sensorVoltageF = front * (3.0 / 1023.0);
float sensorVoltageB= back* (3.0/1023.0);
//double voltage2Pound = 6.8723sensorVoltagesensorVoltagesensorVoltage - 3.7445sensorVoltagesensorVoltage + 7.1943sensorVoltage - .2046;
if (front != 0){
lcd.print("Frnt(lbs): ");
lcd.println(front);
} else if (back != 0){
lcd.print("Back(lbs): ");
lcd.println(back);
}
else{
lcd.println("No Force ");
}
String dataString = "";
dataString += String(sensorVoltageF);
Serial.println(front);
Serial.println(back);
//dataString += " ";
//dataString += String(sensorVoltageB);

button1State = digitalRead(button1Pin);
if (button1State == HIGH){
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
File dataFile = SD.open("DATALOG.txt", FILE_WRITE);
// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening DATALOG.txt");
}
}
}

else if (xbee.getResponse().isError()) {
Serial.print("Error reading packet. Error code: ");
Serial.println(xbee.getResponse().getErrorCode());
}
}
}

          data = rx16.getData(4);
          data2=rx16.getData(6);
          data3=rx16.getData(8);
          data4=rx16.getData(10);
          //data=data*3.0/265.0;
          //data2=data2*3.0/265.0;
          //data3=data3*3.0/265.0;
          //data4=data4*3.0/265.0;
          front=data + data2;
          back=data3+data4;

Looks like you are adding high byte to low byte, rather than combining them into a 16 bit value.

Try printing out the data variables individually.

I have four analog signals coming from four different force sensitive resistors. So each data variable should be a separate analog value. When I print the individual data values I still have the issue with it resetting at ~260

What TYPE does rx16.getData() return?

That's a great question. Working on getting a good answer. From what I understand it is an array packaged into bytes regardless of what it is. Need to confirm that and not sure how to draw out the original analog signal if that is the case.

Code:

//#include <XBee.h>
#include <SoftwareSerial.h>
#include <AltSoftSerial.h>
#include <SPI.h>
#include <SD.h>
//import the xbee, software serial, SPI, and SD card libraries

XBee xbee = XBee();
XBeeResponse response = XBeeResponse();
Rx16IoSampleResponse rx16 = Rx16IoSampleResponse();

//define the two pins used for data transmission
//Dout on the XBee goes to pin 2 and Din goes to pin 3
#define ssRX 2
#define ssTX 3
SoftwareSerial lcd(ssRX, ssTX);
AltSoftSerial xbeeserial;

//variables for each of the four sensor values, the SD card, and the button
float data = 0;
float data2 = 0;
float data3 = 0;
float data4 = 0;
float front = 0;
float back = 0;
const int button1Pin = 4;  // pushbutton 1 pin
int button1State;
const int chipSelect = 10;

void setup() {
  // Set up the pushbutton and sd card pins:
  pinMode(button1Pin, INPUT);
  pinMode(chipSelect, OUTPUT);
  // start serial
  Serial.begin(9600);
  // and the software serial port
  lcd.begin(9600);
  // now that they are started, hook the XBee into
  // Software Serial
  xbeeserial.begin(9600); //new
  xbee.setSerial(xbeeserial);
  lcd.print("                                               ");
  Serial.println("starting up!");
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
}

void loop() {
  xbee.readPacket();
  //Serial.println("test");
  if (xbee.getResponse().isAvailable()) {
    // got something
    Serial.println();
    Serial.print("Frame Type is ");
    Serial.println(xbee.getResponse().getApiId(), HEX);

    if (xbee.getResponse().getApiId() == RX_16_IO_RESPONSE) {
      xbee.getResponse().getRx16IoSampleResponse(rx16);
      //prints the analog values from each of the sensors
      data = rx16.getData(4);
      data2 = rx16.getData(6);
      data3 = rx16.getData(8);
      data4 = rx16.getData(10);
      //data=data*3.0/265.0;
      //data2=data2*3.0/265.0;
      //data3=data3*3.0/265.0;
      //data4=data4*3.0/265.0;
      front = data + data2;
      back = data3 + data4;
      float sensorVoltageF = front * (3.0 / 1023.0);
      float sensorVoltageB = back * (3.0 / 1023.0);
      //double voltage2Pound = 6.8723*sensorVoltage*sensorVoltage*sensorVoltage - 3.7445*sensorVoltage*sensorVoltage + 7.1943*sensorVoltage - .2046;
      if (front != 0) {
        lcd.print("Frnt(lbs): ");
        lcd.println(front);
      } else if (back != 0) {
        lcd.print("Back(lbs): ");
        lcd.println(back);
      }
      else {
        lcd.println("No Force                  ");
      }
      String dataString = "";
      dataString += String(sensorVoltageF);
      Serial.println(data);
      Serial.println(data2);
      Serial.println(data3);
      Serial.println(data4);
      //dataString += " ";
      //dataString += String(sensorVoltageB);

      button1State = digitalRead(button1Pin);
      if (button1State == HIGH) {
        // open the file. note that only one file can be open at a time,
        // so you have to close this one before opening another.
        File dataFile = SD.open("DATALOG.txt", FILE_WRITE);
        // if the file is available, write to it:
        if (dataFile) {
          dataFile.println(dataString);
          dataFile.close();
          // print to the serial port too:
          Serial.println(dataString);
        }
        // if the file isn't open, pop up an error:
        else {
          Serial.println("error opening DATALOG.txt");
        }
      }
    }

    else if (xbee.getResponse().isError()) {
      Serial.print("Error reading packet.  Error code: ");
      Serial.println(xbee.getResponse().getErrorCode());
    }
  }
}

Please always do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code before posting it. This will make it easier for you to spot bugs and make it easier for us to read.

Please use code tags when you post code or warning/error messages. To do this, click the </> button on the forum toolbar, then paste the text you want to be in the code tags. Finally, move the cursor out of the code tags before adding any additional text you don't want to be in the code tags. If your browser doesn't show the posting toolbar, then you can manually add the code tags like this:
[code]``[color=blue]// your code is here[/color]``[/code]

The reason for doing this is that, without code tags, the forum software can interpret parts of your code as markup (the smiley face in your code above for example), leading to confusion, wasted time, and a reduced chance for you to get help with your problem. This will also make it easier for us to read your code and to copy it to the IDE or editor.

Using code tags and other important information is explained in the "How to use this forum" post. Please read it.

"I have four analog signals coming from four different force sensitive resistors."

So just how do you have these resistors connected to your Arduino? Just connecting the resistor to +5v and an analog input pin probably will not work as you may expect.

Yes I have been just connecting them from +5v to ground and an analog input pin. Why would that cause a problem?

"Yes I have been just connecting them from +5v to ground and an analog input pin. Why would that cause a problem?"

You probably need to use the force resistor along with a set resistor in a voltage divider circuit and connect the analog input pin between those two resistors.

This topic has been merged into API Mode XBee Series 1 Analog Sensor.

"You probably need to use the force resistor along with a set resistor in a voltage divider circuit and connect the analog input pin between those two resistors."

This actually is how I have it set up. I apologize for not being more clear.