Well written code NEVER needs a reset to continue to operate properly.
There are various tricks to be defensive, only the very worst conditions could end up with a watchdog reset.
You need to define "not rotating". Time is an issue, but time is not measured or considered in your code.
One approach is to specify a timeout interval. If there is no change in encoder value within that interval, the encoder is not rotating. Otherwise, it is rotating. Use a state variable to keep track.
welcome to the arduino-forum.
well done posting code as a code-section in your first posting.
I'm pretty sure that the values that were printed to the serial monitor are always increasing if the rotery-encoder is turning.
The nature of the encoder-library is:
for each pulse that is detected increment / decrement the value.
It is very unlikely that after starting to rotate that the rotary-encoder will stop exactly at value 0 again.
You should give an overview about your project. You youself say
which means you are (yet) unexperienced. If you give an overview about your project much better suggestions and quite often much easier to realise approaches can be suggested.
Thanks for the input everyone. I'll get back to the drawing board with your suggestions.
Ted - the aim of the project is to create a cheap device for detecting overspool on a cable drum/winch ie if a feeder pulley stops but the drum continues rotating, an overspool is being created.
There is a feeder pulley. Is this feeder pulley driven by a motor?
I mean this this way: Does the feeder pulley have its own driving motor ?
= feeder pulley is rotating even if there is no cable?
or
does the cable moving over the feeder-pulley make the feeder-pulley rotate?
Does the cable-drum have its own motor? If the cable-drum has its own motor this would mean the cable is pullled by the rotating cable-drum.
In case the feeder-pulley stops does the feeder-pulley hold the cable in position so the cable can move not even one millimeter and if then the cable-drum continues to rotate the cable wil be tightened more and more on the cable-drum?
And is this called an "overspool"???
I'm not sure if this is a correct english word
Can you upload some pictures how your device is looking like?
Depending on what wheels
the feeder-pulley is driven by a motor
or
the cable-drum is driven by a motor
or
both
have a motor and are actively driven different solutions to detect a stopped cable-drum can be used.
You should answer these questions so that other users become a clear picture how your device is functioning.
Only the drum rotation is motorised. The feeder pulley is connected to an encoder that reads length of cable pulled out. This encoder is hardwired to the winch and is irrelevant to the device I'm building because I'd like it to be a simple clip-on gadget. However, the pulley is relevant because it will stop turning during an over-spool (while the drum continues).
An over-spool is a messy situation that happens when the drum rotation overtakes the feed (out) and the cable becomes loosely wound and tangled.
If you've ever been fishing with a multiplier reel you will probably be familiar with this - colloquially named 'birds nest' or 'backlash'.