Output force readings on LCD from 4 inputs

Thread Starter

Amy Yu

Joined Oct 14, 2015
5
'm dealing a project that requires 4 force sensors as analog input of Arduino Uno and output the force readings on a 16x2 LCD. It's actually for the assessment of each finger strength of the rehab patient while using the device as illustrated in the figure below. I'm completely new to this, but I have found somebody posted the coding for displaying the force consecutively. I would like to know if it is possible to display the forces simultaneously, or someone has a better idea on how to make this works? Need advices for coding as well, thanks very much!




C:
int fsrVoltage; // the analog reading converted to voltage
int fsrVoltage1;
unsigned long fsrResistance; // The voltage converted to resistance, can be very big so make "long"
unsigned long fsrResistance1;
unsigned long fsrConductance;
unsigned long fsrConductance1;
long fsrForce; // Finally, the resistance converted to force
long fsrForce1;

#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>

Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
void setup()
{

lcd.begin(16, 2);

Serial.begin(9600);

}

void loop()
{


int force = analogRead(A0);
int force1 = analogRead(A1);

fsrVoltage = map(force, 0, 1023, 0, 5000);

// The voltage = Vcc * R / (R + FSR) where R = 10K and Vcc = 5V
// so FSR = ((Vcc - V) * R) / V yay math!
fsrResistance = 5000 - fsrVoltage; // fsrVoltage is in millivolts so 5V = 5000mV
fsrResistance *= 10000; // 10K resistor
fsrResistance /= fsrVoltage;
fsrConductance = 1000000; // we measure in micromhos so
fsrConductance /= fsrResistance;

fsrVoltage1 = map(force1, 0, 1023, 0, 5000);

// The voltage = Vcc * R / (R + FSR) where R = 10K and Vcc = 5V
// so FSR = ((Vcc - V) * R) / V yay math!
fsrResistance1 = 5000 - fsrVoltage1; // fsrVoltage is in millivolts so 5V = 5000mV
fsrResistance1 *= 10000; // 10K resistor
fsrResistance1 /= fsrVoltage1;
fsrConductance1 = 1000000; // we measure in micromhos so
fsrConductance1 /= fsrResistance1;



// Use the two FSR guide graphs to approximate the force
if (fsrConductance <= 1000)
{
fsrForce = fsrConductance / 80;
lcd.setCursor(0, 0);
lcd.print("Force for 1st FSR: ");
lcd.setCursor(0, 1);
lcd.print(fsrForce,DEC);
} else
{
fsrForce = fsrConductance - 1000;
fsrForce /= 30;
lcd.setCursor(0, 0);
lcd.print("Force for 1st FSR: ");
lcd.setCursor(0, 1);
lcd.print(fsrForce,DEC);
}
delay(5000);

if (fsrConductance1 <= 1000)
{
fsrForce1 = fsrConductance1 / 80;
lcd.setCursor(0, 0);
lcd.print("Force for 2nd FSR: ");
lcd.setCursor(0, 1);
lcd.print(fsrForce1,DEC);
}
else
{
fsrForce1 = fsrConductance1 - 1000;
fsrForce1 /= 30;
lcd.setCursor(0, 0);
lcd.print("Force for 2nd FSR: ");
lcd.setCursor(0, 1);
lcd.print(fsrForce1,DEC);
}
delay(200);
}
Moderators note: used code=c tags
 
Last edited by a moderator:

GopherT

Joined Nov 23, 2012
7,983
'm dealing a project that requires 4 force sensors as analog input of Arduino Uno and output the force readings on a 16x2 LCD. It's actually for the assessment of each finger strength of the rehab patient while using the device as illustrated in the figure below. I'm completely new to this, but I have found somebody posted the coding for displaying the force consecutively. I would like to know if it is possible to display the forces simultaneously, or someone has a better idea on how to make this works? Need advices for coding as well, thanks very much!




int fsrVoltage; // the analog reading converted to voltage
int fsrVoltage1;
unsigned long fsrResistance; // The voltage converted to resistance, can be very big so make "long"
unsigned long fsrResistance1;
unsigned long fsrConductance;
unsigned long fsrConductance1;
long fsrForce; // Finally, the resistance converted to force
long fsrForce1;

#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>

Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
void setup()
{

lcd.begin(16, 2);

Serial.begin(9600);

}

void loop()
{


int force = analogRead(A0);
int force1 = analogRead(A1);

fsrVoltage = map(force, 0, 1023, 0, 5000);

// The voltage = Vcc * R / (R + FSR) where R = 10K and Vcc = 5V
// so FSR = ((Vcc - V) * R) / V yay math!
fsrResistance = 5000 - fsrVoltage; // fsrVoltage is in millivolts so 5V = 5000mV
fsrResistance *= 10000; // 10K resistor
fsrResistance /= fsrVoltage;
fsrConductance = 1000000; // we measure in micromhos so
fsrConductance /= fsrResistance;

fsrVoltage1 = map(force1, 0, 1023, 0, 5000);

// The voltage = Vcc * R / (R + FSR) where R = 10K and Vcc = 5V
// so FSR = ((Vcc - V) * R) / V yay math!
fsrResistance1 = 5000 - fsrVoltage1; // fsrVoltage is in millivolts so 5V = 5000mV
fsrResistance1 *= 10000; // 10K resistor
fsrResistance1 /= fsrVoltage1;
fsrConductance1 = 1000000; // we measure in micromhos so
fsrConductance1 /= fsrResistance1;



// Use the two FSR guide graphs to approximate the force
if (fsrConductance <= 1000)
{
fsrForce = fsrConductance / 80;
lcd.setCursor(0, 0);
lcd.print("Force for 1st FSR: ");
lcd.setCursor(0, 1);
lcd.print(fsrForce,DEC);
} else
{
fsrForce = fsrConductance - 1000;
fsrForce /= 30;
lcd.setCursor(0, 0);
lcd.print("Force for 1st FSR: ");
lcd.setCursor(0, 1);
lcd.print(fsrForce,DEC);
}
delay(5000);

if (fsrConductance1 <= 1000)
{
fsrForce1 = fsrConductance1 / 80;
lcd.setCursor(0, 0);
lcd.print("Force for 2nd FSR: ");
lcd.setCursor(0, 1);
lcd.print(fsrForce1,DEC);
}
else
{
fsrForce1 = fsrConductance1 - 1000;
fsrForce1 /= 30;
lcd.setCursor(0, 0);
lcd.print("Force for 2nd FSR: ");
lcd.setCursor(0, 1);
lcd.print(fsrForce1,DEC);
}
delay(200);
}

Every character on a 2x16 can be addressed individually and you can certainly display each value as needed in a given position on the display. There is a good tutorial on LCD displays - an old two part document from EDN article (I think).
 
Top