Hello,
I have a program written that will text a different message based on what tag is read. Everything works out, except the RFID will only scan one tag, and the green light stays lit. The only way I have found to reset it is to open up the Serial Monitor again. I will post the code and any insight would be appreciated.
Thanks
#include <SoftwareSerial.h>
SoftwareSerial SIM900(7,8);
char card[12] = {'7','2','0','0','7','7','5','2','4','9'};
char card2[12] = {'7','2','0','0','7','7','4','9','E','B'};
char code[12];
int bytesread = 0;
int rfidPin = 2; // RFID enable pin connected to digital pin 2
int val=0;
void setup()
{
Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
pinMode(rfidPin,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(rfidPin, LOW); // Activate the RFID reader
SIM900.begin(19200);
SIM900power();
delay(10000);
}
void SIM900power()
{digitalWrite(9,HIGH);
delay(1000);
digitalWrite(9,LOW);
delay(3000);
}
void SendSMS()
{
SIM900.println("Code is great: ");
SIM900.print("AT+CMGF=1\r"); // AT command to send SMS message
delay(100);
SIM900.println("AT + CMGS = \"+xxxxxxxxxxx\""); // recipient's mobile number, in international format
delay(100);
SIM900.println("Hello"); // message to send
delay(100);
SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(100);
SIM900.println();
delay(5000); // give module time to send SMS
SIM900power(); // turn off module
}
void SendSMS2()
{
SIM900.println("Code is good: ");
SIM900.print("AT+CMGF=1\r"); // AT command to send SMS message
delay(100);
SIM900.println("AT + CMGS = \"+xxxxxxxxxxx\""); // recipient's mobile number, in international format
delay(100);
SIM900.println("Howdy"); // message to send
delay(100);
SIM900.println((char)26); // End AT command with a ^Z, ASCII code 26
delay(100);
SIM900.println();
delay(5000); // give module time to send SMS
SIM900power(); // turn off module
}
void loop()
{
digitalWrite(rfidPin, LOW);
if(Serial.available() > 0) // if data available from reader
{
if((val = Serial.read()) == 10) // check for header
{
bytesread = 0;
while(bytesread<10) // read 10 digit code
{
if( Serial.available() > 0)
{
val = Serial.read();
if((val == 10)||(val == 13)) // if header or stop bytes before the 10 digit reading
break; // stop reading
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
}
}
if(bytesread >= 10) // if 10 digit read is complete
{
digitalWrite(rfidPin, HIGH); // De-Activate the RFID reader
if(strcmp(code, card) == 0)
{
Serial.print("Code is accecpted: ");
Serial.println(code);
SendSMS();
do {} while (1);
}
if(strcmp(code, card2) == 0)
{
Serial.print("Code is alright: ");
Serial.println(code);
SendSMS2();
do {} while (1);
}
else
{
Serial.print(code);
Serial.println(" is not valid!");
}
}
bytesread = 0;
delay(500); // wait for a second
}
}
}
WORKINGCODE2.ino (3.8 KB)