I have a project with a Gear Motor running off separate power supply via a PWM driver to control it's speed. The motor has a disc attached to the shaft with a magnet embedded in the disc that triggers a hall sensor. The hall sensor is currently connected to a display which counts the revolutions in real time. I would like to be able to set up a Raspberry Pi so that I can stop the rotations at a specific count, as well as set that count stop number using some kind of rotary encoder. This would necessitate another display as well, showing the pre-programmed revolutions before stop as set by turning the rotary encoder. Is this possible? This set up wraps electric coils, and I need to be able to program the wraps and have it stop when it reaches a specific number which varies from time to time. Any help would be GREATLY appreciated. I'm very new to Raspberry Pi, Linux, and coding.

To see what I'm trying to control: https://www.youtube.com/watch?v=F2Z8fdwFkLQ

  • Can a Pi control a DC motor? Yes, with some additional hardware -- perhaps not any and all motors, but you have not been more specific. Can a Pi receive input from a hall sensor? These come with digital and/or analog outputs; you'd need an ADC to use the latter, but in general, yes.
    – goldilocks
    Dec 17 '20 at 19:47
  • Would you do better to look at servos that can just go on and on and on? I would have thought the stopping accuracy of an electric motor may give you issues / extra rotations...
    – user115418
    Dec 17 '20 at 20:14
  • The video device is almost certainly using a stepper motor which is likely thee best tool for the job. You can control the turns very accurately and accelerate/decelerate as needed. You can do what you want with a DC motor but I doubt it will be very accurate.
    – joan
    Dec 17 '20 at 20:44
  • I'm looking at my original question, and I guess I wasn't very clear. Actual control of the motor (other than to shut it off) is not needed. All I would need the pi to do is accept some sort of count input (like 7000) from an input source (maybe a rotary encoder, or other device). Then I would need the pi to keep count of the hall sensor opening (or closing) and shut off power to the DC motor, via a relay I would imagine, when that number is reached. Because it is a geared motor it stops rapidly when power is shut off. The motor in the video is a geared DC motor with a max RPM 1000. Dec 22 '20 at 22:25

The key issue you have is that you want 'real time' control.

Unfortunately, Linux is not a real time operating system and interaction between the processor and the Linux operating system may well cause timing issues so that you cannot get the precision you require.

This is a task ideally suited to an arduino and I would really recommend that over a Pi for a real time task.

  • The counter in that video is moving at 10-20 Hz, which should not be a problem unless you want to run tensorflow models and blockchain mining at the same time or something.
    – goldilocks
    Dec 18 '20 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.