Reschko

mehrere FSR Sensoren

Sep 24th, 2021
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. int fsrPins[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9}; // the FSR and 10K pulldown are connected to a0
  2.  
  3. int Sensoranzahl = sizeof(fsrPins);
  4.  
  5. unsigned long fsrReading[Sensoranzahl]; // the analog reading from the FSR resistor divider
  6. unsigned long fsrVoltage[Sensoranzahl]; // the analog reading converted to voltage
  7. unsigned long fsrResistance[Sensoranzahl]; // The voltage converted to resistance, can be very big so make "long"
  8. unsigned long fsrConductance[Sensoranzahl];
  9. long fsrForce[Sensoranzahl]; // Finally, the resistance converted to force
  10.  
  11. for (i = 0; i < Sensoranzahl; i++) {
  12.  
  13. fsrReading[i] = analogRead(fsrPin[i]);
  14. Serial.print("Analog reading = ");
  15. Serial.println(fsrReading[i]);
  16.  
  17. fsrVoltage[i] = map(fsrReading[i], 0, 1023, 0, 5000);
  18. Serial.print("Voltage reading in mV = ");
  19. Serial.println()fsrVoltage[i]);
  20. }
  21.  
  22. if (fsrVoltage[i] == 0) {
  23. Serial.println("No pressure");
  24. } else {
  25. // The voltage = Vcc * R / (R + FSR) where R = 10K and Vcc = 5V
  26. // so FSR = ((Vcc - V) * R) / V
  27. fsrResistance[i] = 5000 - fsrVoltage[i]; // fsrVoltage is in millivolts so 5V = 5000mV
  28. fsrResistance[i] *= 10000; // 10K resistor
  29. fsrResistance[i] /= fsrVoltage[i];
  30. Serial.print("FSR resistance in ohms = ");
  31. Serial.println(fsrResistance[i]);
  32.  
  33. fsrConductance[i] = 1000000; // we measure in micromhos so
  34. fsrConductance[i] /= fsrResistance[i];
  35. Serial.print("Conductance in microMhos: ");
  36. Serial.println(fsrConductance[i]);
  37.  
  38. // Use the two FSR guide graphs to approximate the force
  39. if (fsrConductance[i] <= 1000) {
  40. fsrForce[i] = fsrConductance[i] / 80;
  41. Serial.print("Force in Newtons: ");
  42. Serial.println(fsrForce[i]);
  43. } else {
  44. fsrForce[i] = fsrConductance[i] - 1000;
  45. fsrForce[i] /= 30;
  46. Serial.print("Force in Newtons: ");
  47. Serial.println(fsrForce[i]);
  48. } 9807
  49. }
  50. Serial.println("--------------------");
  51. delay(1000);
  52. }
  53. }
Add Comment
Please, Sign In to add comment