Setup for a homemade windmill

I can't help with Item 1.

I don't understand your description of the problem in Item 2

...R

2 problem is that when the windmill turns around it rotates the axle the ir sensor looks at very quickly and then stops which results in the arduino thinks the windmill still goes 10 rpm and therefor activates the relay.

You have set the calculation of duration/rpm within a conditional statement which is active on a state change. If there is no state change, the rpm will not go to zero but will remain at its last calculated value.

You can add a timeout and if no state change is seen, set rpm to 0.

You have a variable called prevmillis which is set to micros() on the state change. You should rename this variable prevmicros for consistency.

Then, right after the line prevstate = currentstate; and before the display/relay section of the code, add the following

if (micros() - prevmicros >= some time out value)
 { 
  rpm = 0;
 }

Centrifugal clutches set to different tension would eliminate any control requirements.

Hello Cattledog

Thanks for answer.

This works like a charm:)

Many thanks

cattledog:
You have set the calculation of duration/rpm within a conditional statement which is active on a state change. If there is no state change, the rpm will not go to zero but will remain at its last calculated value.

You can add a timeout and if no state change is seen, set rpm to 0.

You have a variable called prevmillis which is set to micros() on the state change. You should rename this variable prevmicros for consistency.

Then, right after the line prevstate = currentstate; and before the display/relay section of the code, add the following

if (micros() - prevmicros >= some time out value)

{
  rpm = 0;
}