Hi ![]()
I have a 5 fsr sensors which I want to connect to Arduino UNO.
The code thtat I've found for one sensor is working but I want to write a routine which will let the same solutions for 5 sensor.
This is my code (it is not compiling)
/* FSR testing sketch.
Connect one end of FSR to power, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground
*/
int i=0;
int fsrPin = 0; // the FSR and 10K pulldown are connected to a0
int fsrPin1 = 1;
int fsrpin2 = 2;
int fsrPin3 = 3;
int fsrPin4 = 4;
unsigned long fsrReading; // the analog reading from the FSR resistor divider
unsigned long fsrReading1;
unsigned long fsrReading2;
unsigned long fsrReading3;
unsigned long fsrReading4;
unsigned long fsrVoltage; // the analog reading converted to voltage
unsigned long fsrVoltage1;
unsigned long fsrVoltage2;
unsigned long fsrVoltage3;
unsigned long fsrVoltage4;
unsigned long fsrResistance; // The voltage converted to resistance, can be very big so make "long"
unsigned long fsrResistance1;
unsigned long fsrResistance2;
unsigned long fsrResistance3;
unsigned long fsrResistance4;
unsigned long fsrConductance;
unsigned long fsrConductance1;
unsigned long fsrConductance2;
unsigned long fsrConductance3;
unsigned long fsrConductance4;
long fsrForce; // Finally, the resistance converted to force
long fsrForce1;
long fsrForce2;
long fsrForce3;
long fsrForce4;
long fsrForce5;
void setup(void) {
Serial.begin(9600); // We'll send debugging information via the Serial monitor
}
void loop(void) {
for(i=0; i<5 ;i++){
fsrReading(i) = analogRead(fsrPin(i));
/*fsrReading1 = analogRead(fsrPin1);
fsrReading2 = analogRead(fsrPin2);
fsrReading3 = analogRead(fsrPin3);
fsrReading4 = analogRead(fsrPin4);
fsrReading5 = analogRead(fsrPin5);*/
Serial.print("Analog reading = ");
Serial.println(fsrReading);
// analog voltage reading ranges from about 0 to 1023 which maps to 0V to 5V (= 5000mV)
fsrVoltage(i) = map(fsrReading(i), 0, 1023, 0, 5000);
Serial.print("Voltage reading in mV = ");
Serial.println(fsrVoltage(i));
if (fsrVoltage(i) == 0) {
Serial.println("No pressure");
} else {
// The voltage = Vcc * R / (R + FSR) where R = 10K and Vcc = 5V
// so FSR = ((Vcc - V) * R) / V
fsrResistance(i) = 5000 - fsrVoltage(i); // fsrVoltage is in millivolts so 5V = 5000mV
fsrResistance(i) *= 10000; // 10K resistor
fsrResistance(i) /= fsrVoltage(i);
Serial.print("FSR resistance in ohms = ");
Serial.println(fsrResistance(i));
fsrConductance(i) = 1000000; // we measure in micromhos so
fsrConductance(i) /= fsrResistance(i);
Serial.print("Conductance in microMhos: ");
Serial.println(fsrConductance(i));
// Use the two FSR guide graphs to approximate the force
if (fsrConductance(i) <= 1000) {
fsrForce(i) = fsrConductance(i) / 80;
Serial.print("Force in Newtons: ");
Serial.println(fsrForce(i));
} else {
fsrForce(i) = fsrConductance(i) - 1000;
fsrForce(i) /= 30;
Serial.print("Force in Newtons: ");
Serial.println(fsrForce(i));
}
}
Serial.println("--------------------");
delay(1000);
}
}
thanks ![]()