Using an FSR to determine walking speed

Hi,

For a project im trying to determine the walking speed of a person using a single FSR imbedded into the heel of a shoe insole. I'm assuming i need to utilize a timer and or interrupts but am unsure about how to approach them as i'm fairly new to arduino programming. I'm looking to be able to measure the time between steps, or more specifically measure the time between the FSR output dropping below as certain value.

Thanks :)

To measure the time in between steps will not be hard.
The millis() function will cover most of it.

What kind of setup do you have now? Is the FSR analog or digital? And have you started at the code yet?

What i’m wondering is, speed is distance divided by time. If you have the time, how do you want to get the distance?

Right now my setup is a FSR connected to A0. At the moment my code can read the analog pin and print out the current FSR value. I've been messing around with If statements that check when the value of the FSR drops below a certain point (which would indicate a foot being planted) but having trouble trying to measure the time between the foot being planted, lifted and planted again.

Sorry i hope this is making sense.

As for the distance, this part of my project is mainly concerned with getting the time between each step and then using that value to control another aspect of my project, ie make a light turn on every time a person steps.

but having trouble trying to measure the time between the foot being planted, lifted and planted again.

As told to you before use millis() http://www.arduino.cc/en/Reference/Millis

Make a note of the time in a long variable when you detect the first "down" then when you detect the second "down" the time is given by subtracting that variable from the current value returned by millis().

It’ll be easier for us to see what you have as a code right now and comment on it than for you to insert our comments in your code. Could you post your code? Click on the first icon, the one with “</>” and post your code inside.

Here is my code, it ain’t pretty.

unsigned long time;
int value;
int Steps[2];
int stepOn  = 0;
int stepOff  = 0; 

void setup(){
  Serial.begin(9600);
}
void loop(){
  time = millis();
  value = analogRead(A0);
 // Serial.print("Time: ");
 
 if(value < 20){
   stepOn = 1;
   stepOff = 0;
   Steps[0] = time; 
   Serial.println(Steps[0]);

 }
 
 if(value > 200 && stepOn == 1)
 {
   stepOff = 1; 
   stepOn  = 0;
 }
 
 if(value < 20 && stepOff == 1) 
 {
   stepOn = 0;
   stepOff = 0;
   Steps[1] = time; 
   
 Serial.println(Steps[1]);

   
 }
 
 
 
}

Grumpy_Mike: As told to you before use millis() http://www.arduino.cc/en/Reference/Millis

Make a note of the time in a long variable when you detect the first "down" then when you detect the second "down" the time is given by subtracting that variable from the current value returned by millis().

That is what i've been trying to do, just not sure how to properly execute it :\

Yeah that code won’t work…

unsigned long time;
int value;
int Steps[2];
int stepOn  = 0;
int stepOff  = 0; 

void setup(){
  Serial.begin(9600);
}
void loop(){
  time = millis(); //Don't put this in the loop, it messes your code up!
  value = analogRead(A0);
 // Serial.print("Time: ");
 
 if(value < 20){ //This runs even when the step is already made... you need this to run only once!
   stepOn = 1;
   stepOff = 0;
   Steps[0] = time; //Won't fit!
   Serial.println(Steps[0]);

 }
 
 if(value > 200 && stepOn == 1)
 {
   stepOff = 1; 
   stepOn  = 0;
 }
 
 if(value < 20 && stepOff == 1) 
 {
   stepOn = 0;
   stepOff = 0;
   Steps[1] = time; 
   
 Serial.println(Steps[1]);

   
 }
 
 
 
}

Try this for change:

unsigned long time;
unsigned long new_time;
int value;
int stepOn  = 0;

void setup(){
  Serial.begin(9600);
    time = millis(); //just to have a value...
}
void loop(){

  value = analogRead(A0);

 
 if((value < 20) && (stepOn != 1)){
   stepOn = 1;
   new_time = millis(); // get new time
   Serial.println((new_time - time)); //See the change in new and old time
   time = new_time; //set time to new
 }
 
 if(value > 200 && stepOn == 1)
 {
   stepOn  = 0;
 }

}

Your array Steps[] must also be unsigned long as it holds the value from millis().

An easier way to think of it might be like this pseudo code

   if a step is detected
       newStepMillis = millis()
       stepInterval = newStepMillis - prevStepMillis
       prevStepMillis = newStepMillis

...R

Thank you, that code worked beautifully and better yet its very easy to understand.

Thank you all for your help :)

langley_ii: its very easy to understand.

Personally, I think that is the most important part... But i'm still wondering, how do you measure the distance traveled in comparison with the time? I for example have a different frequency of walking/running than the next person.