Hi I am new Arduino user so please forgive me if I haven’t explained or formatted something properly.
I have a force resistor hooked up to my Arduino UNO, with an LED. I want to count the rate at which my finger taps the force sensor after a minute. The main problem I have is that when I press the sensor, multiple samples have a nonzero value for each sensor press, causing the count of finger taps to be skewed. Ideally, I would be able to count the number of peaks in the serial plotter output. Any idea of how I can do this? Here is what I am currently working with:
Thanks!!
//Constants:
const int ledPin = 3; //pin 3 has PWM funtion
const int sensorPin = A0; //pin A0 to read analog input
//Variables:
int value; //save analog value
int start;
unsigned int count = 0;
void setup() {
pinMode(ledPin, OUTPUT); //Set pin 3 as 'output'
Serial.begin(9600); //Begin serial communication
}
void loop() {
value = analogRead(sensorPin); //Read and save analog value from potentiometer
//Serial.println(value); //Print value
value = map(value, 0, 1023, 0, 255); //Map value 0-1023 to 0-255 (PWM)
analogWrite(ledPin, value); //Send PWM value to led
delay(100); //Smal
if (analogRead(sensorPin) > 600)
{
Serial.println("Beginning Count... ");
start = millis(); // take the start time
count = 0; // reset couter
while (millis() - start < 6000)
{
if (analogRead(sensorPin) > 0)
{
count++;
value = analogRead(sensorPin); //Read and save analog value from potentiometer
Serial.println(value);
//Serial.println(value); //Print value
value = map(value, 0, 1023, 0, 255); //Map value 0-1023 to 0-255 (PWM)
analogWrite(ledPin, value); //Send PWM value to led
//delay(100); //Smal
}
delay(100);
}
Serial.println("Total Count Is: ");
Serial.print(count);
delay(500);
analogWrite(ledPin, 0);
exit(1);
}
else
{
Serial.println(analogRead(sensorPin));
}
}