Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int fsrPins[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9}; // the FSR and 10K pulldown are connected to a0
- int Sensoranzahl = sizeof(fsrPins);
- unsigned long fsrReading[Sensoranzahl]; // the analog reading from the FSR resistor divider
- unsigned long fsrVoltage[Sensoranzahl]; // the analog reading converted to voltage
- unsigned long fsrResistance[Sensoranzahl]; // The voltage converted to resistance, can be very big so make "long"
- unsigned long fsrConductance[Sensoranzahl];
- long fsrForce[Sensoranzahl]; // Finally, the resistance converted to force
- for (i = 0; i < Sensoranzahl; i++) {
- fsrReading[i] = analogRead(fsrPin[i]);
- Serial.print("Analog reading = ");
- Serial.println(fsrReading[i]);
- 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]);
- } 9807
- }
- Serial.println("--------------------");
- delay(1000);
- }
- }
Add Comment
Please, Sign In to add comment