Arduino代码需要说明

时间:2013-11-24 12:49:50

标签: arduino sensor

刚刚遇到一个代码,用于将力传感器的模拟读数转换为以牛顿为单位的力。我不确定它是如何完成的。希望有人可以向我解释。谢谢!我在这里找到了代码http://learn.adafruit.com/force-sensitive-resistor-fsr/using-an-fsr

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 resistance in ohms = ");
    Serial.println(fsrResistance);

    fsrConductance = 1000000;           // we measure in micromhos so 
    fsrConductance /= fsrResistance;
    Serial.print("Conductance in microMhos: ");
    Serial.println(fsrConductance);

    // Use the two FSR guide graphs to approximate the force
    if (fsrConductance <= 1000) {
        fsrForce = fsrConductance / 80;
        Serial.print("Force in Newtons: ");
        Serial.println(fsrForce);      
    } else {
        fsrForce = fsrConductance - 1000;
        fsrForce /= 30;
        Serial.print("Force in Newtons: ");
        Serial.println(fsrForce);            
    }
}

1 个答案:

答案 0 :(得分:0)

如果你看一下这篇文章的第6页http://www.imagesco.com/sensors/fsr/fsrguide.pdf 有两个图表,一个用于重量级,一个用于较轻的一个。如果对它们运行线性回归并转换单位,则应在代码中得到两个方程式。