Arduino DTMF Relay Code
Arduino DTMF Relay Code
int sensorPin = A5; // This sets the sensor pin as analog pin 5
int star = 13; // This makes the variable 'star' represent digital pin 12
int hash = 12; // This makes the variable 'hash' represent digital pin 13
int last0 = 0; // These will be used to remember the state of each relay to be able
to tell if they are on or off
int last1 = 0;
int last2 = 0;
int last3 = 0;
int last4 = 0;
int last5 = 0;
int last6 = 0;
int last7 = 0;
int last8 = 0;
int last9 = 0;
int laststar = 0;
int lasthash = 0;
DTMF dtmf = DTMF(n,sampling_rate); // Initialize the dtmf library with the number
of samples to be taken and the sampling rate.
void setup(){ // The setup protion of the program only runs once, this is just like
when programming Java
pinMode(2, OUTPUT); // This sets the following pins as outputs, sensorPin (analog
5) is not mentioned as analog pins are only for input
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(star, OUTPUT); // 'star' represents digital pin 12
pinMode(hash, OUTPUT); // 'hash' represents digital pin 13
Serial.begin(115200); // Begins serial communication at 115200 baud (can be set
to 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 28800, 38400, 57600, or 115200
baud)
}
int nochar_count = 0;
float d_mags[8];
void loop(){ // The loop part of the program runs continuously, this is much like
putting your code in a for or while loop, that loops forever
char thischar;
dtmf.detect(d_mags,506);
if(thischar){
Serial.println(thischar); // Prints 'thischar' through USB, can be read with
the serial monitor
nochar_count = 0;
// Note that the relays aren't wired for the DTMF tone they are triggered by;
DTMF 0 is pin 2, DTMF 1 is pin 3, etc...
delay(50); // Provides a 50ms delay (this is so relays are quickly activated and
then deactivated)