# DTMF decoder library

**URL:** <https://forum.arduino.cc/t/dtmf-decoder-library/118979>\
**Category:** Audio\
**Created:** [September 5, 2012, 1:19am UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979 "2012-09-05T01:19:22Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![el\_supremo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/el_supremo/32/214787_2.png) [@el\_supremo](https://forum.arduino.cc/u/el_supremo)\
**Post date:** [September 5, 2012, 1:19am UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979/1 "2012-09-05T01:19:22Z")

</div>

I have modified the Goertzel algorithm implementation here:

> **[GitHub - jacobrosenthal/Goertzel: Arduino Library implementation of the...](https://github.com/jacobrosenthal/Goertzel)**
>
> Arduino Library implementation of the Goertzel algorithm - GitHub - jacobrosenthal/Goertzel: Arduino Library implementation of the Goertzel algorithm

so that it can be used to detect DTMF tones. The new version, like the original, is not interrupt driven.  
It is provided AS IS for you to play with.  
There are two sample audio files in the zip which, when the windows audio is turned up full, the sample code detects with no errors.  
There is also a circuit diagram of how I connected the audio from the computer's headphone output to the Arduino's analog Pin 0. Use at your own risk.  
Unzip the attached file into your libraries directory.

UPDATED 2016/12/19. I've attached the most recent version of the library to this message. Later messages (#6, #29) had a link to the zip file but those links will die soon - my ISP is withdrawing the webspace service.  
Also, see message #42 for a link to another DTMF library. I haven't tried it but it is probably better than this one.

Pete

[DTMF.zip](https://forum.arduino.cc/uploads/short-url/eGAIo2OPWgEyQ6llggstNRJy4A0.zip) (43.3 KB)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [September 6, 2012, 1:49am UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979/2 "2012-09-06T01:49:52Z")

</div>

So, I took a look and it works beautifully. Their are 2 things I have questions about though. The tone length is very strict. If the tone is too short it wont work and if it plays too long it will put print the number multiple times. Is their any chance you could make it modifiable? Also, the goertzel algorithm is supposed to compensate for magnitude on its own. Is there anyway to account for that?

Again, great job and thanks for your help!

Moose

---

<div class="post-metadata">

**Author:** ![retrolefty](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@retrolefty](https://forum.arduino.cc/u/retrolefty)\
**Post date:** [September 6, 2012, 1:53am UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979/3 "2012-09-06T01:53:57Z")

</div>

> SexualMoose:  
> So, I took a look and it works beautifully. Their are 2 things I have questions about though. The tone length is very strict. If the tone is too short it wont work and if it plays too long it will put print the number multiple times. Is their any chance you could make it modifiable? Also, the goertzel algorithm is supposed to compensate for magnitude on its own. Is there anyway to account for that?
> 
> Again, great job and thanks for your help!
> 
> Moose

I believe the official (original ATT specs?) DTMF specs for minimum recognition time (shortest tone period) for a valid digit is around 40 msec if I recall correctly. Decoding multiple repeated digits for a single tone of any length sounds like just a 'feature' of the library. 😉

---

<div class="post-metadata">

**Author:** ![el\_supremo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/el_supremo/32/214787_2.png) [@el\_supremo](https://forum.arduino.cc/u/el_supremo)\
**Post date:** [September 6, 2012, 2:37am UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979/4 "2012-09-06T02:37:17Z")

</div>

> The tone length is very strict. If the tone is too short it wont work

How short a tone are you trying? The dialabc example uses 50ms tones. The example code uses a sample length of 128 which means that a sample block is 14 milliseconds long. It should have 3 good blocks in one 50ms tone and might detect tones down to around 30ms - I haven't tried that. You could try making the sample length shorter (try 64) so that the algorithm samples the tone more times. If you do that, you'll have to reduce the threshold amplitude as well.

> and if it plays too long it will put print the number multiple times.

When the code detects a tone it won't return it again until it sees something that is not a tone. If for any reason the amplitude drops a bit to just below the threshold it can think it has seen the end of the tone when there's actually still more to come. Try lowering the threshold amplitude just a bit.

> Is their any chance you could make it modifiable?

Make what modifiable?

> Also, the goertzel algorithm is supposed to compensate for magnitude on its own.

I saw one implementation which divided the resulting magnitude by the number of samples. I don't know if that's actually part of the Goertzel algorithm itself.  
I'll play with it in the next day or so.

> Again, great job and thanks for your help!

You're welcome 😉

Pete

---

<div class="post-metadata">

**Author:** ![el\_supremo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/el_supremo/32/214787_2.png) [@el\_supremo](https://forum.arduino.cc/u/el_supremo)\
**Post date:** [September 6, 2012, 4:29pm UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979/5 "2012-09-06T16:29:58Z")

</div>

> Also, the goertzel algorithm is supposed to compensate for magnitude on its own.

This can be done without changing the library.  
The dtmf\_test sketch originally had this code:

```arduino
  dtmf.detect(d_mags,512);

  thischar = dtmf.button(d_mags,1800);

```

Change it to this:

```arduino
  dtmf.detect(d_mags,512);
  
  for(int i = 0;i < 8;i++) {
    d_mags[i] /= n;
  }
  
  thischar = dtmf.button(d_mags,20.);

```

The "for" loop normalizes the magnitudes. I determined the threshold value of 20 empirically but it works for values of n from 55 up to 160 when using either of the sample audio files.  
I prefer to leave this outside the library but if you want to build it in, in the method DTMF::detect change this statement:

```arduino
    dtmf_mag[i] = sqrt(Q1[i]*Q1[i] + Q2[i]*Q2[i] - coeff[i]*Q1[i]*Q2[i]);

```

to this:

```arduino
    dtmf_mag[i] = sqrt(Q1[i]*Q1[i] + Q2[i]*Q2[i] - coeff[i]*Q1[i]*Q2[i])/N;

```

Pete

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 14, 2013, 8:58am UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979/6 "2013-01-14T08:58:45Z")

</div>

is there a way to make the link alive again?

---

<div class="post-metadata">

**Author:** ![el\_supremo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/el_supremo/32/214787_2.png) [@el\_supremo](https://forum.arduino.cc/u/el_supremo)\
**Post date:** [January 14, 2013, 4:24pm UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979/7 "2013-01-14T16:24:01Z")

</div>

The most recent version of the library is attached to the first message in this thread.

Pete

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 15, 2013, 10:18am UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979/8 "2013-01-15T10:18:52Z")

</div>

Hi Pete

thanks for the new link, but i fail to understand how the code work .  
i dont have any expriance in arduino but i want to give it a shot....

as described i built the neccesery cirucit and connected it to my audio output of my pc.  
when i upload the code to my (MEGA2560) i dont see any feedback from the circuit exept from when i opening the serial monitor and the led on pin 13 go ON. i tried to open the serial monitor  
put it on 115200 baud and wait and see the detction working but its seems to do nothing.

how can i adavnce and make it work (sorry for my bad english)  
my audio output in full volume and my divider is on 512 please help.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 15, 2013, 2:57pm UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979/9 "2013-01-15T14:57:16Z")

</div>

hi i have an update its **working**.  
is there a way that can i decode 6 inputs in parallel?

---

<div class="post-metadata">

**Author:** ![el\_supremo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/el_supremo/32/214787_2.png) [@el\_supremo](https://forum.arduino.cc/u/el_supremo)\
**Post date:** [January 15, 2013, 4:03pm UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979/10 "2013-01-15T16:03:41Z")

</div>

The code could be modified to handle six inputs but it would slow down the sampling rate quite substantially which would change the characteristics of the detection.  
A better way to handle the audio sampling is to use a timer interrupt and do the detection on-the-fly but in either case you would probably need a faster processor to handle six channels.

Pete

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 25, 2013, 9:11am UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979/11 "2013-01-25T09:11:03Z")

</div>

I have an issue with the detection of the DTMF tones. When I try with audio archives through my computer, I have no problem, but when I connect my phone, nothing is detected. I don´t know why.

What I have in mind is to connect one phone to my arduino board, with voicemail active, then if there is an incoming call, the voice mail pick up the call and because of this is allowed to dial the tones. For example 001 wich turns on the heating.

But without detection through my mobile I am blocked, what can I do?

Thanks for your help in advanced

---

<div class="post-metadata">

**Author:** ![retrolefty](https://avatars.discourse-cdn.com/v4/letter/r/dec6dc/32.png) [@retrolefty](https://forum.arduino.cc/u/retrolefty)\
**Post date:** [January 25, 2013, 1:49pm UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979/12 "2013-01-25T13:49:37Z")

</div>

> bowline77:  
> I have an issue with the detection of the DTMF tones. When I try with audio archives through my computer, I have no problem, but when I connect my phone, nothing is detected. I don´t know why.
> 
> What I have in mind is to connect one phone to my arduino board, with voicemail active, then if there is an incoming call, the voice mail pick up the call and because of this is allowed to dial the tones. For example 001 wich turns on the heating.
> 
> But without detection through my mobile I am blocked, what can I do?
> 
> Thanks for your help in advanced

You would probably have to show us how you are attempting to connect to your telephone line. Actually most countries/telephone companies have laws and rules about how equipment can be wired to the local subscribers loop, as it's a balance line and you are not free to ground either the tip or ring wire. Normally equipment manufactures use approved chips/modules/components to do such electrical interfacing to the line called DAA modules. These usually involve a 600 ohm 1:1 transformer as well as ring detection/protection components. Keep in mind that the ring voltage when your phone rings is a 90 VAC 20Hz signal that can easily blow up components wired directly to the phone pair.

So I would suggest you do a little goggling for telephone interfacing circuits to see what you should be using.

Lefty

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [January 28, 2013, 5:10pm UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979/13 "2013-01-28T17:10:28Z")

</div>

I have used El\_supremo offered drawing and I connected a mobile phone with the audio jack so I don´t have the issue of a landline connetion (this is another point that I want to check out)

Thaks for your help

![audio_1.gif](https://europe1.discourse-cdn.com/arduino/original/4X/4/b/e/4be69acdcaf8ebdcecd3a3ce8e51a12c63f5327b.gif)

---

<div class="post-metadata">

**Author:** ![rinkrides](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/rinkrides/32/215878_2.png) [@rinkrides](https://forum.arduino.cc/u/rinkrides)\
**Post date:** [February 17, 2013, 5:21pm UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979/14 "2013-02-17T17:21:21Z")

</div>

> corolla9:  
> hi i have an update its **working**.  
> is there a way that can i decode 6 inputs in parallel?

> el\_supremo:  
> The code could be modified to handle six inputs but it would slow down the sampling rate quite substantially which would change the characteristics of the detection.  
> A better way to handle the audio sampling is to use a timer interrupt and do the detection on-the-fly but in either case you would probably need a faster processor to handle six channels.
> 
> Pete

Parallax Propeller could decode to 7 parallel channels with little external circuitry & leaving one of the COG's for serial back to an arduino.. A propeller chip (P8X32A) has 32 I/O, fully digital, analog input can be accomplished via sigma-delta conversion. There are actually 8 separate MCU's called cog's inside of one chip, this is how the propeller can do real-time parallel processing

---

<div class="post-metadata">

**Author:** ![Docedison](https://avatars.discourse-cdn.com/v4/letter/d/b3f665/32.png) [@Docedison](https://forum.arduino.cc/u/Docedison)\
**Post date:** [February 23, 2013, 3:03am UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979/15 "2013-02-23T03:03:20Z")

</div>

There is an IC part# MT8870. It is a DTMF decoder that will provide a Data Valid signal and 4 bit binary output. all it requires is about 100 MV of clean audio, 5 V and a 3.58 MHz color burst crystal.  
Here is a link from "Futurlec"that " appears to do a great deal.. and cheaper too @$12.98..

[MT8870 DTMF Receiver Mini Board](http://www.futurlec.com/Mini_MT8870.shtml).

Bob

---

<div class="post-metadata">

**Author:** ![rinkrides](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/rinkrides/32/215878_2.png) [@rinkrides](https://forum.arduino.cc/u/rinkrides)\
**Post date:** [March 31, 2013, 5:33am UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979/16 "2013-03-31T05:33:26Z")

</div>

i did buy 6 of these chips $6 ea. haven't tried them yet but im sure they will work fine.

---

<div class="post-metadata">

**Author:** ![DaAwesomeP](https://avatars.discourse-cdn.com/v4/letter/d/cab0a1/32.png) [@DaAwesomeP](https://forum.arduino.cc/u/DaAwesomeP)\
**Post date:** [July 17, 2013, 6:01pm UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979/17 "2013-07-17T18:01:32Z")

</div>

Hi,  
I'm trying to use el\_supremo's DTMF library. No matter what I do, I can't get a reading/signal from it.  
I am wiring up the handset output of my telephone with this schematic:  
  
Taken from: [https://coolarduino.files.wordpress.com/2011/02/dc\_bias11.png](https://coolarduino.files.wordpress.com/2011/02/dc_bias11.png)  
I know this circuit is working because other libraries that do different things correctly analyze the audio.

Is there something I need to change? I would prefer not to by a DTMF Decoder.

---

<div class="post-metadata">

**Author:** ![el\_supremo](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/el_supremo/32/214787_2.png) [@el\_supremo](https://forum.arduino.cc/u/el_supremo)\
**Post date:** [July 17, 2013, 7:05pm UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979/18 "2013-07-17T19:05:15Z")

</div>

Which other libraries, what do they do?

Pete

---

<div class="post-metadata">

**Author:** ![DaAwesomeP](https://avatars.discourse-cdn.com/v4/letter/d/cab0a1/32.png) [@DaAwesomeP](https://forum.arduino.cc/u/DaAwesomeP)\
**Post date:** [July 17, 2013, 7:47pm UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979/19 "2013-07-17T19:47:48Z")

</div>

This is a basic speech recognition software: [GitHub - arjo129/uSpeech: Speech recognition toolkit for the arduino](https://github.com/arjo129/uSpeech). It worked great.  
This gave a response, but because it can only detect one tone at once, it didn't work: [GitHub - jacobrosenthal/Goertzel: Arduino Library implementation of the Goertzel algorithm](https://github.com/jacobrosenthal/Goertzel)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 14, 2013, 3:47pm UTC](https://forum.arduino.cc/t/dtmf-decoder-library/118979/20 "2013-10-14T15:47:13Z")

</div>

Hello,

Works very well for me to display the code on the computer.

For cons, I can not seem to use a DTMF to turn an LED on output.

How to make the LED lights up when you press the button 5.

thank you

[Next page](https://forum.arduino.cc/t/dtmf-decoder-library/118979.md?page=2)
