Advertisement
microrobotics

Force Sensing Resistor (FSR)

Apr 21st, 2023 (edited)
899
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. To read values from an FSR 400 using an Arduino, you can follow these steps. First, connect the FSR to your Arduino as follows:
  3.  
  4. Connect one end of the FSR to an analog input pin (A0) on the Arduino.
  5. Connect the other end of the FSR to the ground (GND) on the Arduino.
  6. Connect a 10 kΩ resistor from the same analog input pin (A0) to the 5V pin on the Arduino.
  7. Next, upload the following code to your Arduino:
  8.  
  9. This code will read the resistance and force values from the FSR sensor and print them to the serial monitor. The FSRResistance constant should be set to the value of the resistor used in the circuit (in this case, 10 kΩ).
  10.  
  11. The force calculation in the code is based on the FSR 400 datasheet, which provides a conversion formula that relates the resistance value to force in Newtons. Note that this formula assumes that the FSR is used in the recommended range of forces (10 g to 10 kg) and that the FSR is properly calibrated and mounted.
  12.  
  13. Keep in mind that the output force values will depend on the specific FSR you are using and may be affected by factors such as temperature, humidity, and sensor aging.
  14. */
  15.  
  16. const int FSRPin = A0;
  17. const int FSRResistance = 10000;
  18.  
  19. void setup() {
  20.   Serial.begin(9600);
  21. }
  22.  
  23. void loop() {
  24.   int sensorValue = analogRead(FSRPin);
  25.   float resistance = FSRResistance * (1023.0 / sensorValue - 1.0);
  26.  
  27.   float force = 1.0 / (0.0002 * resistance); // Convert resistance to force in Newtons
  28.  
  29.   Serial.print("Resistance: ");
  30.   Serial.print(resistance);
  31.   Serial.print(" ohms | Force: ");
  32.   Serial.print(force);
  33.   Serial.println(" N");
  34.  
  35.   delay(500);
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement