Modifications

Sauter à la navigation Sauter à la recherche
3 048 octets ajoutés ,  13 juillet 2012 à 11:07
Ligne 95 : Ligne 95 :     
That is, the voltage is proportional to the '''inverse''' of the FSR resistance.
 
That is, the voltage is proportional to the '''inverse''' of the FSR resistance.
 +
 +
=== Exemple simple ===
 +
Wire the FSR as same as the above example, but this time lets add an LED to pin 11.
 +
 +
[[Fichier:FSR-SAMLE1.jpg]]
 +
 +
[[Fichier:FSR-SAMLE2.jpg]]
 +
 +
This sketch will take the analog voltage reading and use that to determine how bright the red LED is. The harder you press on the FSR, the brighter the LED will be! Remember that the LED has to be connected to a PWM pin for this to work, I use pin 11 in this example.
 +
 +
These examples assume you know some basic Arduino programming.
 +
 +
<nowiki>
 +
  /* FSR testing sketch.
 +
    Connect one end of FSR to 5V, the other end to Analog 0.
 +
    Then connect one end of a 10K resistor from Analog 0 to ground
 +
    Connect LED from pin 11 through a resistor to ground
 +
    For more information see www.ladyada.net/learn/sensors/fsr.html */
 +
 +
  int fsrAnalogPin = 0; // FSR is connected to analog 0
 +
  int LEDpin = 11; // connect Red LED to pin 11 (PWM pin)
 +
  int fsrReading; // the analog reading from the FSR resistor divider
 +
  int LEDbrightness;
 +
 +
  void setup(void) {
 +
    Serial.begin(9600); // We'll send debugging information via the Serial monitor
 +
    pinMode(LEDpin, OUTPUT);
 +
  }
 +
 +
  void loop(void) {
 +
    fsrReading = analogRead(fsrAnalogPin);
 +
    Serial.print("Analog reading = ");
 +
    Serial.println(fsrReading);
 +
    // we'll need to change the range from the analog reading (0-1023) down to the range
 +
    // used by analogWrite (0-255) with map!
 +
    LEDbrightness = map(fsrReading, 0, 1023, 0, 255);
 +
    // LED gets brighter the harder you press
 +
    analogWrite(LEDpin, LEDbrightness);
 +
    delay(100);
 +
  }
 +
</nowiki>
 +
 +
== Mesures FSR analogique (code simple) ===
 +
Here is a code example for measuring the FSR on an analog pin.
 +
 +
[[Fichier:FSR-SAMLE2-1.jpg]]
 +
 +
[[Fichier:FSR-SAMLE2-2.jpg]]
 +
 +
[[Fichier:FSR-SAMLE2-3.jpg]]
 +
 +
This code doesn't do any calculations, it just prints out what it interprets as the amount of pressure in a qualitative manner. For most projects, this is pretty much all thats needed!
 +
 +
<nowiki>
 +
  /* FSR simple 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 fsrPin = 0; // the FSR and 10K pulldown are connected to a0
 +
  int fsrReading; // the analog reading from the FSR resistor divider
 +
 
 +
  void setup(void) {
 +
    // We'll send debugging information via the Serial monitor
 +
    Serial.begin(9600);
 +
  }
 +
 
 +
  void loop(void) {
 +
    fsrReading = analogRead(fsrPin);
 +
    Serial.print("Analog reading = ");
 +
    Serial.print(fsrReading); // the raw analog reading
 +
    // We'll have a few threshholds, qualitatively determined
 +
    if (fsrReading < 10) {
 +
    Serial.println(" - No pressure");
 +
    } else if (fsrReading < 200) {
 +
    Serial.println(" - Light touch");
 +
    } else if (fsrReading < 500) {
 +
    Serial.println(" - Light squeeze");
 +
    } else if (fsrReading < 800) {
 +
    Serial.println(" - Medium squeeze");
 +
    } else {
 +
    Serial.println(" - Big squeeze");
 +
    }
 +
    delay(1000);
 +
  }
 +
</nowiki>
    
== Source ==
 
== Source ==
29 917

modifications

Menu de navigation