Example Code for Arduino-DTMF Decoding and Playback
Last revision 2025/12/13
The article provides a step-by-step guide to decode and playback DTMF signals using Arduino, including hardware setup, software preparation, wiring instructions, sample code, and troubleshooting tips to effectively detect and reproduce DTMF tones with potential issues and solutions for dual tone generation.
Hardware Preparation
Software Preparation
- Download Arduino IDE: Click to download Arduino IDE
- Download the DTMF library library: DTMF library
- About how to install the library?
Wiring Diagram
For the Shield version, just stack it on an Arduino compatible device. If you are using the module, just wire the pins like the table below to your Arduino.
| DTMF | Arduino |
|---|---|
| Q1 | 12 |
| Q2 | 11 |
| Q3 | 10 |
| Q4 | 9 |
| STD | 8 |
| SPK2 | 3 |
| SPK1 | 2 |
Other Preparation Work
- Download the DTMF library from the provided link.
- Install the library in the Arduino IDE following the software preparation instructions.
- Connect the DTMF module to the Arduino board as per the wiring diagram.
- Ensure the serial monitor is set to 9600 baud rate.
Sample Code
You must download the library
/*
DTMF.cpp - Example code for DTMF library
Pin Diagram
DTMF Arduino
Q1 12
Q2 11
Q3 10
Q4 9
STD 8
SPK1 2
SPK2 3
*/
#include "dtmf.h"
DTMF dtmf;
void setup()
{
Serial.begin(9600);
}
void loop()
{
// Play a default number with all possibilities
//dtmf.playDTMF();
// Read DTMF codes one by one and print it on Serial
int myDtmf;
myDtmf = dtmf.getDTMF();
if(myDtmf != -1) Serial.println(myDtmf);
delay(80); // to avoid getting repeated output.
}
Result
- Open the Arduino serial monitor at 9600 baud rate.
- When DTMF tones are detected (e.g., from a phone keypress), the corresponding DTMF codes will be printed in the serial monitor.
- If the
dtmf.playDTMF()function is uncommented, a buzzer connected to SPK1 or SPK2 will play default DTMF tones. - If duplicated numbers are received, adjust the
delay(80)value in the code to improve performance.
Additional Information
Arduino current Tone library performs very well for single tone generation. Since it uses a single timer, dual tone generation at the same time is not possible. DTMF is a dual tone signal, and in order to enable this feature we need to use an external library. The DTMF library integrates an updated version of the Arduino Tone Library - V0006 from 2010. Note that using this feature, will occupy an extra timer and might affect some other libraries requiring timers to function.
However this function, is not entirely reliable due to the performance of Arduino. Requiring an amplifier.
Was this article helpful?
