I'm controlling a car instrument panel with Arduino using the tone() function, however with Arduino Uno's minimum 31Hz frequency I can only set the speedometer at ~12mph or more. I'd like to be able to set the speed from 0, which would require around 10Hz I believe. Are there any code tricks I could use? Maybe I should use hardware timer, or a different board?

  • 1
    What frequency range would you like to cover? Sep 22, 2021 at 14:42
  • Let's say 10-400Hz, I don't have an exact number because each instrument cluster is different, but 10-400Hz should cover most of them
    – Piotr
    Sep 22, 2021 at 14:47
  • can't you toggle the pin on and off in loop() so as to lower the pulses per second from 30? It might not be as accurate, but your slow-reacting speedometer won't mind a 200us jitter.
    – dandavis
    Sep 22, 2021 at 16:45
  • try the Timer1 library
    – Juraj
    Sep 22, 2021 at 18:22

1 Answer 1


For this, I would consider using Timer 1 in mode 14 (fast PWM, with TOP value controlled by ICR1), with the prescaler set to 64. The timer would then be clocked at 250 kHz, giving you the following specs:

  • timer frequency: 250 kHz (time resolution = 4 µs)
  • minimum frequency: 3.81 Hz (exact period = 218 µs = 262,144 ms)
  • maximum frequency: 125 kHz (period = 8 µs)

As the time resolution is constant, the frequency resolution worsens as you increase the frequency. At 400 Hz the resolution is about 0.16%, or 0.64 Hz.

This is not the only possible solution. Toggle mode would work also, and also other prescaler values, which would give different frequency ranges and resolutions.

Check the datasheet to see how to set the configuration bits (basically: non-inverting PWM on either OC1A or OC1B, waveform generation mode = 14, prescaler = 64). You may be able to find libraries to do this if you prefer that approach, I have not checked this possibility.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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