DTMF decoder without 8870.
Devices and components
Arduino Uno Rev3
Breadboard (generic)
LED (generic)
Jumper wires (generic)
Software and tools
Arduino IDE
Project description
Arduino Decoder DTMF Code
arduino
compile and upload the code into Arduino IDE and don't forget to add the library first.
the link for the library is:
https://github.com/jacobrosenthal/Goertzel
1/*
2
3 This code is a basic implementation of a DTMF decoder for detecting the 16 character
4 DTMF code from the analog pin A0 and gives the decoded output by checking for all the
5 Upper and lower tones in the DTMF matrix and gives us the corresponding number by turning
6 on the corresponding digital bit for the numbers 0-9 and by Serially printing the rest of
7 the characters.
8 This work is entirely based on the Kevin Banks code found at
9 http://www.embedded.com/design/embedded/4024443/The-Goertzel-Algorithm
10 so full credit to him for his generic implementation and breakdown.
11 The Goertzel algorithm is long standing so see
12 http://en.wikipedia.org/wiki/Goertzel_algorithm for a full description.
13 It is often used in DTMF tone detection as an alternative to the Fast
14 Fourier Transform because it is quick with low overheard because it
15 is only searching for a single frequency rather than showing the
16 occurrence of all frequencies.
17 * THIS CODE IS Made/modified by "Mian Mohammad Shoaib" and Released into the public domain.
18 * for any querries related to the code feel free to ask at
19
20 MMSHOAIB8452@GMAIL.COM
21 */
22
23
24#include <Goertzel.h>
25
26int sensorPin = A0;
27const int N = 100; //it is the number of samples code will take y0u can change for sensitivity and can if large it can slow the arduino
28const float threshold = 2000; //minimum tone amplitude to be considered we can change it for more senstivity
29const float sampling_freq = 8900; //maximum detectable frequency is the sampling rate/2 and arduino uno with 16Mhz can support sampling upto 8900 Hz
30float x_frequencies[4]; // make two arrays for holding x and y axis frequencies to be detected
31float y_frequencies[4];
32
33void setup(){
34 pinMode(13, OUTPUT); //initalize blink led to show if any tone is detected
35 pinMode(2, OUTPUT); //initialize 10 pins as output to show the dtmf outputs from 2 to number 12 rest will be just derially printed to the monitor
36 pinMode(3, OUTPUT);
37 pinMode(4, OUTPUT);
38 pinMode(5, OUTPUT);
39 pinMode(6, OUTPUT);
40 pinMode(7, OUTPUT);
41 pinMode(8, OUTPUT);
42 pinMode(9, OUTPUT);
43 pinMode(10, OUTPUT);
44 pinMode(11, OUTPUT);
45 pinMode(12, OUTPUT);
46
47 Serial.begin(9600);
48
49x_frequencies[0]=1209; //just initialize the arrays with the x and y axis tone frequencies along with their row and colon number
50x_frequencies[1]=1336;
51x_frequencies[2]=1477;
52x_frequencies[3]=1633;
53
54y_frequencies[0]=697;
55y_frequencies[1]=770;
56y_frequencies[2]=852;
57y_frequencies[3]=941;
58}
59
60bool detect_tone(float freq){
61
62Goertzel goertzel = Goertzel(freq, N, sampling_freq); //initialize library function with the given sampling frequency no of samples and target freq
63 goertzel.sample(sensorPin); //Will take n samples
64 float magnitude = goertzel.detect(); //check them for target_freq
65
66 if(magnitude>threshold){ //if you're getting false hits or no hits adjust the threshold
67 digitalWrite(13,HIGH); //blink led on 13 if a pulse is detected
68 delay(250);
69 digitalWrite(13,LOW);
70 Serial.print(freq);
71 Serial.print("\
72");
73 return true;
74 }
75 else
76 return false;
77}
78
79
80void print_number(int row,int column){
81int number=0;
82if(row==0){ //find the number corresponding to the found row and column
83 if(column== 0)
84 number= 1;
85 else if(column== 1)
86 number= 2;
87 else if(column== 2)
88 number= 3;
89 else if(column== 3)
90 number= 10;
91}
92else if(row==1){
93 if(column== 0)
94 number= 4;
95 else if(column== 1)
96 number= 5;
97 else if(column== 2)
98 number= 6;
99 else if(column== 3)
100 number= 11;
101}
102else if(row==2){
103 if(column== 0)
104 number= 7;
105 else if(column== 1)
106 number= 8;
107 else if(column== 2)
108 number= 9;
109 else if(column== 3)
110 number= 12;
111}
112else if(row==3){
113 if(column== 0)
114 number= 14;
115 else if(column== 1)
116 number= 0;
117 else if(column== 2)
118 number= 15;
119 else if(column== 3)
120 number= 13;
121}
122
123if(number <10){
124digitalWrite((number+2),HIGH);
125Serial.print(number);
126}
127else if(number ==10)
128Serial.print('A');
129else if(number ==11)
130Serial.print('B');
131else if(number ==12)
132Serial.print('C');
133else if(number ==13)
134Serial.print('D');
135else if(number ==14)
136Serial.print('*');
137else if(number ==15)
138Serial.print('#');
139Serial.print("\
140");
141delay(800);
142for(int i=2;i<=12;i++){
143 digitalWrite(i,LOW);
144}
145}
146
147void loop(){
148int column=0,row=0;
149int i=0;
150while(1){
151 if(detect_tone(x_frequencies[i]) == true){
152 column = i;
153 break;
154 }
155 i++;
156if(i==4)
157i=0;
158}
159
160i=0;
161while(1){
162if(detect_tone(y_frequencies[i]) == true){
163 row = i;
164 break;
165 }
166 i++;
167if(i==4)
168i=0;
169}
170print_number(row,column);
171
172}
Arduino Decoder DTMF Code
arduino
compile and upload the code into Arduino IDE and don't forget to add the library first.
the link for the library is:
https://github.com/jacobrosenthal/Goertzel
1/*
2
3 This code is a basic implementation of a DTMF decoder for detecting the 16 character
4 DTMF code from the analog pin A0 and gives the decoded output by checking for all the
5 Upper and lower tones in the DTMF matrix and gives us the corresponding number by turning
6 on the corresponding digital bit for the numbers 0-9 and by Serially printing the rest of
7 the characters.
8 This work is entirely based on the Kevin Banks code found at
9 http://www.embedded.com/design/embedded/4024443/The-Goertzel-Algorithm
10 so full credit to him for his generic implementation and breakdown.
11 The Goertzel algorithm is long standing so see
12 http://en.wikipedia.org/wiki/Goertzel_algorithm for a full description.
13 It is often used in DTMF tone detection as an alternative to the Fast
14 Fourier Transform because it is quick with low overheard because it
15 is only searching for a single frequency rather than showing the
16 occurrence of all frequencies.
17 * THIS CODE IS Made/modified by "Mian Mohammad Shoaib" and Released into the public domain.
18 * for any querries related to the code feel free to ask at
19
20 MMSHOAIB8452@GMAIL.COM
21 */
22
23
24#include <Goertzel.h>
25
26int sensorPin = A0;
27const int N = 100; //it is the number of samples code will take y0u can change for sensitivity and can if large it can slow the arduino
28const float threshold = 2000; //minimum tone amplitude to be considered we can change it for more senstivity
29const float sampling_freq = 8900; //maximum detectable frequency is the sampling rate/2 and arduino uno with 16Mhz can support sampling upto 8900 Hz
30float x_frequencies[4]; // make two arrays for holding x and y axis frequencies to be detected
31float y_frequencies[4];
32
33void setup(){
34 pinMode(13, OUTPUT); //initalize blink led to show if any tone is detected
35 pinMode(2, OUTPUT); //initialize 10 pins as output to show the dtmf outputs from 2 to number 12 rest will be just derially printed to the monitor
36 pinMode(3, OUTPUT);
37 pinMode(4, OUTPUT);
38 pinMode(5, OUTPUT);
39 pinMode(6, OUTPUT);
40 pinMode(7, OUTPUT);
41 pinMode(8, OUTPUT);
42 pinMode(9, OUTPUT);
43 pinMode(10, OUTPUT);
44 pinMode(11, OUTPUT);
45 pinMode(12, OUTPUT);
46
47 Serial.begin(9600);
48
49x_frequencies[0]=1209; //just initialize the arrays with the x and y axis tone frequencies along with their row and colon number
50x_frequencies[1]=1336;
51x_frequencies[2]=1477;
52x_frequencies[3]=1633;
53
54y_frequencies[0]=697;
55y_frequencies[1]=770;
56y_frequencies[2]=852;
57y_frequencies[3]=941;
58}
59
60bool detect_tone(float freq){
61
62Goertzel goertzel = Goertzel(freq, N, sampling_freq); //initialize library function with the given sampling frequency no of samples and target freq
63 goertzel.sample(sensorPin); //Will take n samples
64 float magnitude = goertzel.detect(); //check them for target_freq
65
66 if(magnitude>threshold){ //if you're getting false hits or no hits adjust the threshold
67 digitalWrite(13,HIGH); //blink led on 13 if a pulse is detected
68 delay(250);
69 digitalWrite(13,LOW);
70 Serial.print(freq);
71 Serial.print("\
72");
73 return true;
74 }
75 else
76 return false;
77}
78
79
80void print_number(int row,int column){
81int number=0;
82if(row==0){ //find the number corresponding to the found row and column
83 if(column== 0)
84 number= 1;
85 else if(column== 1)
86 number= 2;
87 else if(column== 2)
88 number= 3;
89 else if(column== 3)
90 number= 10;
91}
92else if(row==1){
93 if(column== 0)
94 number= 4;
95 else if(column== 1)
96 number= 5;
97 else if(column== 2)
98 number= 6;
99 else if(column== 3)
100 number= 11;
101}
102else if(row==2){
103 if(column== 0)
104 number= 7;
105 else if(column== 1)
106 number= 8;
107 else if(column== 2)
108 number= 9;
109 else if(column== 3)
110 number= 12;
111}
112else if(row==3){
113 if(column== 0)
114 number= 14;
115 else if(column== 1)
116 number= 0;
117 else if(column== 2)
118 number= 15;
119 else if(column== 3)
120 number= 13;
121}
122
123if(number <10){
124digitalWrite((number+2),HIGH);
125Serial.print(number);
126}
127else if(number ==10)
128Serial.print('A');
129else if(number ==11)
130Serial.print('B');
131else if(number ==12)
132Serial.print('C');
133else if(number ==13)
134Serial.print('D');
135else if(number ==14)
136Serial.print('*');
137else if(number ==15)
138Serial.print('#');
139Serial.print("\
140");
141delay(800);
142for(int i=2;i<=12;i++){
143 digitalWrite(i,LOW);
144}
145}
146
147void loop(){
148int column=0,row=0;
149int i=0;
150while(1){
151 if(detect_tone(x_frequencies[i]) == true){
152 column = i;
153 break;
154 }
155 i++;
156if(i==4)
157i=0;
158}
159
160i=0;
161while(1){
162if(detect_tone(y_frequencies[i]) == true){
163 row = i;
164 break;
165 }
166 i++;
167if(i==4)
168i=0;
169}
170print_number(row,column);
171
172}
Downloadable files
Arduino DTMF decoder
The circuit uses 10 LEDs connected from digital pin 2 to 12 which will light up when a tone for digits between 0 and 9 is pressed respectively and a pulse detection LED will be connected across pin 13 which will flash briefly when a pulse or signal is detected, numbers greater than 9 (the special characters) will be displayed via serial printing in the IDE.
The input pin of the audio jack or AUX cable will be connected to analog pin A0 with a 1uF capacitor in series that will filter out low frequencies and DC offset.
Arduino DTMF decoder
Note: Content and images are from: https://projecthub.arduino.cc/, with some modifications.
If you want it removed due to copyright reasons, please leave a comment. Thank you.
I want to share this article more widely so that everyone knows about Arduino and your project.