DTMF

This friendly module enables Arduino and similar devices to communicate through sound. This board started with the need or requirement for data communication from arduino enabled or other MCU needed to transfer data in a universal approach with a cellphone. Studied FSK at first option due to its better performance and speed. Due to some hardware issues we decided to try DTMF (8870 chip).

The result was even more universal, allowing all kinds of cellphones to send “commands” over an audio channel. The DTMF signals are a telecommunication standard therefore all phones and beepers and some other devices are capable of producing this signals, even home landline phones.

Commands are all the numbers 0-9, four letters ( A,B,C,D ) and “*”, ”#”.

Some of the hardware we've built include a robot car GSM band enabled.

And another one powered by an android phone. Both connected through the audio minijack

It would work just fine to use the microphone attached if you get close enough to the microphone, if there is a lot of background noise.

Hardware

The design took into consideration the possibility of making it wireless. Since background noise is usually a problem, we just added some connectors for microphone and speaker. But since we want to use it attached to a cellphone we will most likely be using the mini jack.

Sample Code

We've written a library to ease the use of the module. Its not completely tested yet but basic functionality is fine.

Just download and unzip it in your libraries folder, under the sketchbook folder located in your documents. This is where you save your sketchs from arduino IDE. alternatively, you can place it in the libraries folder in the root of arduino. Remember to restart arduino IDE after you have installed a new library.

An example for arduino IDE would be:

dtmf.ino
/*
  DTMF.cpp - TEST code for DTMF library
*/
#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();
  Serial.println(myDtmf);
}

Gsm car code

If you want to build a Wireless car with unlimited range ( as far as human population goes, and your provider has good signal) here is a code example:

dtmf.ino
/*
  DTMF.cpp - TEST code for DTMF library
 */
#include "dtmf.h"
 
byte gsmDriverPin[3] = {
  3,16,17};
byte EN1 = 6;  
byte EN2 = 5;  
byte IN1 = 7;
byte IN2 = 4; 
char inChar=-1;
 
int xxx;
 
DTMF dtmf; // default set to DFRobot DTMF board pins, Speaker pins
 
void setup()
{
  Serial.begin(9600);
  for(int i=4;i<=7;i++) pinMode(i, OUTPUT); 
  pinMode(3,OUTPUT);
  pinMode(16,OUTPUT);
  pinMode(17,OUTPUT);
  //Init the driver pins for GSM function
  digitalWrite(17,HIGH);//Output GSM Timing 
  delay(1500);
  digitalWrite(17,LOW);  
  digitalWrite(3,LOW);//Enable the GSM mode
  digitalWrite(16,HIGH);//Disable the GPS mode
  delay(2000);
  Serial.begin(9600); //set the baud rate
  delay(5000);//call ready
  Serial.println("AT"); //Send AT command  
  delay(2000);
  Serial.println("AT");   
  delay(2000);
  //Send message
  Serial.println("ATS0=1"); //autopickup on first tone
}
 
void loop()
{
  // Read DTMF codes one by one and print it on Serial
  xxx = dtmf.getDTMF();
  delay(100);
  if(xxx != -1)
  {
    //Serial.println(xxx);
    switch(xxx)
    {
    case 2://Move ahead
      Motor1(100,true);  //You can change the speed, such as Motor(50,true)
      Motor2(100,true);
      break;
    case 8://move back
      Motor1(100,false);
      Motor2(100,false);
      break;
    case 4://turn left
      Motor1(100,false);
      Motor2(100,true);
      break;       
    case 6://turn right
      Motor1(100,true);
      Motor2(100,false);
      break;   
    case 5://stop
      Motor1(0,false);
      Motor2(0,false);
      break;
 
    }
  }
  xxx = -1;
 
}
 
void Motor1(int pwm, boolean reverse)
{
  analogWrite(EN1,pwm); //set pwm control, 0 for stop, and 255 for maximum speed
  if(reverse) digitalWrite(IN1,HIGH);
  else digitalWrite(IN1,LOW);    
}  
 
void Motor2(int pwm, boolean reverse)
{
  analogWrite(EN2,pwm);
  if(reverse) digitalWrite(IN2,HIGH);    
  else digitalWrite(IN2,LOW);  
}

Do it your self

Parts list: resistor 10k x2 ? resistor 1k x1 ? crystal 3.59 x1 ? cap ?