How Sense Object Rotation Postion and Stop?

I have little skill in programming skills, but I have been able to fumble my way with forum help and sketch examples to control a stepper motor running some gears and belts to rotate a disc. Ive modified Cheapstepper_simple.ino to count steps, stop at 180 degrees rotation, wait 20 minutes then rotate back the opposite direction. Due to sloppy gears, slipping, and whatnot, the system, over time, will slowly move off of 180 degrees with each rotation. I think a sensor approach vs counting steps will work better.

Is there a simple sketch example I can modify to sense, (say with a Hall Effect sensor), the rotating disk location (vs count steps)?

Thank you

The rotation angle of the disk can be measured using a shaft encoder, available commercially in countless configurations.

Most shaft encoders are relative, meaning you have to set the zero position at power up. Absolute shaft encoders are available, but are much more expensive.

All sensors will have to use some counting, so it might be more productive to solve the current problems.

I looked at shaft encoders. The shaft encoder hardware solution will not work in my existing mechanical configuration. I can easily add a magnet to the rotating disk and have it sensed to stop the rotation, I hope, more consistently than my sloppy mechanical gearing and belts.

A hall effect sensor doesnt count i dont think. Is there a simple sketch example to sense a hall effect sensor?

The Arduino counts, not the sensor. A single Arduino digital input suffices to read the output of a digital Hall Effect sensor.

I understand. Is there something in the Arduino library I can use as a simple example to modify for my rotating disk using the hall effect sensor?

A Hall Effect sensor could be used to count complete shaft or disk rotations.

The State Change Detection example built into the Arduino IDE does that to count button presses, which are functionally and electrically equivalent to Hall Effect sensor outputs.

In the Arduino 1.8.x IDE:

File>Examples>02.Digital>StateChangeDetection

If you think about this approach, you will realize that it can only indicate when your object has already passed that point, whereas the stepper motor can be stopped at the point you want.

I would program the sketch to stop the motor when it detects state change at the sensor. as long as is consistent why would that not work? As I said, the mechanical system is sloppy and counting stepper motor steps will slowly change the 180 degree location of the disk and does not work.

thanks. Ill give it a try.

Have you designed a stepper motor and cog belt system to actually produce a degree type movement from the stepper step size?

yes. It slips so I need a sensor for more precise 180 degree flip sense.

What is the disk's rotation speed? What is the ratio of disk vs motor speed? What is the disk's mass?

. It works fine for me at 18 RPM. Rotates fine. Im using GT2 pulleys and geared belt. Its slips. Its sloppy. It is what it is and will not be changed. I only need to sense whenever it hits 180 degrees and I will stop the motor and it will be good enough for me.

I would think about an optical "slot sensor" and 2 "flags" attached to the disk at the desired stop points.

Slot sensors

Seems you do not have required adjustable tension pulley.

Yes that would work. I have obtained some Hall effect sensors and small magnets to try and integrate them into my experiment. Thank you

Depending on the disk's diameter, thickness and weight, the motor may not be able to start and stop it quickly without missing steps and getting lost.

yes. No adjustable tension or proper design but its a DIY experiment and works fine except I would like a more consistent 180 degree stop.