
Figure 1 : FSR connected to the Arduino A0 pin
# coding for FSR (read value from sensor)
- 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);
- }
---------------------------------------------------------
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:
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