Moving servo to specific positions

Any help with this would be appreciated. I am not a programmer, as you may see!
I have tried basically the same sketch, but using ‘case’ in place of ‘else if’, and various other iterations of this sketch, but no success!
In this project I will send info from RFID reader via serial to Max Msp to trigger some eye and ear candy, that part is working very well!
However, I thought I would use a servo connected to Arduino to turn an arrow to point to specific points on a dial (that naturally relates to each card)…if it doesn’t happen the project will be fine to go, but after two days I am rather at a dead end but still have the bit between my teeth!!

Any help welcome!
//////////////////////arduino sketch/////////////////
////code to send single number to serial (for max/msp) and to turn pointer to indicate selection.
///adapted from many sources

#include <SoftwareSerial.h>
#define rxPin 0
#define txPin 1

//create a Serial object RFID
SoftwareSerial RFID = SoftwareSerial(rxPin, txPin);
char code[20];

int val = 0;
int bytesread = 0;

int pointer = 0; // pointer value
// starsign cards send to position = 1, start card sets pointer to reset = 2
int servoPin = 4; // pin for servo motor tried pwm 9
int i=0;
int degree = 0;

//relating signs with rfid code
char Aquarius = “0415A1112786”;//1
char Pisces = “1F001A920097”;//2
char Aries = “1F001AAFA802”;//3
char Taurus = “1F001AC7BF7D”;//4
char Gemini = “1F001AA612B1”;//5
char Cancer = “0415A10962DB”;//6
char Leo = “0415A1110EAF”;//7
char Virgo = “0415A1103191”;//8
char Libra = “0415A104A014”;//9
char Scorpio = “0415A106CA7C”;//10
char Sagittarius = “0415A110F959”;//11
char Capricorn = “1F001A7F3F45”;//12

void setup()
{
Serial.begin(9600); //open serial hardware
RFID.begin(9600); //open serial software
pinMode(rxPin, INPUT); //set pin on arduino for receiving RFID data
pinMode(txPin, OUTPUT); //this is not important
}

void loop()
{
if (pointer == 1) //when card is recognized
{
point(); //Use function “point”
delay (500);
}
if (pointer == 2) //ifcard is reset
{
reset(); //use function “reset” (see below)
}
delay (500);

val = 0;
bytesread = 0;

while(bytesread < 12)
{
// read 12 digit code
val = RFID.read();
if(val == 3)
{ // if header or stop bytes before the 10 digit reading
break; // stop reading
}

if(val != 2)
{
code[bytesread] = val; // add the digit
bytesread++; // ready to read next digit
code[bytesread] = ‘\0’; // add the NULL
}
}

if(bytesread >= 12)
{ // if 12 digit read is complete

for(int i=0; i<bytesread; i++)
{
}
int tag = FindValidTag(code);
Serial.print("");//if no text reading is not always right add delay?
Serial.println(tag);

}
}

int FindValidTag(char *code)
{
if(strcmp(code, Aquarius) == 0)
{
degree=60;//trial value
return 1;
pointer=1;
}

else if(strcmp(code, Pisces) == 0)
{
degree=70;
return 2;
}

else if(strcmp(code, Aries) == 0)
{
degree = 80;//trial value
return 3;
}

else if(strcmp(code, Taurus) == 0){
degree = 90;//trial value
return 4;
}

else if(strcmp(code, Gemini) == 0)
{
degree = 100;//trial value
return 5;
}

else if(strcmp(code, Cancer) == 0)
{
degree = 110;//trial value
return 6;
}

else if(strcmp(code, Leo) == 0)
{
degree = 120;//trial value
return 7;
}

else if(strcmp(code, Virgo) == 0)
{
degree = 130;//trial value
return 8;
}

else if(strcmp(code, Libra) == 0)
{
degree = 140;//trial value
return 9;
}

else if(strcmp(code, Scorpio) == 0)
{
degree = 150;//trial value
return 10;
}

else if(strcmp(code, Sagittarius) == 0)
{
degree = 160;//trial value
return 11;
}

else if(strcmp(code, Capricorn) == 0)
{
degree = 170;//trial value
return 12;
}

else
{
return 0;
pointer=2;
}
}

void point()
{
//pointer=degree;
{
digitalWrite(servoPin, HIGH); // start the pulse to servo
delayMicroseconds(degree); // length of pulse try multiplier? 10/100/1000
digitalWrite(servoPin, LOW); // stop the pulse to servo

}
delay(5000);
}
void reset()
{
//send pointer back to start ‘choose card’ code to go here
}

#include <SoftwareSerial.h>
#define rxPin 0
#define txPin 1

//create a Serial object RFID
SoftwareSerial RFID = SoftwareSerial(rxPin, txPin);

Wrong. You should not be doing software serial on the hardware serial pins.

 else
 {
   return 0;
   pointer=2;
 }

Setting the value of pointer AFTER the return was a waste of typing.

void point()
{
 //pointer=degree;
 {
   digitalWrite(servoPin, HIGH);   // start the pulse to servo
   delayMicroseconds(degree);  // length of pulse try multiplier? 10/100/1000
   digitalWrite(servoPin, LOW);    // stop the pulse to servo

 }

Something wrong with the Servo library?

All you said in your post was “this didn’t work”. You’ve got several things going on - reading the RFID cards, moving the servo to specific angles, etc. What is working? What is not working? What do you need help with?

There isn’t exactly a question in your post.

Below is some servo control code you can use to find what values to use to get the servo to point to where you want.

// zoomkat 10-4-10 serial servo test
// type servo position 0 to 180 in serial monitor
// for writeMicroseconds, use a value like 1500
// for IDE 0019 and later
// Powering a servo from the arduino usually DOES NOT WORK.

String readString;
#include <Servo.h> 
Servo myservo;  // create servo object to control a servo 

void setup() {
  Serial.begin(9600);
  myservo.attach(7);  //the pin for the servo control 
  Serial.println("servo-test-21"); // so I can keep track of what is loaded
}

void loop() {

  while (Serial.available()) {
    delay(10);  
    if (Serial.available() >0) {
      char c = Serial.read();  //gets one byte from serial buffer
      readString += c; //makes the string readString
    } 
  }

  if (readString.length() >0) {
    Serial.println(readString);  //so you can see the captured string 
    int n;
    char carray[6]; //converting string to number
    readString.toCharArray(carray, sizeof(carray));
    n = atoi(carray); 
    myservo.writeMicroseconds(n); // for microseconds
    //myservo.write(n); //for degees 0-180
    readString="";
  } 
}

Thanks for highlighting coding errors!
The RFID tags are read ok, and converted to integers, then the data is sent via serial to Max/MSP where each integer (1-12) sets off various events.

What is not happening is any movement of servo! My question should be something like:
How can I make servo move to a chosen position that is defined by choice of information from RFID tag ?

I have tried reading serial data, see sketch below, but I get a conflict somewhere that means wrong data is written to serial (I get a return of ‘0’ c. 90% of time and correct integer c.10% when using this sketch, however the servo does exhibit some movement (tho’ not anywhere specific!).

#include <SoftwareSerial.h>
#include <Servo.h>
#define rxPin 0
#define txPin 1
Servo myservo;
//create a Serial object RFID
SoftwareSerial RFID = SoftwareSerial(rxPin, txPin);
char code[20];

int pos = 0;
int incomingByte;
int m = 0;
int ledState = LOW;
int value = 0;


int val = 0;
int bytesread = 0;
char Aquarius[]  = "0415A1112786";//1
char Pisces[]  = "1F001A920097";//2
char Aries[]  = "1F001AAFA802";//3
char Taurus[] = "1F001AC7BF7D";//4
char Gemini[] = "1F001AA612B1";//5
char Cancer[]  = "0415A10962DB";//6
char Leo[]  = "0415A1110EAF";//7
char Virgo[]  = "0415A1103191";//8
char Libra[]  = "0415A104A014";//9
char Scorpio[]  = "0415A106CA7C";//10
char Sagittarius[]  = "0415A110F959";//11
char Capricorn[]  = "1F001A7F3F45";//12

int ledCnt = 5;
int LED[] = {
  13, 11, 9, 7, 5};

void setup()
{
  Serial.begin(9600); //open serial hardware
  RFID.begin(9600); //open serial software

  pinMode(rxPin, INPUT); //set pin on arduino for receiving RFID data
  pinMode(txPin, OUTPUT); //this is not important

  myservo.attach(9);

}

void loop()
{


  val = 0;
  bytesread = 0;

  while(bytesread < 12)
  {
    // read 12 digit code
    val = RFID.read();
    if(val == 3)
    { // if header or stop bytes before the 10 digit reading
      break; // stop reading
    }

    if(val != 2)
    {
      code[bytesread] = val; // add the digit
      bytesread++; // ready to read next digit
      code[bytesread] = '\0'; // add the NULL
    }
  }

  if(bytesread >= 12)
  {    
    for(int i=0; i<bytesread; i++)
    {

    }

    int tag = FindValidTag(code);
    Serial.print("");//if no text reading is not always right add delay?
    Serial.println(tag);


  }
  while (Serial.available() > 0)
  {
    //value *= 10;
    value = (Serial.read() );//+=
    //delay(100);
  }

  myservo.write(value);
}

int FindValidTag(char *code)
{
  if(strcmp(code, Aquarius) == 0)
    return 1;
  else if(strcmp(code, Pisces) == 0)
    return 2;
  else if(strcmp(code, Aries) == 0)
    return 3;
  else if(strcmp(code, Taurus) == 0)
    return 4;
  else if(strcmp(code, Gemini) == 0)
    return 5;
  else if(strcmp(code, Cancer) == 0)
    return 6; 
  else if(strcmp(code, Leo) == 0)
    return 7;
  else if(strcmp(code, Virgo) == 0)
    return 8;
  else if(strcmp(code, Libra) == 0)
    return 9;
  else if(strcmp(code, Scorpio) == 0)
    return 10;
  else if(strcmp(code, Sagittarius) == 0)
    return 11;
  else if(strcmp(code, Capricorn) == 0)
    return 12;
  else
    return 0;
}
  Serial.begin(9600); //open serial hardware
  RFID.begin(9600); //open serial software

Repeat after me: “I CAN NOT USE THE SAME PINS FOR TWO DIFFERENT PURPOSES”.

Really. Once you get past that, things will improve.

  pinMode(rxPin, INPUT); //set pin on arduino for receiving RFID data
  pinMode(txPin, OUTPUT); //this is not important

You are asking Serial to control these pins, and SoftwareSerial (which, by the way, is obsolete; you should be using NewSoftSerial) AND explicitly setting pinMode.

You can’t do that.

It’s no wonder you are having problems with serial communication.

    for(int i=0; i<bytesread; i++)
    {

    }

Looks quite useful. I wonder why more people don’t do this.

Well I have been looking at this for awhile now, but I can still not get integer written to serial all the time! I still sometimes get a 0 in place of correct integer (1-12). PaulS thanks for advice, about use of this:

 Serial.begin(9600); //open serial hardware
  RFID.begin(9600); //open serial software

But if remove Serial.begin (9600), no number will be sent to max msp, if I remove RFID.begin(9600), then no signal will be received from ID-12 reader!! But like i said I am not a programmer!!
Question: If anybody could advise on how to improve this code to make RFID reader always write correct integer to serial, I would be grateful! Else I will cover up,…errr creatively ehnance…effect in Max!

//////////Code for Arduino//////////

#include <SoftwareSerial.h>
#define rxPin 0
#define txPin 1

#include <Servo.h>
Servo myservo;  // create object to control a servo
SoftwareSerial RFID = SoftwareSerial(rxPin, txPin);
char code[20];

int val = 0;
int bytesread = 0;
char Aquarius[]  = "0415A1112786";//1
char Pisces[]  = "1F001A920097";//2
char Aries[]  = "1F001AAFA802";//3
char Taurus[] = "1F001AC7BF7D";//4
char Gemini[] = "1F001AA612B1";//5
char Cancer[]  = "0415A10962DB";//6
char Leo[]  = "0415A1110EAF";//7
char Virgo[]  = "0415A1103191";//8
char Libra[]  = "0415A104A014";//9
char Scorpio[]  = "0415A106CA7C";//10
char Sagittarius[]  = "0415A110F959";//11
char Capricorn[]  = "1F001A7F3F45";//12


void setup()
{
  Serial.begin(9600); //open serial 
  RFID.begin(9600); //open serial
  myservo.attach(7);  //the pin for the servo control
}

void loop()
{
  val = 0;
  bytesread = 0;

  while(bytesread < 12)
  {
    // read 12 digit code
    val = RFID.read();
    if(val == 3)
    { 
      break; // stop reading
    }

    if(val != 2)
    {
      code[bytesread] = val; // add the digit
      bytesread++; // ready to read next digit
      code[bytesread] = '\0'; // add the NULL
    }
  }

  if(bytesread >= 12)
  { 
    int tag = FindValidTag(code);
    Serial.print("");
    Serial.println(tag);

  }
}

int FindValidTag(char *code)
{
  if(strcmp(code, Aquarius) == 0){
    myservo.write(40);
    return 1;
  }
  else if(strcmp(code, Pisces) == 0){
    myservo.write(50);
    return 2;
  }
  else if(strcmp(code, Aries) == 0){
    myservo.write(60);
    return 3;
  }
  else if(strcmp(code, Taurus) == 0){
    myservo.write(70);
    return 4;
  }
  else if(strcmp(code, Gemini) == 0){
    myservo.write(80);
    return 5;
  }
  else if(strcmp(code, Cancer) == 0){
    myservo.write(90);
    return 6; 
  }
  else if(strcmp(code, Leo) == 0){
    myservo.write(100);
    return 7;
  }
  else if(strcmp(code, Virgo) == 0){
    myservo.write(120);
    return 8;
  }
  else if(strcmp(code, Libra) == 0){
    myservo.write(130);
    return 9;
  }
  else if(strcmp(code, Scorpio) == 0){
    myservo.write(140);
    return 10;
  }
  else if(strcmp(code, Sagittarius) == 0){
    myservo.write(150);
    return 11;
  }
  else if(strcmp(code, Capricorn) == 0){
    myservo.write(160);
    return 12;
  }
  else
    return 0;
}

The SoftwareSerial class (which is obsolete, and has been replaced by NewSoftSerial) can use ANY 2 digital pins. Just plug the RFID reader into two other pins, and change the values of txPin and rxPin.

Until you do that, you and the rest of us are wasting time. You because you can not use the same pair of pins to talk to the RFID reader and the hardware serial port at the same time, and us because you are not listening to us.

PaulS thanks for pointing out previous errors.
OK I am completely stuck. My latest sketch, spews out the last ‘return’ as fast as serial connection allows. If I comment out the last conditional ‘else’ it gives me ‘1290’ in the serial window.
I don’t know what is wrong with code BUT I do know it is wrong, which is something!?!
Can anybody please guide me to correcting this code. I want the integer, decided by reading RFID tag, to be sent via serial, to be used by Max/Msp (that is working fine with a previous Arduino sketch). I then decided to add a servo movement to sketch that is related to RFID tag and my problems began!

#include <NewSoftSerial.h>

NewSoftSerial rfidSerial =  NewSoftSerial(8,7);  

#include <Servo.h>
Servo myservo;  // create object to control a servo

char code[20];

int val = 0;
int bytesread = 0;

char Aquarius[]  = "0415A1112786";//1
char Pisces[]  = "1F001A920097";//2
char Aries[]  = "1F001AAFA802";//3
char Taurus[] = "1F001AC7BF7D";//4
char Gemini[] = "1F001AA612B1";//5
char Cancer[]  = "0415A10962DB";//6
char Leo[]  = "0415A1110EAF";//7
char Virgo[]  = "0415A1103191";//8
char Libra[]  = "0415A104A014";//9
char Scorpio[]  = "0415A106CA7C";//10
char Sagittarius[]  = "0415A110F959";//11
char Capricorn[]  = "1F001A7F3F45";//12


void setup()
{
  Serial.begin(9600); //open serial 
  rfidSerial.begin(9600);  
  myservo.attach(2);  //the pin for the servo control
}

void loop()
{
  val = 0;
  bytesread = 0;

  while(bytesread < 12)
  {
    // read 12 digit code
    val = rfidSerial.read();
    if(val == 3)
    { 
      break; // stop reading
    }

    if(val != 2)
    {
      code[bytesread] = val; // add the digit
      bytesread++; // ready to read next digit
      code[bytesread] = '\0'; // add the NULL
    }
  }

  if(bytesread >= 12)
  { 
    int tag = FindValidTag(code);
    Serial.print("");//
    Serial.println(tag);//

  }
}

int FindValidTag(char *code)
{
  if(strcmp(code, Aquarius) == 0){
    myservo.write(40);
    return 1;
  }
  else if(strcmp(code, Pisces) == 0){
    myservo.write(50);
    return 2;
  }
  else if(strcmp(code, Aries) == 0){
    myservo.write(60);
    return 3;
  }
  else if(strcmp(code, Taurus) == 0){
    myservo.write(70);
    return 4;
  }
  else if(strcmp(code, Gemini) == 0){
    myservo.write(80);
    return 5;
  }
  else if(strcmp(code, Cancer) == 0){
    myservo.write(90);
    return 6; 
  }
  else if(strcmp(code, Leo) == 0){
    myservo.write(100);
    return 7;
  }
  else if(strcmp(code, Virgo) == 0){
    myservo.write(120);
    return 8;
  }
  else if(strcmp(code, Libra) == 0){
    myservo.write(130);
    return 9;
  }

  else if(strcmp(code, Scorpio) == 0){
    myservo.write(140);
    return 10;
  }
  else if(strcmp(code, Sagittarius) == 0){
    myservo.write(150);
    return 11;
  }
  else if(strcmp(code, Capricorn) == 0){
    myservo.write(160);
    return 12;
  }
  else
    myservo.write(10);
  //  return 0;////this value printed over over againcommented out returns multiple 1290


}

Comment out the call to FindValidTag, until you know what the problem is. Print the number of bytes read, and the value in code, to the serial port.

Until you can confirm that you are reading something reasonable, there is no reason to invoke additional code.

What does code contain, when you scan a tag?

OK I will have to put this on back burner for a while!

I cannot get NewSoftSerial to work with ID12 RFID reader! I have no problems reading cards and sending data via serial to Max/MSP with using SoftwareSerial, so I will either forsake using a servo or put up with intermittent movement!! It is a shame after 4 days(!!!) on this to throw in the towel but I am totally at a loss!

Thanks for help PaulS and zoomkat!

while(bytesread < 12)
  {
    // read 12 digit code
    val = rfidSerial.read();

How do you know that there is something there to read?

I was just throwing my towel down and…! Thanks PaulS. My code now reads RFID tags and spits out the required integer to serial…BUT any hint of a servo seemingly (see commented out code…) corrupts that data. There have been a few attempts (writing degree value declared in conditional to servo, reading Serial, reading rfidSerial and attempting to integrate zoomkat sketch).

#include <NewSoftSerial.h>
NewSoftSerial rfidSerial =  NewSoftSerial(8,7);  
//#include <Servo.h>
//Servo myservo;

char code[20];

int pos = 0;
int incomingByte;
int m = 0;

int value = 0;


int val = 0;
int bytesread = 0;
char Aquarius[]  = "0415A1112786";//1
char Pisces[]  = "1F001A920097";//2
char Aries[]  = "1F001AAFA802";//3
char Taurus[] = "1F001AC7BF7D";//4
char Gemini[] = "1F001AA612B1";//5
char Cancer[]  = "0415A10962DB";//6
char Leo[]  = "0415A1110EAF";//7
char Virgo[]  = "0415A1103191";//8
char Libra[]  = "0415A104A014";//9
char Scorpio[]  = "0415A106CA7C";//10
char Sagittarius[]  = "0415A110F959";//11
char Capricorn[]  = "1F001A7F3F45";//12

void setup()
{
  Serial.begin(9600); //open serial hardware
  rfidSerial.begin(9600); //open serial software


  // myservo.attach(2);

}

void loop()
{


  val = 0;
  if(rfidSerial.available() > 0) {
    if((val = rfidSerial.read()) == 2) {                  // check for header 
      bytesread = 0; 
      while(bytesread < 12)
        if( rfidSerial.available() > 0) { 

          // read 12 digit code
          val =  rfidSerial.read();
          if(val == 3)
          { // if header or stop bytes before the 10 digit reading
            break; // stop reading
          }

          if(val != 2)
          {
            code[bytesread] = val; // add the digit
            bytesread++; // ready to read next digit
            code[bytesread] = '\0'; // add the NULL
          }
        }

      if(bytesread >= 12)
      {    
        for(int i=0; i<bytesread; i++)
        {
          //remove cause problem with tag 
        }

        int tag = FindValidTag(code);
        rfidSerial.print("");//if no text reading is not always right add delay?
        Serial.println(tag);


      }
      while (Serial.available() > 0)
      {
        //value *= 10;
        //value = (Serial.read());//
        //delay(100);
      }

      //myservo.write(value);
    }
  }
}

int FindValidTag(char *code)
{
  if(strcmp(code, Aquarius) == 0){
    return 1;
    // myservo.write(179);
  }
  else if(strcmp(code, Pisces) == 0){
    return 2;
    //myservo.write(30);
  }
  else if(strcmp(code, Aries) == 0)
    return 3;
  else if(strcmp(code, Taurus) == 0)
    return 4;
  else if(strcmp(code, Gemini) == 0)
    return 5;
  else if(strcmp(code, Cancer) == 0)
    return 6;
  else if(strcmp(code, Leo) == 0)
    return 7;
  else if(strcmp(code, Virgo) == 0)
    return 8;
  else if(strcmp(code, Libra) == 0)
    return 9;
  else if(strcmp(code, Scorpio) == 0)
    return 10;
  else if(strcmp(code, Sagittarius) == 0)
    return 11;
  else if(strcmp(code, Capricorn) == 0)
    return 12;
  else
    return 0;
}

What is the output of the RFID? Is it a string of characters, an integer?

The RFID reader reads a card and the arduino code converts each RFID code to a number(ie integer).
e.g
char Aquarius = “0415A1112786”;// this is shown in serial window as 1
char Pisces = “1F001A920097”;//this is shown in serial window as2
char Aries = “1F001AAFA802”;//this is shown in serial window as3
char Taurus = “1F001AC7BF7D”;//this is shown in serial window as4
and likewise for each card.

This number is then picked up by Max/MSP via serial to be used to select various visual and audio delights for the ears and eyes!!

That part works fine, both with my original code using ‘SoftwareSerial’ and with amended code(with help from PaulS) using ‘NewSoftSerial’ ! But when I try to steer a servo to physically indicate choice of card I get problems. Annoyingly this effect is not essential for project, the project can roll on without this. ! But after 4 1/2 days my simple idea is not so simple.

I get a compile error at the below line.

NewSoftSerial rfidSerial = NewSoftSerial(8,7);

I get a compile error at the below line.

zoomkat, you know better than that.

What error are you getting?

What error are you getting?

“‘NewSoftSerial’ does not name a type”

I’m using IDE0021

No other messages? Like not being able to open NewSoftSerial.h?

Problem solved. When I downloaded NewSoftSerial, I made a NewSoftSerial folder in the libraries folder and unzipped the files there. Apparently the zip file made its own sub folder and put the files in the sub folder, apparently causing the usual file location issue. The sketch compiles now.

Working.!!
Thanks for guidance PaulS and Zoomkat! I went back to one of my initial almost working sketches and tinkered. The main culprit seened to be excluding this from code:

if(rfidSerial.available() > 0) {
    if((val = rfidSerial.read()) == 2) {

What a mission this turned out to be…now what can I find to confuse me for another few days…stay tuned!!
Here is code needs some tidying up…still it works!

#include <NewSoftSerial.h>
NewSoftSerial rfidSerial =  NewSoftSerial(8,7);  

#include <Servo.h>
Servo myservo;  // create object to control a servo
//SoftwareSerial RFID = SoftwareSerial(rxPin, txPin);
char code[20];

int val = 0;
int bytesread = 0;
char Aquarius[]  = "0415A1112786";//1
char Pisces[]  = "1F001A920097";//2
char Aries[]  = "1F001AAFA802";//3
char Taurus[] = "1F001AC7BF7D";//4
char Gemini[] = "1F001AA612B1";//5
char Cancer[]  = "0415A10962DB";//6
char Leo[]  = "0415A1110EAF";//7
char Virgo[]  = "0415A1103191";//8
char Libra[]  = "0415A104A014";//9
char Scorpio[]  = "0415A106CA7C";//10
char Sagittarius[]  = "0415A110F959";//11
char Capricorn[]  = "1F001A7F3F45";//12


void setup()
{
  Serial.begin(9600); //open serial
  rfidSerial.begin(9600); //open serial
  myservo.attach(2);  //the pin for the servo control
}

void loop()
{


  val = 0;
  if(rfidSerial.available() > 0) {
    if((val = rfidSerial.read()) == 2) {                  // check for header
      bytesread = 0;
      while(bytesread < 12)
        if( rfidSerial.available() > 0) {

          // read 12 digit code
          val =  rfidSerial.read();
          if(val == 3)
          { // if header or stop bytes before the 10 digit reading
            break; // stop reading
          }

          if(val != 2)
          {
            code[bytesread] = val; // add the digit
            bytesread++; // ready to read next digit
            code[bytesread] = '\0'; // add the NULL
          }
        }

      if(bytesread >= 12)
      {    
        for(int i=0; i<bytesread; i++)
        {
          //remove cause problem with tag
        }

        int tag = FindValidTag(code);
        rfidSerial.print("");//if no text reading is not always right add delay?
        Serial.println(tag);


      }
      while (Serial.available() > 0)
      {
        //pos=map(val,0,12,0,179);
        //myservo.write(val);
        //value *= 10;
        //value = (Serial.read());//
        //delay(100);
      }

      
    }
  }
}

int FindValidTag(char *code)
{
  if(strcmp(code, Aquarius) == 0){
    myservo.write(40);
    return 1;
  }
  else if(strcmp(code, Pisces) == 0){
    myservo.write(50);
    return 2;
  }
  else if(strcmp(code, Aries) == 0){
    myservo.write(60);
    return 3;
  }
  else if(strcmp(code, Taurus) == 0){
    myservo.write(70);
    return 4;
  }
  else if(strcmp(code, Gemini) == 0){
    myservo.write(80);
    return 5;
  }
  else if(strcmp(code, Cancer) == 0){
    myservo.write(90);
    return 6;
  }
  else if(strcmp(code, Leo) == 0){
    myservo.write(100);
    return 7;
  }
  else if(strcmp(code, Virgo) == 0){
    myservo.write(120);
    return 8;
  }
  else if(strcmp(code, Libra) == 0){
    myservo.write(130);
    return 9;
  }
  else if(strcmp(code, Scorpio) == 0){
    myservo.write(140);
    return 10;
  }
  else if(strcmp(code, Sagittarius) == 0){
    myservo.write(150);
    return 11;
  }
  else if(strcmp(code, Capricorn) == 0){
    myservo.write(160);
    return 12;
  }
  else{
    return 0;
  }
}