Parallax RFID and Door Bell

Hi i am trying to use my arduino as a replacement to my doorbell so it will detect a button press and play a tune. this side works however when i add the parallex RFID reader to operate the electric lock I come across the following issue. Basically the code will wait in the main loop until a tag is scanned before repeating the loop. this means it is not detecting the doorbell press. if anyone can come up with a solution to this i would be most greatefull basically it needs to wait for a tag scan but also watch for the door bell press at the same time.

#include <WString.h>
#include <Tone.h>
#include <SoftwareSerial.h>

int val = 0;
char code[10];
int bytesread = 0;

#define rxPin 8
#define txPin 9
#define DBellLED 3
#define DBellBTN 7
#define DBellSND 5
#define Lock 4

#define maxLength 76

String Tags = String(maxLength); // allocate a new String

char* myTags[10]={“1000BE6CF8\n”, “17003B5CC9\n”, “2400A8000C\n”,“2400AE9166\n”, “1700807CC0\n”,“17007F9B19\n”,“18006BDD63\n”};

int buttonState = 0;
int SongCount = 0;
Tone tone1;
#define OCTAVE_OFFSET 0
int notes = { 0,
NOTE_C4, NOTE_CS4, NOTE_D4, NOTE_DS4, NOTE_E4, NOTE_F4, NOTE_FS4, NOTE_G4, NOTE_GS4, NOTE_A4, NOTE_AS4, NOTE_B4,
NOTE_C5, NOTE_CS5, NOTE_D5, NOTE_DS5, NOTE_E5, NOTE_F5, NOTE_FS5, NOTE_G5, NOTE_GS5, NOTE_A5, NOTE_AS5, NOTE_B5,
NOTE_C6, NOTE_CS6, NOTE_D6, NOTE_DS6, NOTE_E6, NOTE_F6, NOTE_FS6, NOTE_G6, NOTE_GS6, NOTE_A6, NOTE_AS6, NOTE_B6,
NOTE_C7, NOTE_CS7, NOTE_D7, NOTE_DS7, NOTE_E7, NOTE_F7, NOTE_FS7, NOTE_G7, NOTE_GS7, NOTE_A7, NOTE_AS7, NOTE_B7
};

char *song = “The Simpsons:d=4,o=5,b=160:c.6,e6,f#6,8a6,g.6,e6,c6,8a,8f#,8f#,8f#,2g,8p,8p,8f#,8f#,8f#,8g,a#.,8c6,8c6,8c6,c6”;

void setup() {
Serial.begin(9600);
pinMode(DBellLED, OUTPUT);
pinMode(DBellSND, OUTPUT);
pinMode(Lock, OUTPUT);
pinMode(DBellBTN, INPUT);
tone1.begin(DBellSND);
digitalWrite(DBellLED, HIGH);
pinMode(2,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(2, LOW); // Activate the RFID reader
Serial.println(“Loading”);
Serial.println(Tags);
}

void loop()
{

buttonState = digitalRead(DBellBTN);
Serial.println(buttonState);
if (buttonState == HIGH)
{
Serial.println(“DoorBell Pressed”);
digitalWrite(DBellLED, LOW);
play_rtttl(song);
digitalWrite(DBellLED, HIGH);
}
checkTag();

}

void checkTag()
{
SoftwareSerial RFID = SoftwareSerial(rxPin,txPin);
RFID.begin(2400);

if((val = RFID.read()) == 10)
{ // check for header
bytesread = 0;
while(bytesread<10)
{ // read 10 digit code
val = RFID.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
Serial.print("TAG code is: "); // possibly a good TAG
Serial.println(code); // print the TAG code
for (int i = 0; i < 6; i++){
if (strcmp(code, myTags*) == 0)*

  • {*
  • Serial.println(“Allowed”);*
  • digitalWrite(Lock, HIGH);*
  • Serial.println(“Door Unlocked”);*
  • for (int j = 0; j < 10; j++)*
  • {*
  • digitalWrite(DBellLED, LOW);*
  • delay(500);*
  • digitalWrite(DBellLED, HIGH);*
  • delay(500);*
  • }*
  • digitalWrite(Lock, LOW);*
  • Serial.println(“Door Locked”);*
  • }*
  • }*
  • }*
  • bytesread = 0;*
  • delay(500); // wait for a second*
  • } *
  • }*
    Thanks for your help.

These changes may not help with the problem you're currently enduring but they are probably necessry...

void checkTag()
{
  [glow]// Make this a global variable...[/glow]
  [glow]SoftwareSerial RFID = SoftwareSerial(rxPin,txPin);[/glow] 

  [glow]// Move this to setup...[/glow]
  [glow]RFID.begin(2400);[/glow]