So the code below measures how much force is exerted on the FSR. I would like to know what would I have to change in this code so that it can record for how long the FSR is being pressed for. So instead of "What force is exerted on the FSR?", I want to ask "How long is the FSR being pressed for?"

Any help will be most appreciated

#include <Wire.h>
SoftwareSerial bluetooth_port(0, 1); //ports for Rx and Tx
int flexSensorPin; // The flex sensor for pin 0 

void setup() 

  Serial.begin(9600); // Start the serial transmission

void loop() 

  flexSensorPin = analogRead(A0); // Flex sensor pin 


  • 2
    check out the millis() function – jsotola Sep 11 '19 at 16:07
  • you need to clarify your question ... is somewhere around 3 seconds an acceptable measurement of time? – jsotola Sep 11 '19 at 16:24
  • When there's no "force" read the sensor value and then start counting, something like: if(sernsorReading != 0){start counting} – ElectronSurf Sep 11 '19 at 19:12

Use the analog comparator implemented in AVRs. this function, monitors two analog levels and generates interrupts if one of them goes higher or lower than the other as set. use this interrupt to record/stop counting. on AIN connects to FSR, and the other to a potentiometer to define a threshold. here are some links to get you going.

http://www.gammon.com.au/forum/?id=11916 https://github.com/tardate/LittleArduinoProjects/tree/master/playground/AnalogComparator

| improve this answer | |
  • Thank you, I will definitely check these links out – user19964 Sep 16 '19 at 0:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.