如何减少/消除FSR传感器的波动?

问题描述 投票:0回答:0

以下代码用于将 6 个 FST 38.1mm 方形 FSR 与 Arduino UNO 连接。

/* 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 
 
For more information see www.ladyada.net/learn/sensors/fsr.html */

int fsrPins[] = {0, 1, 2, 3, 4, 5}; // Array to store all FSR pin numbers
int numFSRs = 6; // Number of FSRs connected
float fsrReadings[6]; // Array to store analog readings from each FSR
double fsrVoltages[6]; // Array to store voltages for each FSR
double fsrResistances[6]; // Array to store resistances for each FSR
double fsrConductances[6]; // Array to store conductances for each FSR
double fsrForces[6]; // Array to store forces for each FSR
double fsrWeights[6]; // Array to store weights for each FSR

int interval = 1; // Time interval between readings (in milliseconds)
unsigned long previousMillis = 0;

void setup(void) {
  Serial.begin(9600); // We'll send debugging information via the Serial monitor
}

void loop(void) {
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    processFSRReadings(); // Call the asynchronous function to process FSR readings
  }
}

// Asynchronous function to process FSR readings
void processFSRReadings() {
  for (int i = 0; i < numFSRs; i++) {
    fsrReadings[i] = analogRead(fsrPins[i]);
    Serial.print("Analog reading " + String(i+1) + " = ");
    Serial.println(fsrReadings[i]);
    
    // analog voltage reading ranges from about 0 to 1023 which maps to 0V to 5V (= 5000mV)
    fsrVoltages[i] = map(fsrReadings[i], 0, 1023, 0, 5000);
    //Serial.print("Voltage reading " + String(i+1) + " in mV = ");
    //Serial.println(fsrVoltages[i]);  

    if (fsrVoltages[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        yay math!
      fsrResistances[i] = 5000 - fsrVoltages[i]; // fsrVoltages is in millivolts so 5V = 5000mV
      fsrResistances[i] *= 10000; // 10K resistor
      fsrResistances[i] /= fsrVoltages[i];
      //Serial.print("FSR resistance " + String(i+1) + " in ohms = ");
      //Serial.println(fsrResistances[i]);

      fsrConductances[i] = 1000000; // we measure in micromhos so 
      fsrConductances[i] /= fsrResistances[i];
      //Serial.print("Conductance " + String(i+1) + " in microMhos: ");
      //Serial.println(fsrConductances[i]);

      // Use the two FSR guide graphs to approximate the force
      if (fsrConductances[i] <= 1000) {
        fsrForces[i] = fsrConductances[i] / 300; // The division by 350 is an empirical constant used to approximate the force based on experimental calibration.
        fsrWeights[i] = fsrForces[i] / 9.80665;
        //Serial.print("Force " + String(i+1) + " in Newtons: ");
        //Serial.println(fsrForces[i]);
        //Serial.print("Force " + String(i+1) + " in Kg: ");
        //Serial.println(fsrWeights[i]);
      } else {
        fsrForces[i] = fsrConductances[i]-1000;
        fsrForces[i] /= 250;
        fsrWeights[i] = fsrForces[i] / 9.80665;
        //Serial.print("Force " + String(i+1) + " in Newtons: ");
        //Serial.println(fsrForces[i]);   
        //Serial.print("Force " + String(i+1) + " in Kg: ");
        //Serial.println(fsrWeights[i]);         
      }
    }
    //Serial.println("--------------------");
  }
}

我在不同传感器中输出相同重量的 10 个间隔样本。

Screen shot of my varying analog readings

减少波动的解决方案是什么? 下面是我的电路。

enter image description here

我需要减少每个FSR的波动,以便我能够校准重量计算。

提前致谢。

arduino-uno robotics arduino-c++
© www.soinside.com 2019 - 2024. All rights reserved.