Precise motor speed control and display with homing button

Hi everyone!

I’m very new to arduino, actually before diving in I need to know if my project is feasible, and the right way to go with it.

I’m building a sort of mechanical music sequencer, with small bike wheels spinning thanks to a motor and bike fixed gears and a chain.

I need to be able while the motor is off to dial in a BPM (either with a potentiometer or keypad), have an lcd display show the BPM value, and then a switch to start the motor, another switch to stop it, and a homing button that drives the motor back to its zero position, which correspond to the first beat musically.

(In this project the BPM = RPM x 4 , since I have 4 beats around the wheels. That is if the motor and the wheels have a gear of same diameter and then spin at the same speed)

So my questions are:

  • Is it possible to have a homing button with a dc motor or only with a stepper motor? Maybe a dc motor with a sensor?
    If the homing button is complicated, I could also just manually move the wheels and motor back to their starting position, but can the motor shaft be moved when the motor is off or is it blocked?

  • Is it possible to input the BPM (/RPM) and then start the motor at that precise speed (which would actually be a given PWM voltage) ? I don’t want to start the motor and then set the speed...

  • can I directly mount a bike’s fixed gear sprocket on a 24v motor, so it is the same diameter as the ones on the wheels? Or should I rather have a smaller shaft on the motor and have it spin faster?

I’ll need to be able to run it between 0 and 140 BPM. So I was thinking, if I have sprockets of same diameter on the motor and the wheels, I would get a 24v 50RPM DC motor (taking into account the resistance that would diminish the motor’s speed capability I guess) ; an L298N motor driver; an Arduino Uno; a potentiometer or keypad; an lcd display; 3 toggle buttons; and a power supply. Does it seem right?

Thank you very much in advance! It is a lot of questions.. sorry if some of it is totally off, I’m starting

Have a great day!!

Homing a DC motor will not be simple even with an external sensor unless the motor stops instantly when the power is shut off. This usually requires friction in the motor mechanism.

If you are using a geared DC motor and want to stop the output shaft at a particular position the friction of the gearbox may be sufficient.

Making a DC motor run at a precise speed usually needs some external means to measure the speed. It may be that the sensor for measuring the speed and identifying the stop position can be one and the same.

I use a QRE1113 reflective optical sensor to detect the speed and count the revolutions of a small DC motor. My motor operates at up to 15000 RPM so stopping at a specific place would be impractical. However the same sensor and the same code could be used for a slow motor.

The code in the link just collects the time for speed calculations. You will need to use it in conjunction with PID to control the speed. Read about the Arduino PID library.

...R

Thanks a lot for your answer and code Robin!

Maybe I could forget about the homing button and as you say only drive the wheels slowly forward or backward and stop them at the start position with the motor.

As for the speed, that is what I was worried about... The problem with a sensor is that I can't start the motor at a desired speed then, right? I have to start the motor then the sensor will give me a speed and I can adjust it.

-> Would there be any way to create a function or a link between the PWM voltage and the speed, so that I could dial in a desired speed while the motor is off. And then launch it, and the program would know what PWM voltage to output?
Maybe sort of manually at the beginning, run the motor with a sensor across all its range of speed, and record the relationship between PWM voltage and speed in RPM?

Thanks

Adri36:
As for the speed, that is what I was worried about... The problem with a sensor is that I can't start the motor at a desired speed then, right? I have to start the motor then the sensor will give me a speed and I can adjust it.

The system I built for my model train measures the motor speed in microseconds per revolution (keep in mind the motor speed is up to 15,000 RPM) and I control the speed from my PC by sending a value (in microseconds) of the speed I want the motor to operate at.

I reckon you could implement a similar system.

Obviously if the motor is stationary it will take a little while to get up to the set speed, but that speed could be pre-determined.

I don't think there is any reliable relationship between PWM value and speed as so much depends on the load on the motor. IMHO if you want close control of a constant speed you need to measure the speed and use a proportional feedback system that constantly adjusts the PWM value to keep the speed constant.

At its simplest you adjust the PWM value based on the error between the desired speed and actual speed. A worthwhile refinement is to supplement that with an adjustment that takes account of how long the error has persisted. Those are the P and I elements of a PID system.

I have hacked the code from the Arduino PID library so I'm not going to present it here - my changes (to simplify things :slight_smile: ) would take too much explaining. The library code is intended to apply to a wide range of control systems but mine is specific to my project.

The P calculation is, basically,

P-pwm = error * P-errorFactor

and the I calculation is

I-pwm = I-pwm + (error * I-errorFactor)

and

totalPwm = P-pwm + I-pwm

When the speed is correct the P-pwm will be zero and the I-pwm will be the value that makes the motor achieve that speed.

On my project I update those values every revolution.

The effectiveness of the control system is determined by the choice of the error factors

...R