hi! i have RDM630 and mega 2560. its working now. However, when I tap the authorized key tag it does not stop rotating. I want my servo motor to be rotating for only about 5 secs in both direction when an authorized key tag is tapped. Im using it for a lock. please help, here's my code:
//the LED turns on or blink
#include <SoftwareSerial.h>
#include <Servo.h>
SoftwareSerial RFID = SoftwareSerial(10,11);
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
char character;
String our_id;
void setup() {
myservo.attach(12); // attaches the servo on pin 12 to the servo object
Serial.begin(9600);
RFID.begin(9600);
pinMode(13, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
}
void servo()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
// loop ();
//myservo. detach ();
}
}
void loop() {
while(RFID.available()>0)
{
character = RFID.read();
our_id += character;
}
if (our_id.length() > 10) {
our_id = our_id.substring(1,13);
if (our_id == "76002C2AF686")
{
Serial.print ("USER: Rowena Joy C. Perez \n");
Serial.print("ACCESS GRANTED (id: ");
Serial.print(our_id);
our_id = "";
Serial.println(" ) ");
servo ();
digitalWrite(8, HIGH);
//digitalWrite(13,HIGH);
delay(1000);
digitalWrite(8,LOW);
// digitalWrite(13, LOW);
delay(1000);
}
else
{
Serial.print ("UNAUTHORIZED USER \n");
Serial.print("ACCESS DENIED (id: ");
Serial.print(our_id);
our_id = "";
Serial.println(" ) ");
digitalWrite(13,HIGH);
int x = 3;
for (x; x > 0; x--)
{
delay(100);
digitalWrite(9, HIGH);
delay(100);
digitalWrite(9, LOW);
}
digitalWrite(13,LOW);
}
}
our_id = "";
delay(1000);
}