Hi, Im doing a project where i need to have something turned on as long as something is rotating. The point is to make people able to turn a "handle" and as long as it is rotating, something can happen. So im looking for a way to detect if there is rotation. Im new to this so i haven't been able to find what i need.
boolean sensorValue, previousValue, someThing;
unsigned long marker; // holds/marks the time the sensor changes
void loop() {
 sensorValue = digitalRead(sensorPin); // read sensor
 if (sensorValue != previousValue) { // if it has changed
  marker = millis(); // mark the time
  previousValue = sensorValue; // update
 }
 if (millis() - marker < 3000) { // if less than 3seconds
  someThing = true;
 } else someThing = false;
}
Yeah that would be an option. But im looking for something that instantly detects if the handle is spinning. Kinda like a fishing reel. The second you stop reeling, the line stops. Hope it makes sense
Rotary encoders can see movement quicker but all require a certain minimum amount of motion before it can be detected. Or a minimum speed, for that matter.
A rotary encoder (slotted optical discs) may have 10 slots, so 20 dark/light changes. That means up to 360/20 = 18 degrees of rotation before you see it change. When moving, the next tick of the sensor comes as the encoder moved another 18 degrees.
Some encoders have higher resolution, but still the same problem. There is no such thing as "as soon as there is motion", it always has to be "... of a certain speed and a certain minimal rotation", where the same of course accounts for sensing the cessation of the motion.