Week 6

/ /






Figure 1 : FSR connected to the Arduino A0 pin

# coding for FSR (read value from sensor)


  1. int fsrAnalogPin = 0; // FSR is connected to analog 0
  2. int LEDpin = 11; // connect Red LED to pin 11 (PWM pin)
  3. int fsrReading; // the analog reading from the FSR resistor divider
  4. int LEDbrightness;
  5. void setup(void) {
  6. Serial.begin(9600); // We'll send debugging information via the Serial monitor
  7. pinMode(LEDpin, OUTPUT);
  8. }
  9. void loop(void) {
  10. fsrReading = analogRead(fsrAnalogPin);
  11. Serial.print("Analog reading = ");
  12. Serial.println(fsrReading);
  13. // we'll need to change the range from the analog reading (0-1023) down to the range
  14. // used by analogWrite (0-255) with map!
  15. LEDbrightness = map(fsrReading, 0, 1023, 0, 255);
  16. // LED gets brighter the harder you press
  17. analogWrite(LEDpin, LEDbrightness);
  18. delay(100);
  19. }
---------------------------------------------------------

This sensor was function well during testing and confirmed this is official sensor for my pedometer. I reprogrammed the coding to make this sensor count if FSR detect the sensor value high than threshold. So it will count 1 and i declare it as a step.


#coding for FSR counting

int fsrPin = 0;     // the FSR and 10K pulldown are connected to a0
int fsrReading;     // the analog reading from the FSR resistor divider
int counter = 0;
 
void setup(void) {
  // We'll send debugging information via the Serial monitor
  Serial.begin(9600);   
}

void loop()
{
  fsrReading = analogRead(fsrPin); 
   Serial.print(counter);
   Serial.println(" steps");
  
  if (fsrReading > 500 && fsrReading < 600)
  {
    counter=counter + 1;
   Serial.print(counter);
   Serial.println(" steps");
  }
  else
  {
   Serial.print(counter);
   Serial.println(" steps");
  }
  
  delay(100);   
}






1 comments:

{ Unknown } on: 21 January 2014 at 00:12 said...

did u test this code and get accurate number of steps ?
because '' if (fsrReading > 500 && fsrReading < 600)'' from this line the counter will increment alot as long as ur feet still on the ground , since ur feet doesnt simply touch the ground but remains for less than a second, right ?

Post a Comment

 
Copyright © 2010 Pedometer, All rights reserved
Design by DZignine. Powered by Blogger