i have a dtmf module for decode dtmf tones. i have connected the 4 digitals output of the decoder on 4 digital inputs of arduino nano .with my code i drive 4 relays ,every time i send a dtmf tone. the problem is that i want to put before run my program a safety 4 digits binary code that when i send it with dtmf run the rest of my program.other wise return back and aspect the right 4 digit code to run the program .can somebody help me do it?
// Arduino Digital pins for Relay module
const byte R1 = 12;
const byte R2 = 11;
const byte R3 = 10;
const byte R4 = 9;
// Arduino Digital pins for DTMF module
const byte Q1 = 8;
const byte Q2 = 7;
const byte Q3 = 6;
const byte Q4 = 5;
const byte STQ = 4;
// A counter
byte count = 0;
// Variables for reading the DTMF module pin status
boolean S_Q1 = LOW;
boolean S_Q2 = LOW;
boolean S_Q3 = LOW;
boolean S_Q4 = LOW;
boolean S_STQ = LOW;
const byte PTT = 2; // Push To Talk (PTT) button on radio
void setup()
{
// Identify the input and output pins
// Arduino input pins from DTMF module output pins
pinMode(Q1, INPUT); // Q1 LED 0001
pinMode(Q2, INPUT); // Q2 LED 0010
pinMode(Q3, INPUT); // Q3 LED 0100
pinMode(Q4, INPUT); // Q4 LED 1000
pinMode(STQ, INPUT); // STQ goes high/on when a tone is detected
pinMode(PTT, OUTPUT); // D2 connect to a 330 ohm resister to pin 1 of the optocoupler
pinMode(13, OUTPUT); // onboard LED
// Pins on relay board. A LOW turns on the relay.
pinMode(R1, OUTPUT); // LED or control relay #1
pinMode(R2, OUTPUT); // LED or control relay #2
pinMode(R3, OUTPUT); // LED or control relay #3
pinMode(R4, OUTPUT); // LED or control relay #4
digitalWrite(R1, HIGH); // Turn off relay 1
digitalWrite(R2, HIGH); // Turn off relay 2
digitalWrite(R3, HIGH); // Turn off relay 3
digitalWrite(R4, HIGH); // Turn off relay 4
}
void loop()
{
S_STQ = digitalRead(STQ);
if (S_STQ == HIGH)
{
// Read the status of the DTMF module pins
S_Q1 = digitalRead(Q1);
S_Q2 = digitalRead(Q2);
S_Q3 = digitalRead(Q3);
S_Q4 = digitalRead(Q4);
delay (3000); // pause 3 second for transmission to end
digitalWrite(PTT, HIGH); // Turn PTT on
digitalWrite(13, HIGH); // Turn on LED
delay (1000); // pause 1 second before transmitting
//if (S_Q1 == HIGH)
if (S_Q1 == HIGH && S_Q2 == LOW && S_Q3 == LOW && S_Q4 == LOW) //DTMF KEY 1
{
digitalWrite(R1, LOW); // turn on relay #1
count = count + 1;
}
//else
if (S_Q1 == HIGH && S_Q2 == LOW && S_Q3 == HIGH && S_Q4 == LOW) // DTMF KEY 5
{
digitalWrite(R1, HIGH); // turn off relay #1
}
//if (S_Q2 == HIGH)
if (S_Q1 == LOW && S_Q2 == HIGH && S_Q3 == LOW && S_Q4 == LOW) //DTMF KEY 2
{
digitalWrite(R2, LOW); // turn on relay #2
count = count + 1;
}
if (S_Q1 == LOW && S_Q2 == HIGH && S_Q3 == HIGH && S_Q4 == LOW) // DTMF KEY 6
{
digitalWrite(R2, HIGH); // turn off relay #2
}
if (S_Q1 == HIGH && S_Q2 == HIGH && S_Q3 == LOW && S_Q4 == LOW) //DTMF KEY 3
{
digitalWrite(R3, LOW); // turn on relay #3
count = count + 1;
}
if (S_Q1 == HIGH && S_Q2 == HIGH && S_Q3 == HIGH && S_Q4 == LOW) //DTMF KEY 7
{
digitalWrite(R3, HIGH); // turn off relay #3
}
//if (S_Q4 == HIGH)
if (S_Q1 == LOW && S_Q2 == LOW && S_Q3 == HIGH && S_Q4 == LOW) //DTMF KEY 4
{
digitalWrite(R4, LOW); // turn on relay #4
count = count + 1;
}
if (S_Q1 == LOW && S_Q2 == LOW && S_Q3 == LOW && S_Q4 == HIGH) //DTMF KEY 8
{
digitalWrite(R4, HIGH); // turn off relay #4
}
if (S_Q1 == HIGH && S_Q2 == LOW && S_Q3 == LOW && S_Q4 == HIGH) //DTMF KEY9
{
digitalWrite(R1, HIGH); digitalWrite(R2, HIGH); digitalWrite(R3, HIGH); digitalWrite(R4, HIGH);
}
digitalWrite(PTT, LOW); // turn PTT off
digitalWrite(13, LOW); // Turn off LED
count = 0; // Reset counter
delay(100);
}
}
}
}
πληκτρολογήστε ή επικολλήστε τον κώδικα εδώ