I have written code on the Arduino to record the pressure applied to a FSR sensor connected to pin A0. Here is my code
int pressureAnalogPin = 0; //pin where our pressure pad is located.
int pressureReading; //variable for storing our reading
bool active = false; //boolean to check whether arduino should be sending pressure values
void setup()
{
Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
}
void loop()
{
if (Serial.available()) //checks if data is coming in
{
char read = Serial.read(); //Set varaiable read to data read from mobile
if (read == 'g') //if read is equal to character 'g' set boolean active to true
{
active = true;
}
if (read == 'x') //if read is equal to character 'x' set boolean active to false
{
active = false;
}
}
if (active == true) //Only send data to phone when boolean active is set to true
{
pressureReading = analogRead(pressureAnalogPin); // Set varaible pressureReading to the pressure value recorded by FSR
Serial.print(pressureReading); //Send pressure value to mobile phone
}
delay(100);// a delay of 100ms in loop
}
I receive results from 0 to 1023. I have conducted an experiment, by incrementing weights on top of the pressure sensor.
Above is an excel chart showing the increase in weight and the pressure recorded.
Can someone let me know what is the unit is for these pressure readings?
As you gave already measured and calibrated the sensor with weights 50 - 800 gram according to your Excel, you have the option to use two methods (provided you use the same setup as in your calibration.
Oprion one programatically with map
for each interval
which in your case will produce very imprecise measurements as you have to have if and than map.
Or you calculate the whole range with EXCEL interpolate function than you get for every of the 1024 data points a gram value which you store in an array and retrieve with:
BUT for real use you will probably need an additional circuit, the manufacturers calibration data and a stable power supply. For playing around and learning this shoot and hope its a hit method is ok.
AND this is the sellers recommendation:
Datasheet for the sensor including all the calibration circuits