How to Detect a Pattern

Hi,

I want to know if the following is feasible;

I have a strain gauge as an input which gives a value between -100 and 100. When no force is applied the value is 0.

I have a motor as an output.

I want to know if I can set the motor to turn on when a certain pattern is detected by the arduino from the strain gauge.

For instance:

If force is greater then 50 for one second and then less then -50 for one second - turn motor on for a set amount.

I also need to have some tolerance built in as obviously a person isnt going to hold it at 50 for exactly one second etc.

Any help appreciated

Thanks, Steve

So something like the following ;

if (force > 50) {

while ((change in time ) < 1000) {

if ( force < -50){
// turn motor on for given time;
}
}

my thinking of above is that if force goes to 50 and then within 1 second it goes to -50 then the motor will turn on.

I have a feeling though that the while loop will just close off after 1 second no matter what?

Hi, thanks for your input. For the time being i will just be starting off with a simple combination and see how it goes. As i will be running it along side other code that will also control the motor, using the same force sensor i may find i have to make the combination more precise so it only goes off when its actually needed, not randomly.

The pattern matcher cries for a state machine. State 0 is IDLE, from which a transition to state 1 is made when the strain gauge input becomes >50. In state 1 you either wait for certain time (1s) before a transition into state 2, or for some unwanted strain gauge value to go back e.g. to IDLE. And so on, until a state is reached that requires to turn on (or off) the motor.