Current setup uses a Parralax RFID reader, a servo, and a button. When the button is pushed the servo rotates like it should. When attempting to swipe the correct RFID card that was defined earlier, it doesn’t activate the servo. I tested using the Serial connection to see if the codes matched, and they did. Another interesting note: when I replace the == 1 to == 0 after the strcmp, it still wouldn’t activate the servo, but like usual, the rest of the code worked as usual. Anyone might know what is going on and/or how I fix this?
#include <Servo.h>
Servo Servo1;
int val = 0;
char code[10];
int bytesread = 0;
int ServoPin = 9;
int ButtonPin = 8;
char Card[] = {'0','4','1','5','E','D','3','F','4','7'};
void setup() {
Serial.begin(2400); // Start serial connection
pinMode(2,OUTPUT); // RFID Enable pin
pinMode(ButtonPin,INPUT);
pinMode(ServoPin,OUTPUT);
digitalWrite(2, LOW); // Enable the RFID reader
Servo1.attach(ServoPin);
Servo1.write(0);
}
void loop() {
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
Serial.println(code);
Serial.println(Card);
String Code = String(code);
if ( strcmp(code,Card) == 1 ) { ServoCycle; }
}
bytesread = 0;
digitalWrite(2, HIGH); // deactivate the RFID reader for a moment so it will not flood
delay(3000); // wait for a bit
digitalWrite(2, LOW); // Activate the RFID reader
}
}
if ( digitalRead(ButtonPin) == HIGH ) { ServoCycle(); }
}
void ServoCycle()
{
Servo1.write(100);
delay(3000);
Servo1.write(0);
loop();
}
I did use someone’s example RFID reading code as my base and added onto it. Any help would be greatly appreciated!