Need a low frequency (can preset at each value of 15Hz to 25Hz) PWM signal

Thanks again for all of the help. Looks to me to be getting close to a solution to my problem.

To summarise my understanding on the recent feedback…

Have a variable ‘period’ that is set to the desired cycle time (i.e. 1 / frequency). So, ‘period’ set to 50mS would give a 20Hz frequency.
Have a variable ‘dutycycle’ that takes an analog (say potentiometer) reading expressed as a range value of 0-1023 and maps these limits to 15% and 85% duty cycle min and max values
Have variables ‘onTime’ and ‘offTime’ and calculate the values of these needed usng the duty cycle and period values.
Use the loop with If statements to then move between the High and Low output signal status based on the previous signal status and the time. The increment the time with a variable ‘lastChange’

The challenges I still see for me to get to a working solution are…

  1. How does the potentiometer input circuit (to adjust the duty cycle between 15% and 85%) get recognised and fit in with this example code? I’m looking to set the motor at any speed in the range
  2. The very useful example code from wvmarle does not compile. It has the error “ 'dutyCycle' was not declared in this scope”. From my reading of the code, ‘duty cycle’ was declared as a float variable – but this is where my weak knowledge of Arduino code is exposed. What is wrong?
  3. I’m assuming I also need to declare the Arduino pins for input and output. For example:
    const int potPin = A0; // Analog input pin that the potentiometer attached to
    const int outPin = 9; // PWM output pin that the Motor or LED is attached to
    Or have I got this wrong?

On the questions raised by 6v6gt…
How to get this into a sketch and use of a potentiometer. Plan to use a pot maybe with pad switches for speed presets (if I’m feeling confident!). I had originally envisaged a 10K potentiometer input into pin A0. My remaining sketch challenges above probably set out my other needs re the sketch.

On using an LCD screen, I actually don’t need to show the input treadmill speed (and with it time and distance) of the treadmill as I have already built a box with a 1602 LCD display that takes reed sensor feedback on treadmill motor rotations to generate the readings. So once past the use of Arduino serial readout in trialing it, and once the motor turns I can do final calibration. Hope that makes sense.

Thanks again for all of the support.