Software Serial

sketch_nov11b.cpp: In function 'void loop()':
sketch_nov11b:110: error: 'SoftwareSerial' was not declared in this scope
sketch_nov11b:110: error: expected `;' before 'RFID'
sketch_nov11b:111: error: 'RFID' was not declared in this scope

//BEGIN CODE

#define servoPin 4 // control pin for servo motor (White or yellow wire of servo)
#define minPulse 500 // minimum servo position (Open position)
#define maxPulse 2200 // maximum servo position (Closed position)
#define rxPin 8 // SOUT pin of RFID module
#define txPin 9
#define enable 2 // /ENABLE pin of RFID module
#define LED1 13 // LED output pin
#define LED2 12 // other LED output pin for two-way LED (yellow)
#define switchPin 7

boolean open = true; // default start up is to assume the lock is open
int val = 0;
char code[10];
int bytesread = 0;
int pulse, switchVal;

char tag1[11] = "0800335036"; // this is size 11 because it is a NULL terminating string
char tag2[11] = "0800330A99";
char tag3[11] = "0F03028B4F";



void LEDControl(int state){

switch (state){
case 1:
digitalWrite(LED1,HIGH);
digitalWrite(LED2,LOW);
break;
case 2:
digitalWrite(LED2,HIGH);
digitalWrite(LED1,LOW);
break;
case 3:
for(int y=0;y<5;y++){
digitalWrite(LED1,HIGH);
digitalWrite(LED2,LOW); 
delay(250);
digitalWrite(LED2,HIGH);
digitalWrite(LED1,LOW);
delay(250);
}
}

}

boolean checkTag(char *tag){

for (int x=0;x<10;x++){
if( tag[x] != code[x]){
return false;
}
}
return true;
}

boolean findGoodTag(){
if (checkTag(tag1)){ return true;}
else if (checkTag(tag2)){ return true;}
else if (checkTag(tag3)){ return true;}

// Add more lines right here like the one above if you have more tags

else{
Serial.print("Bad tag: ");
Serial.println(code);
LEDControl(3);
return false;
}

}
void moveServo(){

if (open){
pulse = minPulse;
open = false;
LEDControl(1);
}
else if (!open){
pulse = maxPulse;
open = true;
LEDControl(2);
}

for (int x =1;x<150;x++){
delay (10); // don't know why this works, but it does
digitalWrite(servoPin, HIGH); // start the pulse
delayMicroseconds(pulse); // pulse width
digitalWrite(servoPin, LOW); // stop the pulse
}

}



void setup() {

pinMode(servoPin, OUTPUT); // Set servo pin as an output pin
pinMode(LED1,OUTPUT); // Set LED pin as output
pinMode(LED2,OUTPUT); // Set LED pin as output
Serial.begin(9600);
Serial.println("Begin");
pinMode(enable,OUTPUT); // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(enable, LOW); // Activate the RFID reader
pinMode(switchPin, INPUT);
}

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

switchVal = digitalRead(switchPin);



if((val = RFID.read()) == 10)
{ // check for header
if(switchVal == HIGH){
Serial.println("Button");
moveServo();
} 
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) && (findGoodTag()))
{ // if 10 digit read is complete 
digitalWrite(enable, HIGH); // dectivate the RFID reader
moveServo(); 
delay(500);
digitalWrite(enable, LOW); // Activate the RFID reader
}
}
}

Don't you need to include some library calls in there somewhere too? Or did I just miss them?

@CrossRoads
I think you mean header files, and yes there is a #include "SoftwareSerial.h" missing. As well it should be, since SoftwareSerial is obsolete.

maker007 should be using NewSoftSerial, instead.

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

Why do you want to create a new instance on every pass through loop?

if((val = RFID.read()) == 10)
{ // check for header
if(switchVal == HIGH){
Serial.println("Button");
moveServo();
}

If the end of the tag data was read, and the switch is held down move the servo.

if((bytesread == 10) && (findGoodTag()))
{ // if 10 digit read is complete
digitalWrite(enable, HIGH); // dectivate the RFID reader
moveServo();
delay(500);
digitalWrite(enable, LOW); // Activate the RFID reader
}

If the end of the tag data was read, and the tag is good, move the servo.

Two questions. Why are you moving the servo in the first block of code, even if the tag was not valid?

Why are you turning the RFID read off and on?

I lied. I have 3 questions. Is your tab key broken, or is the complete lack of indenting a copy/paste issue, or don't you understand the benefits of proper indenting?

OK, so that was three questions, for a total of 5. Oh, well...

char tag1[11] = "0800335036"; // this is size 11 because it is a NULL terminating string
char tag2[11] = "0800330A99";
char tag3[11] = "0F03028B4F";

When declaring and initializing in one step, the compiler will determine the size that the array needs to be. You do not have to explicitly set the size.

its not my code!!!

its not my code!!!

No, it is your question and people on this forum try to help you bringing this code "to live" again. They are not attacking you :slight_smile: Mind you, the code seems to be > 2 years old and there has been quite some progress in the Arduino universe (where time is measured in micro's ...) . So try to understand the advice given and change your code accordingly to see if it works. If not just ask additional questions and explain what you have tried sofar.

Adventures in Technology: Arduino RFID Door lock

It is also informative to read the comments on blogs ...
Rob