# Rotary Dial

Hi all!

I’m trying to “hack” an old telephone with a rotary dial.
I already figured out how it works and made a little circuit to feed to my arduino UNO.
The way it works:
I have (only) two wires connected to the Arduino;
1st signal will go LOW when a number is being dialled. (so from the moment you start turning until it
is done, this 1st signal will allways be LOW, otherwise HIGH

the second signal will tell me which number is dialled by pulsing (HIGH to LOW) a number of times.
So if i dial a 4, there will be 4 pulses .

I attached a screenshot from the plotter to give you an idea how this works.

So now, i want to read how many times this has pulsed , so i can process this info and do something with it.

And here is where i find my problem.
Although the plotter shows me that the dial is always pulsing the right amount of times,
the program i wrote is not interpreting this right. (so there must be an error in the coding)
Sometimes i read 5 pulses, then 6, then 3.
I seem to have this problem espacially when i’m trying to read higher numbers. ( Dialling a 9 will almost never result in a 9 )

I attached the small block of code I wrote for this, so you can follow what i’m talking about.

Does ANYONE have an idea how to solve my problem?

Lomme

PS: I’m dutch so i used some dutch names for the variables, but it should be readable for anyone

telefoon_extra_test.ino (792 Bytes)

You have to include some debouncing in your code which has a time element to eliminate spurious readings. For example, and assuming you have recorded the value of millis() at the last state change:

``````if(staat != vorige_staat && ( millis() - lastStateChangeAtMs > 50)  ){
// this eliminates bounces by ensuring that the last state change was more than 50mS ago.
. . .
}
``````

Thanks alot for the advice, it worked out perfectly!

But now i'm wondering why the bouncing was the problem..

When I looked at the plotter, these signals seemed perfectly fine, and didn't show any signs of bouncing... so, how does this work?

greets, and again, thanks alot!

Lompje:
Thanks alot for the advice, it worked out perfectly!

But now i'm wondering why the bouncing was the problem..

When I looked at the plotter, these signals seemed perfectly fine, and didn't show any signs of bouncing... so, how does this work?

greets, and again, thanks alot!

Your plotter can't register changes that occur in several microseconds (or you haven't configured it to do that).

Hi,