Reversing a wheel with some constraints


I am wondering if anyone can help me. I have a fairly simple project that I am hoping to use an arduino uno for.

It is a wheel powered by a 24V DC motor. I am hoping to use one or two sensors that will operate from a magnet located on the wheel.

Basically I will push a start button and the wheel will rotate as soon as it makes a sensor it will change direction until it makes the sensor again and then changes direction again. So basically rotating 360 degrees back and fourth.

This part is faily simple but example code would be greatly appreciated.

The next part is my struggle. I want to protect the system so that if the wheel does not make the 360 degree rotation within a set period of time I want to enable a relay to cut the power. A sort of safety feature.

If anyone has any ideas that would help and example code I could play with it would be greatly appreciated.

Thanks in advance.

How fast is this wheel going to turn and how much inertia will it have when power is removed? Once the magnet hits the sensor the wheel has to stop before changing direction, inertia will probably move the magnet past the sensor and when reverse power is applied the sensor will very quickly "see" the magnet again, initiating another reversal. And so on ...

Hi, thanks for the response. The motor is very slow at 3rpm. I did think of this and that Is why I thought that I may require two sensors.

Maybe one sensor to detect when going clockwise and one to detect going anti-clockwise.

Although with the slow movement and very light weight I am hoping to use one sensor.

You should be able to organize the code so that when it reverses the motor it will expect the first false sensor input and, while noting it as evidence that the motor is rotating it will know not to cause the motor to reverse until the next input. Indeed it would be wise (if possible) to wait until the motor is past the sensor before changing direction. That way you can guarantee there will be two sensor detections. If it is important that the motor does not go past 360 degrees then you could have two sensors close together so that it stops (and changes direction) between them.

Once you know how many millisecs there should be for a complete revolution it will be straightforward to have a timeout if the next sensor input is delayed much beyond the expected time.