Mehrere FSR-Sensoren mit Arduino Mega

So jetzt... war ein Tipfehler

const int fsrPins[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9}; // the FSR and 10K pulldown are connected to a0

const int Sensoranzahl = sizeof(fsrPins) / sizeof(int);

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];
unsigned long fsrweight [Sensoranzahl];
long fsrForce[Sensoranzahl];       // Finally, the resistance converted to force
int i;

void setup () 
{
  Serial.begin(9600);
}

void loop()
{
  for (i = 0; i < Sensoranzahl; i++) {

    fsrReading[i] = analogRead(fsrPins[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] = 500000;           // we measure in micromhos so
    fsrConductance[i] /= fsrResistance[i];
    Serial.print("Conductance in microMhos: ");
    Serial.println(fsrConductance[i]);

              //0.5   51
    if (fsrConductance[i] <= 5) {
      fsrForce[i] = fsrConductance[i] / 10 ;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}

          //0.75      76.5
      else{if (fsrConductance[i] <= 7.5) {
      fsrForce[i] = fsrConductance[i] / 10;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
         //1       101
      else{if (fsrConductance[i] <= 15) {
      fsrForce[i] = fsrConductance[i] / 15;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
       //1,25       126,5
      else{if (fsrConductance[i] <= 22.5) {
      fsrForce[i] = fsrConductance[i] / 18;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
       //1,5       152
      else{if (fsrConductance[i] <= 27.5) {
      fsrForce[i] = fsrConductance[i] / 18.3;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
        //1,75       177,5
      else{if (fsrConductance[i] <= 31.7) {
      fsrForce[i] = fsrConductance[i] / 18.1;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
         //2       203
      else{if (fsrConductance[i] <= 35.5) {
      fsrForce[i] = fsrConductance[i] / 17.75;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
       //2,25       228,5
      else{if (fsrConductance[i] <= 38) {
      fsrForce[i] = fsrConductance[i] / 16.8;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
       //2,5       254
      else{if (fsrConductance[i] <= 46.5) {
      fsrForce[i] = fsrConductance[i] / 18.6;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
       //2,75       279,5
      else{if (fsrConductance[i] <= 49.2) {
      fsrForce[i] = fsrConductance[i] / 17.89;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
        //3       305
      else{if (fsrConductance[i] <= 54.3) {
      fsrForce[i] = fsrConductance[i] / 18.1;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
        //3,25       330,5
      else{if (fsrConductance[i] <= 61) {
      fsrForce[i] = fsrConductance[i] / 18.77;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
       //3,5       356
      else{if (fsrConductance[i] <= 63) {
      fsrForce[i] = fsrConductance[i] / 18;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
       //3,75       381,5
      else{if (fsrConductance[i] <= 67.5) {
      fsrForce[i] = fsrConductance[i] / 18;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
       //4       407
      else{if (fsrConductance[i] <= 69) {
      fsrForce[i] = fsrConductance[i] / 17.25;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
      //4,25       432,5
      else{if (fsrConductance[i] <= 72.7) {
      fsrForce[i] = fsrConductance[i] / 17.1;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
       //4,5       458
      else{if (fsrConductance[i] <= 83) {
      fsrForce[i] = fsrConductance[i] / 18.4;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
      //4,75       483,5
      else{if (fsrConductance[i] <= 87) {
      fsrForce[i] = fsrConductance[i] / 18.3;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
      //5       509
      else{if (fsrConductance[i] <= 88.5) {
      fsrForce[i] = fsrConductance[i] / 17.7;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
      //5,25       534,5
      else{if (fsrConductance[i] <= 91.5) {
      fsrForce[i] = fsrConductance[i] / 17.4;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
      //5,5       560
      else{if (fsrConductance[i] <= 93.5) {
      fsrForce[i] = fsrConductance[i] / 17;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
      //5,75       585,5
      else{if (fsrConductance[i] <= 97) {
      fsrForce[i] = fsrConductance[i] / 16.8;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
      //6       611
      else{if (fsrConductance[i] <= 98.5) {
      fsrForce[i] = fsrConductance[i] / 16.4;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
      //6,25       636,5
      else{if (fsrConductance[i] <= 99) {
      fsrForce[i] = fsrConductance[i] / 15.84;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}

      //6,5       662
      else{if (fsrConductance[i] <= 102.5) {
      fsrForce[i] = fsrConductance[i] / 15.77;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}

       //6,75       687,5
      else{if (fsrConductance[i] <= 104.6) {
      fsrForce[i] = fsrConductance[i] / 15.5;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
        //7       713
      else{if (fsrConductance[i] <= 105.5) {
      fsrForce[i] = fsrConductance[i] / 15.07;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
         //7,25       738,5
      else{if (fsrConductance[i] <= 112) {
      fsrForce[i] = fsrConductance[i] / 15.45;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
      //7,5       764
      else{if (fsrConductance[i] <= 112.5) {
      fsrForce[i] = fsrConductance[i] / 15;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
       //7,75       789,5
      else{if (fsrConductance[i] <= 114) {
      fsrForce[i] = fsrConductance[i] / 14.71;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
      //8       815
      else{if (fsrConductance[i] <= 115) {
      fsrForce[i] = fsrConductance[i] / 14.37;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
       //8,25       840,5
      else{if (fsrConductance[i] <= 116.6) {
      fsrForce[i] = fsrConductance[i] / 14.13;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
        //8,5       866
      else{if (fsrConductance[i] <= 117.7) {
      fsrForce[i] = fsrConductance[i] / 13.85;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
       //8,75       891,5
      else{if (fsrConductance[i] <= 119) {
      fsrForce[i] = fsrConductance[i] / 13.6;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
       //9       917
      else{if (fsrConductance[i] <= 120) {
      fsrForce[i] = fsrConductance[i] / 13.33;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
      //9,25       942,5
      else{if (fsrConductance[i] <= 120.5) {
      fsrForce[i] = fsrConductance[i] / 13.03;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
      //9,5       968
      else{if (fsrConductance[i] <= 121) {
      fsrForce[i] = fsrConductance[i] / 12.73;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
      //9,75       993,5
      else{if (fsrConductance[i] <= 122.8) {
      fsrForce[i] = fsrConductance[i] / 12.59;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
      //10       1019
      else{if (fsrConductance[i] <= 124) {
      fsrForce[i] = fsrConductance[i] / 12.4;
      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i],4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i],4);}
      
      
     
      
      
   

          




           }}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}}
    }
     delay(2000);
  }

Um Gottes Willen...
Wenn ich einmal STRG-T drücke, da sehe ich ja nichts mehr.
Du hast das massiv unglücklich verschachtelt.
Und dann in jedem if wiederholt sich der Teil:

      fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce[i], 4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight[i], 4);

Das auslagern und nur aufrufen.
Ich schau mal, ob ich Dir was bauen kann....

:pray: Danke

Kannst Du mal probieren, ob der Code durchläuft?
Ichhabe jetzt nur erstmal geteilt und suchen & ersetzen gemacht.
Dann kann auch gesucht werden.

const byte fsrPins[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9}; // the FSR and 10K pulldown are connected to a0

const byte Sensoranzahl = sizeof(fsrPins) / sizeof(int);

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];
unsigned long fsrweight [Sensoranzahl];
long fsrForce[Sensoranzahl];       // Finally, the resistance converted to force

void setup ()
{
  Serial.begin(9600);
}

void loop()
{
  readSensors();
  rechneSensors();
  delay(2000);
}
void readSensors ()
{
  for (byte i = 0; i < Sensoranzahl; i++)
  {
    fsrReading[i] = analogRead(fsrPins[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]);
  }
}
void rechneSensors()
{
  for (byte i = 0; i < Sensoranzahl; i++)
  {
    if (fsrVoltage[i] == 0)
    {
      Serial.print(F("No pressure on Sensor "));
      Serial.println(i);
    }
    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(F("FSR resistance in ohms = "));
      Serial.println(fsrResistance[i]);
      fsrConductance[i] = 500000;           // we measure in micromhos so
      fsrConductance[i] /= fsrResistance[i];
      Serial.print("Conductance in microMhos: ");
      Serial.println(fsrConductance[i]);
      korrekturSensors(i);
    }
  }
}

void korrekturSensors(const byte i)
{
  //0.5   51
  if (fsrConductance[i] <= 5)
  {
    fsrForce[i] = fsrConductance[i] / 10 ;
  }
  //0.75      76.5
  else if (fsrConductance[i] <= 7.5)
  {
    fsrForce[i] = fsrConductance[i] / 10;
  }
  //1       101
  else if (fsrConductance[i] <= 15)
  {
    fsrForce[i] = fsrConductance[i] / 15;
  }
  //1,25       126,5
  else if (fsrConductance[i] <= 22.5)
  {
    fsrForce[i] = fsrConductance[i] / 18;
  }
  //1,5       152
  else if (fsrConductance[i] <= 27.5)
  {
    fsrForce[i] = fsrConductance[i] / 18.3;
  }
  //1,75       177,5
  else if (fsrConductance[i] <= 31.7)
  {
    fsrForce[i] = fsrConductance[i] / 18.1;
  }
  //2       203
  else if (fsrConductance[i] <= 35.5)
  {
    fsrForce[i] = fsrConductance[i] / 17.75;
  }
  //2,25       228,5
  else if (fsrConductance[i] <= 38)
  {
    fsrForce[i] = fsrConductance[i] / 16.8;
  }
  //2,5       254
  else if (fsrConductance[i] <= 46.5)
  {
    fsrForce[i] = fsrConductance[i] / 18.6;
  }
  //2,75       279,5
  else if (fsrConductance[i] <= 49.2)
  {
    fsrForce[i] = fsrConductance[i] / 17.89;
  }
  //3       305
  else if (fsrConductance[i] <= 54.3)
  {
    fsrForce[i] = fsrConductance[i] / 18.1;
  }
  //3,25       330,5
  else if (fsrConductance[i] <= 61)
  {
    fsrForce[i] = fsrConductance[i] / 18.77;
  }
  //3,5       356
  else if (fsrConductance[i] <= 63)
  {
    fsrForce[i] = fsrConductance[i] / 18;
  }
  //3,75       381,5
  else if (fsrConductance[i] <= 67.5)
  {
    fsrForce[i] = fsrConductance[i] / 18;
  }
  //4       407
  else if (fsrConductance[i] <= 69)
  {
    fsrForce[i] = fsrConductance[i] / 17.25;
  }
  //4,25       432,5
  else if (fsrConductance[i] <= 72.7)
  {
    fsrForce[i] = fsrConductance[i] / 17.1;
  }
  //4,5       458
  else if (fsrConductance[i] <= 83)
  {
    fsrForce[i] = fsrConductance[i] / 18.4;
  }
  //4,75       483,5
  else if (fsrConductance[i] <= 87)
  {
    fsrForce[i] = fsrConductance[i] / 18.3;
  }
  //5       509
  else if (fsrConductance[i] <= 88.5)
  {
    fsrForce[i] = fsrConductance[i] / 17.7;
  }
  //5,25       534,5
  else if (fsrConductance[i] <= 91.5)
  {
    fsrForce[i] = fsrConductance[i] / 17.4;
  }
  //5,5       560
  else if (fsrConductance[i] <= 93.5)
  {
    fsrForce[i] = fsrConductance[i] / 17;
  }
  //5,75       585,5
  else if (fsrConductance[i] <= 97)
  {
    fsrForce[i] = fsrConductance[i] / 16.8;
  }
  //6       611
  else if (fsrConductance[i] <= 98.5)
  {
    fsrForce[i] = fsrConductance[i] / 16.4;
  }
  //6,25       636,5
  else if (fsrConductance[i] <= 99)
  {
    fsrForce[i] = fsrConductance[i] / 15.84;
  }
  //6,5       662
  else if (fsrConductance[i] <= 102.5)
  {
    fsrForce[i] = fsrConductance[i] / 15.77;
  }
  //6,75       687,5
  else if (fsrConductance[i] <= 104.6)
  {
    fsrForce[i] = fsrConductance[i] / 15.5;
  }
  //7       713
  else if (fsrConductance[i] <= 105.5)
  {
    fsrForce[i] = fsrConductance[i] / 15.07;
  }
  //7,25       738,5
  else if (fsrConductance[i] <= 112)
  {
    fsrForce[i] = fsrConductance[i] / 15.45;
  }
  //7,5       764
  else if (fsrConductance[i] <= 112.5)
  {
    fsrForce[i] = fsrConductance[i] / 15;
  }
  //7,75       789,5
  else if (fsrConductance[i] <= 114)
  {
    fsrForce[i] = fsrConductance[i] / 14.71;
  }
  //8       815
  else if (fsrConductance[i] <= 115)
  {
    fsrForce[i] = fsrConductance[i] / 14.37;
  }
  //8,25       840,5
  else if (fsrConductance[i] <= 116.6)
  {
    fsrForce[i] = fsrConductance[i] / 14.13;
  }
  //8,5       866
  else if (fsrConductance[i] <= 117.7)
  {
    fsrForce[i] = fsrConductance[i] / 13.85;
  }
  //8,75       891,5
  else if (fsrConductance[i] <= 119)
  {
    fsrForce[i] = fsrConductance[i] / 13.6;
  }
  //9       917
  else if (fsrConductance[i] <= 120)
  {
    fsrForce[i] = fsrConductance[i] / 13.33;
  }
  //9,25       942,5
  else if (fsrConductance[i] <= 120.5)
  {
    fsrForce[i] = fsrConductance[i] / 13.03;
  }
  //9,5       968
  else if (fsrConductance[i] <= 121)
  {
    fsrForce[i] = fsrConductance[i] / 12.73;
  }
  //9,75       993,5
  else if (fsrConductance[i] <= 122.8)
  {
    fsrForce[i] = fsrConductance[i] / 12.59;
  }
  //10       1019
  else if (fsrConductance[i] <= 124)
  {
    fsrForce[i] = fsrConductance[i] / 12.4;
  }
  serialSensors(i);
}

void serialSensors(const byte i)
{
  fsrweight[i] =    fsrForce[i] / 9.81 * 1000 ;
  Serial.print(F("Gewichtskraft in Newton: "));
  Serial.println(fsrForce[i], 4);
  Serial.print(F("Gewicht in gramm: "));
  Serial.println(fsrweight[i], 4);
}

Hinweis:

muss geändert werden in:
const byte Sensoranzahl = sizeof(fsrPins);
Grund ist, das das array jetzt als byte deklariert ist.

Daher ist die bevorzugte Schreibweise
const byte Sensoranzahl = sizeof(fsrPins)/sizeof(fsrPins[0]);
Das bleibt immer richtig.

1 Like

Ich weiß es - und mache es doch immer wieder ... grr.

Besser die allgemeinere Variante
const byte Sensoranzahl = sizeof(fsrPins) / sizeof(fsrPins[0]);

Wer zu spät kommt ...

So,
Pause vorbei - ich hab das mal noch weiter runter gekürzt.
Du brauchst doch gar nicht alle Variablen als Array.

Dein Code braucht noch:

Der Sketch verwendet 5448 Bytes (2%) des Programmspeicherplatzes. Das Maximum sind 253952 Bytes.
Globale Variablen verwenden 602 Bytes (7%) des dynamischen Speichers, 7590 Bytes für lokale Variablen verbleiben. Das Maximum sind 8192 Bytes.

Meiner:

const byte fsrPins[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9}; // the FSR and 10K pulldown are connected to a0
const byte Sensoranzahl = sizeof(fsrPins)/sizeof(fsrPins[0]);

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;  // The voltage converted to resistance, can be very big so make "long"
unsigned long fsrConductance;
unsigned long fsrweight;
long fsrForce;       // Finally, the resistance converted to force

void setup ()
{
  Serial.begin(115200);
}

void loop()
{
  readSensors();
  rechneSensors();
  delay(2000);
}
void readSensors ()
{
  for (byte i = 0; i < Sensoranzahl; i++)
  {
    fsrReading[i] = analogRead(fsrPins[i]);
    Serial.print(F("Analog reading Port "));
    Serial.print(i);
    Serial.print(": ");
    Serial.println(fsrReading[i]);
    fsrVoltage[i] = map(fsrReading[i], 0, 1023, 0, 5000);
    Serial.print(F("Voltage reading in mV = "));
    Serial.println(fsrVoltage[i]);
  }
}
void rechneSensors()
{
  for (byte i = 0; i < Sensoranzahl; i++)
  {
    if (fsrVoltage[i] == 0)
    {
      Serial.print(F("No pressure on Sensor "));
      Serial.println(i);
    }
    else
    {
      // The voltage = Vcc * R / (R + FSR) where R = 10K and Vcc = 5V
      // so FSR = ((Vcc - V) * R) / V
      fsrResistance = 5000 - fsrVoltage[i];     // fsrVoltage is in millivolts so 5V = 5000mV
      fsrResistance *= 10000;                // 10K resistor
      fsrResistance /= fsrVoltage[i];
      Serial.print(F("FSR resistance in ohms = "));
      Serial.println(fsrResistance);
      fsrConductance = 500000;           // we measure in micromhos so
      fsrConductance /= fsrResistance;
      Serial.print("Conductance in microMhos: ");
      Serial.println(fsrConductance);
      korrekturSensors();
    }
  }
}

void korrekturSensors()
{
  // *INDENT-OFF*
  //0.5   51
  if (fsrConductance <= 5)          fsrForce = fsrConductance / 10;
  //0.75      76.5
  else if (fsrConductance <= 7.5)   fsrForce = fsrConductance / 10;
  //1       101
  else if (fsrConductance <= 15)    fsrForce = fsrConductance / 15;
  //1,25       126,5
  else if (fsrConductance <= 22.5)  fsrForce = fsrConductance / 18;
  //1,5       152
  else if (fsrConductance <= 27.5)  fsrForce = fsrConductance / 18.3;
  //1,75       177,5
  else if (fsrConductance <= 31.7)  fsrForce = fsrConductance / 18.1;
  //2       203
  else if (fsrConductance <= 35.5)  fsrForce = fsrConductance / 17.75;
  //2,25       228,5
  else if (fsrConductance <= 38)    fsrForce = fsrConductance / 16.8;
  //2,5       254
  else if (fsrConductance <= 46.5)  fsrForce = fsrConductance / 18.6;
  //2,75       279,5
  else if (fsrConductance <= 49.2)  fsrForce = fsrConductance / 17.89;
  //3       305
  else if (fsrConductance <= 54.3)  fsrForce = fsrConductance / 18.1;
  //3,25       330,5
  else if (fsrConductance <= 61)    fsrForce = fsrConductance / 18.77;
  //3,5       356
  else if (fsrConductance <= 63)    fsrForce = fsrConductance / 18;
  //3,75       381,5
  else if (fsrConductance <= 67.5)  fsrForce = fsrConductance / 18;
  //4       407
  else if (fsrConductance <= 69)    fsrForce = fsrConductance / 17.25;
  //4,25       432,5
  else if (fsrConductance <= 72.7)  fsrForce = fsrConductance / 17.1;
  //4,5       458
  else if (fsrConductance <= 83)    fsrForce = fsrConductance / 18.4;
  //4,75       483,5
  else if (fsrConductance <= 87)    fsrForce = fsrConductance / 18.3;
  //5       509
  else if (fsrConductance <= 88.5)  fsrForce = fsrConductance / 17.7;
  //5,25       534,5
  else if (fsrConductance <= 91.5)  fsrForce = fsrConductance / 17.4;
  //5,5       560
  else if (fsrConductance <= 93.5)  fsrForce = fsrConductance / 17;
  //5,75       585,5
  else if (fsrConductance <= 97)    fsrForce = fsrConductance / 16.8;
  //6       611
  else if (fsrConductance <= 98.5)  fsrForce = fsrConductance / 16.4;
  //6,25       636,5
  else if (fsrConductance <= 99)    fsrForce = fsrConductance / 15.84;
  //6,5       662
  else if (fsrConductance <= 102.5) fsrForce = fsrConductance / 15.77;
  //6,75       687,5
  else if (fsrConductance <= 104.6) fsrForce = fsrConductance / 15.5;
  //7       713
  else if (fsrConductance <= 105.5) fsrForce = fsrConductance / 15.07;
  //7,25       738,5
  else if (fsrConductance <= 112)   fsrForce = fsrConductance / 15.45;
  //7,5       764
  else if (fsrConductance <= 112.5) fsrForce = fsrConductance / 15;
  //7,75       789,5
  else if (fsrConductance <= 114)   fsrForce = fsrConductance / 14.71;
  //8       815
  else if (fsrConductance <= 115)   fsrForce = fsrConductance / 14.37;
  //8,25       840,5
  else if (fsrConductance <= 116.6) fsrForce = fsrConductance / 14.13;
  //8,5       866
  else if (fsrConductance <= 117.7) fsrForce = fsrConductance / 13.85;
  //8,75       891,5
  else if (fsrConductance <= 119)   fsrForce = fsrConductance / 13.6;
  //9       917
  else if (fsrConductance <= 120)   fsrForce = fsrConductance / 13.33;
  //9,25       942,5
  else if (fsrConductance <= 120.5) fsrForce = fsrConductance / 13.03;
  //9,5       968
  else if (fsrConductance <= 121)   fsrForce = fsrConductance / 12.73;
  //9,75       993,5
  else if (fsrConductance <= 122.8) fsrForce = fsrConductance / 12.59;
  //10       1019
  else if (fsrConductance <= 124)   fsrForce = fsrConductance / 12.4;
  serialSensors();
  // *INDENT-ON*
}

void serialSensors()
{
  fsrweight = fsrForce / 9.81 * 1000 ;
  Serial.print(F("Gewichtskraft in Newton: "));
  Serial.println(fsrForce, 4);
  Serial.print(F("Gewicht in gramm: "));
  Serial.println(fsrweight, 4);
}
Der Sketch verwendet 5148 Bytes (2%) des Programmspeicherplatzes. Das Maximum sind 253952 Bytes.
Globale Variablen verwenden 320 Bytes (3%) des dynamischen Speichers, 7872 Bytes für lokale Variablen verbleiben. Das Maximum sind 8192 Bytes.

Und ich seh auch nichts schwerwiegendes, was da jetzt schief gehen sollte bei der Berechnung.

Es gibt noch eine Möglichkeit, die Größe eines Arrays herauszufinden.
Zumindest mir, gefällt sie besser, als die sizeof Variante.
Sie ist ebenso konstant und hat kein Laufzeitverhalten.

#include <Streaming.h> // die Lib findest du selber ;-)
Stream &cout = Serial; // cout Emulation für "Arme"


template<typename ArrayType, size_t count>
constexpr size_t arrayCount(const ArrayType (&)[count])
{
  return count;
}



const byte fsrPins[] = {A0, A1, A2, A3, A4, A5, A6, A7, A8, A9}; // the FSR and 10K pulldown are connected to a0

const size_t Sensoranzahl = arrayCount(fsrPins);

void setup()
{
  Serial.begin(9600);
  cout << F("Start: ") << F(__FILE__) << endl;
  cout << Sensoranzahl << endl;

   for (unsigned i = 0; i < arrayCount(fsrPins); i++)
  {
    // tuwas mit i
  }
}

void loop()
{
}
2 Likes

@combie Klasse! Das wird gleich ins Repertoire aufgenommen! :+1:

Sorry.. ich war gerade beim Zahnarzt. Ich habe den Code soeben getestet. So siehts aktuell aus. Der obere linke Block baut sich von oben nach unten auf. Anschließen ergeben sich von links nach rechts fast zeilenweise Hieroglyphen.
Ich bedanke mich schon mal vielmals für Euren Einsatz. Richtig gut :ok_hand: :blush:

Mein Beileid.
Ich muss nicht mehr hin :wink:

Du musst im SerMon unten rechts auf 115200 einstellen.

War zum Glück nur Kontrolle. :grin:.

Das sieht schon mal richtig geil aus :muscle:. Eine Sache ist mir aufgefallen. Er zeigt mir die Newton 4 bis 9 nicht an. 10-13 wird gezeigt und 14-19 dann wieder nicht. Und kann man sich auch eine Stelle nach dem Komma anzeigen lassen.

Ich weiss... Schau mal, auf wie wenig Zeilen das runter ist :wink:
Im übrigen habe ich schon den Code auf unter 5000 Programmspeicher...
Aber das:

Muss man sehen. Allerdings kann ich Dir sagen, das die ganzen Komma-Divisionen nicht schick sind.

Kannst Du mal bitte folgendes machen:
Das delay() ruhig auf 5000 oder mehr setzen.
danach den Code hochladen und danach den SerMon öffnen.
Wenn Du den Teil mit den fehlenden hast, einmal STRG-A und STRG-C drücken und hier in Codetags mit dem </> Button einfügen.
(Erst den Button drücken, dann STRG-V)
Das wird...

Da hab ich dann schon mal was ganz schickes zum lesen...

Noch n Nachtrag:
Wenn Du nur den einen Sensor testen willst, mach mal ganz oben:

//const byte Sensoranzahl = sizeof(fsrPins) / sizeof(fsrPins[0]);
const byte Sensoranzahl = 1;

damit die leeren Abfragen nicht mitlaufen.

So da ist er

Analog reading Port 0: 408
Voltage reading in mV = 1994
FSR resistance in ohms = 15075
Conductance in microMhos: 33
Gewichtskraft in Newton: 1
Gewicht in gramm: 1211
Analog reading Port 0: 545
Voltage reading in mV = 2663
FSR resistance in ohms = 8775
Conductance in microMhos: 56
Gewichtskraft in Newton: 2
Gewicht in gramm: 3023
Analog reading Port 0: 572
Voltage reading in mV = 2795
FSR resistance in ohms = 7889
Conductance in microMhos: 63
Gewichtskraft in Newton: 3
Gewicht in gramm: 10301
Analog reading Port 0: 614
Voltage reading in mV = 3000
FSR resistance in ohms = 6666
Conductance in microMhos: 75
Gewichtskraft in Newton: 10
Gewicht in gramm: 12113
Analog reading Port 0: 619
Voltage reading in mV = 3025
FSR resistance in ohms = 6528
Conductance in microMhos: 76
Gewichtskraft in Newton: 10
Gewicht in gramm: 12113
Analog reading Port 0: 636
Voltage reading in mV = 3108
FSR resistance in ohms = 6087
Conductance in microMhos: 82
Gewichtskraft in Newton: 10
Gewicht in gramm: 12113
Analog reading Port 0: 683
Voltage reading in mV = 3338
FSR resistance in ohms = 4979
Conductance in microMhos: 100
Gewichtskraft in Newton: 12
Gewicht in gramm: 21203
Analog reading Port 0: 713
Voltage reading in mV = 3484
FSR resistance in ohms = 4351
Conductance in microMhos: 114
Gewichtskraft in Newton: 13
Gewicht in gramm: 23021
Analog reading Port 0: 727
Voltage reading in mV = 3553
FSR resistance in ohms = 4072
Conductance in microMhos: 122
Gewichtskraft in Newton: 21

Moment,
das ist doch ein Rechenfehler.

Wenn die Berechnung Werte "auslassen" würde, würde trotzdem ein weiterer analogwert an Port0 gelesen und angezeigt.
Dafür habe ich das aufgeteilt.
Die Funktion readSensor ist in sich abgeschlossen.

Hm.. Na mal sehen, ob Du den Fehler findest - ich such mal auch, denke aber, das das mit dem Teilen nicht passt.

Ersetze mal die erste Zeile in serialSensors()

  fsrweight = ((fsrForce * 100000) / 981) ;

Ok, Dein Problem ist

long fsrForce;       // Finally, the resistance converted to force

Also nochmal zurück auf Anfang.
Ich würde die ganze Kommarechnerei weglassen und den Wert erst mit einem festen Wert multiplizieren (10000?) und dann durch den Korrekturwert dividieren.

fsrForce = (fsrConductance*10000) / 1877;

dann kommt was Ganzzahliges raus, mit dem weiter gearbeitet werden kann.

Ok das habe ich getan...
Grundsätzlich verhält er sich wie zuvor. Also es werden die besagten Werte ausgelassen.
Zusätzlich fällt mir auf, dass wenn ich schlagartig Druck drauf gebe, friert die Berechnung für fsrForce ein. Die anderen Werte variieren dann weiterhin. Kann ich oben eigentlich in der Deklaration float setzen?. So war der Urcode beschrieben.

Gewicht in gramm: 22201233
Analog reading Port 0: 767
Voltage reading in mV = 3748
FSR resistance in ohms = 3340
Conductance in microMhos: 149
Gewichtskraft in Newton: 12213
Gewicht in gramm: 22201233
Analog reading Port 0: 761
Voltage reading in mV = 3719
FSR resistance in ohms = 3444
Conductance in microMhos: 145
Gewichtskraft in Newton: 12213
Gewicht in gramm: 22201233
Analog reading Port 0: 754
Voltage reading in mV = 3685
FSR resistance in ohms = 3568
Conductance in microMhos: 140
Gewichtskraft in Newton: 12213
Gewicht in gramm: 22201233
Analog reading Port 0: 750
Voltage reading in mV = 3665
FSR resistance in ohms = 3642
Conductance in microMhos: 137
Gewichtskraft in Newton: 12213
Gewicht in gramm: 22201233
Analog reading Port 0: 751
Voltage reading in mV = 3670
FSR resistance in ohms = 3623
Conductance in microMhos: 138
Gewichtskraft in Newton: 12213
Gewicht in gramm: 22201233
Analog reading Port 0: 768
Voltage reading in mV = 3753
FSR resistance in ohms = 3322
Conductance in microMhos: 150
Gewichtskraft in Newton: 12213
Gewicht in gramm: 22201233
Analog reading Port 0: 782
Voltage reading in mV = 3822
FSR resistance in ohms = 3082
Conductance in microMhos: 162
Gewichtskraft in Newton: 12213
Gewicht in gramm: 22201233
Analog reading Port 0: 787
Voltage reading in mV = 3846
FSR resistance in ohms = 3000
Conductance in microMhos: 166
Gewichtskraft in Newton: 12213
Gewicht in gramm: 22201233
Analog reading Port 0: 776
Voltage reading in mV = 3792
FSR resistance in ohms = 3185
Conductance in microMhos: 156
Gewichtskraft in Newton: 12213
Gewicht in gramm: 22201233
Analog reading Port 0: 766
Voltage reading in mV = 3743
FSR resistance in ohms = 3358
Conductance in microMhos: 148
Gewichtskraft in Newton: 12213
Gewicht in gramm: 22201233
Analog reading Port 0: 766

Urcode für einen Sensor

int fsrPin = 0;     // the FSR and 10K pulldown are connected to a0
float fsrReading;     // the analog reading from the FSR resistor divider
float fsrVoltage;     // the analog reading converted to voltage
float fsrResistance;  // The voltage converted to resistance, can be very big so make "long"
float fsrConductance; 
float fsrForce;       // Finally, the resistance converted to force
float fsrweight;
void setup(void) {
  Serial.begin(9600);   // We'll send debugging information via the Serial monitor
}
 
void loop(void) {
  fsrReading = analogRead(fsrPin);  
  Serial.print("Analog reading = ");
  Serial.println(fsrReading);
 
  // analog voltage reading ranges from about 0 to 1023 which maps to 0V to 5V (= 5000mV)
  fsrVoltage = map(fsrReading, 0, 1023, 0, 5000);
  Serial.print("Voltage reading in mV = ");
  Serial.println(fsrVoltage);  
 
  if (fsrVoltage == 0) {
    Serial.println("No pressure");  
  } else {
    // 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;
    Serial.print("FSR Wiederstand in Ohm = ");
    Serial.println(fsrResistance);
 
    fsrConductance = 500000;           // we measure in micromhos so 
    fsrConductance /= fsrResistance;
    Serial.print("Conductance in microMhos: ");
    Serial.println(fsrConductance);
 
    // Mehrere lineare Gleichungen, um den Kraft zu approximieren. Auf Leitfähigkeit sind 10% mehr angesetzt und der Teiler 10% weniger

              //0.5   51
    if (fsrConductance <= 5) {
      fsrForce = fsrConductance / 10 ;
      fsrweight =    fsrForce / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce,4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight,4);}

          //0.75      76.5
      else{if (fsrConductance <= 7.5) {
      fsrForce = fsrConductance / 10;
      fsrweight =    fsrForce / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce,4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight,4);}
      
         //1       101
      else{if (fsrConductance <= 15) {
      fsrForce = fsrConductance / 15;
      fsrweight =    fsrForce / 9.81 * 1000 ;
      Serial.print("Gewichtskraft in Newton: ");
      Serial.println(fsrForce,4);
      Serial.print("Gewicht in gramm: ");
      Serial.println(fsrweight,4);}
.......................

Ja, könntest Du.
Ich hatte das auch schon vermutet, das da was umgeschrieben wurde. Denn das, was Du als Phänomen hast, hängt schon vorher mit fsrConductance.

Was mich noch immer umtreibt, ist Dein Teiler. Der steigt langsam an und später fällt er wieder ab - das würde bedeuten, das mit seigendem Wert für fsrConductance der Druck erst steigt und später wieder fällt.
Das ist doch nicht richtig oder hat der Sensor so ne Kurve?
Alles was ich bisher geshen habe, das ab einem bestimmten Druck der Widerstandswert rapide abnimmt und im weiteren Verlauf stegig weiter....