Hello Forum
I am currently working on a project where I have to send out a SMS when a specific RFID tag is scanned. I have my ID-20LA and my SIM900 shield hooked up to my Arduino Uno, and both of them working fine on their own. Both the RFID reader and the GSM shield communicates with my Uno via the software-serial library.
This is my shield
http://imall.iteadstudio.com/im120417009.html
This is my current sketch. It should have functioned this way. "When two known tags gets scanned, send a sms" - what I actually get is that I can't scan any RFID's at all, and no sms gets send.
#include <SoftwareSerial.h>
#include "SIM900.h"
#include "sms.h"
SMSGSM sms;
SoftwareSerial mySerial(4,A2); // RX, TX
int RFIDResetPin = 5;
//Tags tilføjes her, de kan findes i seriel monitor, når et tag scannes.
char tag1[13] = "01002DC7D03B";
char tag2[13] = "01002DC6678D";
void setup(){
mySerial.begin(9600);
Serial.begin(9600);
gsm.begin(2400);
pinMode(RFIDResetPin, OUTPUT);
digitalWrite(RFIDResetPin, HIGH);
mySerial.listen();
}
void loop(){
char tagString[13];
int index = 0;
boolean reading = false;
while(mySerial.available()){
int readByte = mySerial.read(); //read next available byte
if(readByte == 2) reading = true; //begining of tag
if(readByte == 3) reading = false; //end of tag
if(reading && readByte != 2 && readByte != 10 && readByte != 13){
//store the tag
tagString[index] = readByte;
index ++;
}
}
checkTag(tagString); //Check if it is a match
clearTag(tagString); //Clear the char of all value
resetReader(); //eset the RFID reader
}
void checkTag(char tag[]){
///////////////////////////////////
//Check the read tag against known tags
///////////////////////////////////
if(strlen(tag) == 0) return; //empty, no need to contunue
if(compareTag(tag, tag1)){ // if matched tag1, do this
sms.SendSMS("12345678", "TAG1"); //12345678 = phonenumber
}
else if(compareTag(tag, tag2)){ //if matched tag2, do this
sms.SendSMS("12345678", "TAG2");
}
else{
Serial.println(tag); //Læs ukendte tags, og print serielt.
}
}
void resetReader(){
//reset læseren
digitalWrite(RFIDResetPin, LOW);
digitalWrite(RFIDResetPin, HIGH);
delay(150);
}
void clearTag(char one[]){
//clear the char array by filling with null - ASCII 0
//Will think same tag has been read otherwise
for(int i = 0; i < strlen(one); i++){
one[i] = 0;
}
}
boolean compareTag(char one[], char two[]){
//compare two value to see if same,
if(strlen(one) == 0) return false; //empty
for(int i = 0; i < 12; i++){
if(one[i] != two[i]) return false;
}
return true; //no mismatches
}
I've read that the Arduino can't handle two software serials running at once, and therefore you have to use the function ".listen" before communicating with either the RFID or the SIM900. At the bottom of my void setup i end with "mySerial.listen();" to be able to scan my tags. Then when a known tag is scanned, I would like to send a sms, which is this part of the sketch:
if(compareTag(tag, tag1)){ // if matched tag1, do this
gsm.listen();
sms.SendSMS("12345678", "TAG1"); //12345678 = phonenumber
I am then trying to use the "gsm.listen();" before sending the message. The problem is that theres is no ".listen" function build into the SIM900 library and therefore I can't use it. Even if I delete the line "gsm.listen();" I don't receive the sms.
Does anyone know how I can change the serial from the RFID to the SIM900 so I can send my sms?
thank you very much
best regards
Johannes