State change random feature

this entire project has anoyed me beyond belief. i dont get whats going on and how to fix it.

it looks good, it compiles, but just does bugger all at this point. fustration as exceeded maximum capacity.

thanks for trying to get this to work, and thanks for the help. i just dont know how to move forward at this point

i was thinking that maybe a complete change of tact is in order, perhaps just taking the RFID code, getting that to function with a single servo, then just use an if statement, random function and millis in the same loop as the RFID in order to randomly get the other servos to do the job and ditch the case switch entirely.

honestly the only reason i used case switches was to ensure the rfid code wasnt triggered while the servos where already doing something, but i can supress that by adding code to return the servo's to original possition when the rfid is triggered anyway or an if statement using greater/smaller than to compensate.....maybe....

think this might be the way to go instead?

so i threw this together, it compiled, without errors, NO errors, no warnings nothing.

#include <Wire.h>
#include <SPI.h>
#include <Servo.h>
#include <MFRC522.h>

MFRC522 mfrc522(10, 9); // MFRC522 mfrc522(SS_PIN, RST_PIN)
Servo myservo;
int angle = 0;
String tagUID = "9A 71 1C B0"; // String to store UID of tag. Change it with your tag's UID
const unsigned long fist = random (4000, 5000);
const unsigned long thumb = random (6000, 7000);


void setup() {
  Serial.begin(115200);
  Serial.println("start setup");
  myservo.attach(6);
  SPI.begin(); // Init SPI bus
  mfrc522.PCD_Init(); // Init MFRC522
  myservo.write(0);
  Serial.println("setup complete");

}
void loop() {

  Serial.println("look for new cards");
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }

  Serial.println("reading from card");
  String tag = "";
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
    tag.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
    tag.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  tag.toUpperCase();

  Serial.println("checking the card");
  if (tag.substring(1) == tagUID) //change here the UID of the card/cards that you want to give access
  {
    Serial.println("if match novement here");
    if (angle < 90) {
      myservo.write(90);
    }
    else
    { myservo.write(45);
    }
    delay(200);
    myservo.write(0);
  }
  Serial.println("checking millis for fist");
  if ( millis() == fist) {
    myservo.write(0);
    delay (200);
    myservo.write(130);
  }

}

edited to update new code correctly.

the idea is i can expand on it and see where it goes......next step, upload it and see if....well anything happens

it seems to work, except for the parts for "fist" but progress

OK, I feel your pain. But we can't help, unless we see the code you are talking about, and you get way more thorough describing what you are getting, or not getting.

Taken literally, your report makes no sense.

Spend just a bit more time, use your best common sense and see if, by placing your finger on the code and playing real dumb, you don't notice right away where you go off the rails.

Maybe you see something, maybe you don't.

I still can't tell you don't have an hardware issue, so:

Freeze a version of your code, post it here. Preferably something that compiles and runs; carefully describe how it differs from what you wish was happening.

Take a break from that frozen code. I'll take a peek when I can. Place your attention on the rfid part, get that responding without any servo code, just the card reader. See if it is operating well. You may have done this already, post it if you did, and say it worked well. Or use the below instead of the loop() in your current full code, so you pick up the setup() and other stuff so it will compile and run.

This is called hacking. Not a bad thing, necessarily. Note the crap-ton of printing to see every little thing that is happening.

void loop()
{
  String tag = "";
  unsigned char aByte;

  delay(200);  // poor man's 5 times a second could be slower even

  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    Serial.println("I see no card.");
    return;
  }

  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    Serial.println("I can't read the card.");  // can't? didn't?
    return;
  }

  Serial.println("I think I have something. Just a moment. Just a moment.");

  //Reading from the card
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
    aByte = mfrc522.uid.uidByte[i];
    Serial.print("<");
    Serial.print(aByte);
    Serial.println(">");

    if (aByte < 0x10)
      tag.concat(String(" 0"));
    else
      tag.concat(String(" "));

    tag.concat(String(aByte, HEX));

    Serial.print("                >");
    Serial.print(tag);
    Serial.println("<");
  }

  tag.toUpperCase();
  Serial.print(" and upper cased                            ");
  Serial.println(tag);

  //Checking the card

  if (tag.substring(1) == tagUID) //change here the UID of the card/cards that you want to give access
  {
    Serial.println("tagUID match found.");
    delay(777);
  }
  else
    Serial.println("the casd is not valid.");
}

So. Post a current version that compiles and runs and you have fine-tooth combed.

Verify the card reader only, with my or your own smallest sketch.

a7

Gack. Oh well, what I wrote is still worth you going through with you moron switch turned off. :wink:

Add enough printing so you know it works, not that it seems to...

a7

im just heading off to bed for the night.

i do want to note an particular issue i have though, the serial monitor breaks my arduino.

it takes a good 5 minutes for the monitor to load in the first place (and i run a good spec pc) and then it'll freeze once loaded up, then just breaks my arduino, the code i had working, now doesnt respond and will have to unlug the arduino and reload the code to it.

so that monitor, totally annoying for me to use as sometimes it works fine. others it doesnt. not reliable for some reason. (i know, its a me problem)

i have to return my niece to her mothers tomorrow so doubt i'll get much time, but when i can make some time, i will do. thank you again.

#include <Servo.h>
#include <MFRC522.h>
#include <Wire.h>
#include <SPI.h>

MFRC522 mfrc522(10, 9); // MFRC522 mfrc522(SS_PIN, RST_PIN)
Servo fingers;
Servo thumb;
Servo wrist;
int angle = 0;
String tagUID = "9A 71 1C B0"; // String to store UID of tag. Change it with your tag's UID


typedef enum
{
  initialState,
  wantCheckrfid,
  want1,              //Fistclench,
  wantFistrelax,
  want2,              //Thumbsupclench,
  wantThumbsuprelax,
} states;

// state machine variables
states state = initialState;
unsigned long lastStateChange = 0;
unsigned long timeInThisState = 1000;

void setup() {

  Serial.begin(115200);
  Serial.println("stripped of everything! zeroing servos");

  fingers.attach(4);
  thumb.attach(3);
  wrist.attach(2);

  fingers.write(0);
  thumb.write(0);
  wrist.write(0);

  delay(2777);

  //wrist2.attach(10)
  //pinktip.attach(9);
  //pinkybase.attach(8);
  //ringtip.attach(7);
  //ringbase.attach(6);
  //middletip.attach(5);
  //middlebase.attach(4);
  //indextip.attach(3);
  //indexbase.attach(2);
  SPI.begin(); // Init SPI bus
  mfrc522.PCD_Init(); // Init MFRC522
}

void doStateChange ()
{
  lastStateChange = millis ();
  timeInThisState = 1000;
  String tag = "";

  switch (state)
  {
    case initialState:
      state = wantCheckrfid;
      break;

    case wantCheckrfid:

      state = random(2) ? want1 : want2;
      Serial.print("selection");

      timeInThisState = random (1000, 5000);
      break;

    case want1:
      Serial.print("want1: fingers "); Serial.print(120);
      Serial.print(" thumb "); Serial.println(80);
      fingers.write(120);
      thumb.write(80);
      state = wantFistrelax;
      timeInThisState = 2000;
      Serial.print("end want1 ");      
      break;


    case wantFistrelax:
      fingers.write(0);
      thumb.write(0);
      state = wantCheckrfid;
      timeInThisState = 3000;
      Serial.print("end wantfistrelax ");
      break;



    case want2:
      fingers.write(120);
      wrist.write(90);
      state = wantThumbsuprelax;
      timeInThisState = 2000;
      Serial.print("end want2 ");
      break;

      


    case wantThumbsuprelax:
      fingers.write(0);
      wrist.write(0);
      state = wantCheckrfid;
      timeInThisState = 3000;
      Serial.print("end wantthumbuprelax ");
      break;

      

  }
}

void loop() {

  // Look for new cards
      if ( ! mfrc522.PICC_IsNewCardPresent()) {
        return;
      }
      // Select one of the cards
      if ( ! mfrc522.PICC_ReadCardSerial()) {
        return;
      }

      //Reading from the card
String tag = "";
      for (byte i = 0; i < mfrc522.uid.size; i++)
      {
        tag.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
        tag.concat(String(mfrc522.uid.uidByte[i], HEX));
      }
      tag.toUpperCase();

      //Checking the card
      if (tag.substring(1) == tagUID) //change here the UID of the card/cards that you want to give access

      fingers.write(20);
      thumb.write(30);
      delay (200);
      fingers.write(0);
      thumb.write(0);
      Serial.print("endrfid");

  if (millis () - lastStateChange >= timeInThisState)
    doStateChange ();
}

the current frozen code.

and i just noticed. it autosaved after i tried moving the rfid to the bottom section.....well thats screwed that up i guess.

OK THX.

The serial monitor of course should be no problem.

I google-see lotsa company for various kinds of that misery.

At the risk of telling you something you know, try a different USB cable and try your code with no real servos attached.

CU

a7

you know how they say out of sight, out of mind? well im sitting here thinking i only have one of these cables for this arduino, which is plugged into the monitors usb hub....which plugs into my pc via the same cable type as my arduino......want a prat lol.

i got a several hundred mile round trip to do today so if not too tired when i get back, i'll give it a shot and post the results.

not going to lie though, i kind of like the new code more than the case switch method, if i got both sets of code working.....which do you feel would be better? as you have more experience than i do it'll be nice to get that oppinion.

Ok, take the code in #66, and apply the IDE Tools/Auto Format to it.

Then look closely. You are missing a pair of braces.

This

      if (tag.substring(1) == tagUID) //change here the UID of the card/cards that you want to give access
        fingers.write(20);

is a complete if statement...

I like the new position of the RFID stuff, but you've boxed yourself out a bit it seems, as it messes up your switch/case

In the original switch/case, the machine would stay in state wantCheckrfid until a new card was seen, and

uh oh, it looks like you' may have had a missing pair of braces from the very beginning.

Let's assume that wantCheckrfid should not exit until and unless it gets a new. valid card. It then does some reaction and moves to either want1 or want2.

Now with your new arrangment, wantCheckrfid, now misnamed BTW, will always go to want1 or want2, without regard to any RFID.

The new placement of the RFID is OK, but it should not do any servo stuff. Rather it could, perhaps, raise a flag meaning "new valid card seen", and then, in wantCheckrfid, you could use that flag to control exiting that state.

So I am turning it back to you. I can't know what you want this sketch to do, but I can tell you that it will do what you write.

Here is your code, with your errors fixed, and my idea inserted. I can only verify this - it compiles and I believe it comes closer to how you want it to work.

#include <Servo.h>
#include <MFRC522.h>
#include <Wire.h>
#include <SPI.h>

MFRC522 mfrc522(10, 9); // MFRC522 mfrc522(SS_PIN, RST_PIN)
Servo fingers;
Servo thumb;
Servo wrist;
int angle = 0;
String tagUID = "9A 71 1C B0"; // String to store UID of tag. Change it with your tag's UID

unsigned char validCardSeen = 0;	// we haven't. seen a valid card.

typedef enum
{
  initialState,
  wantCheckrfid,
  want1,              //Fistclench,
  wantFistrelax,
  want2,              //Thumbsupclench,
  wantThumbsuprelax,
} states;

// state machine variables
states state = initialState;
unsigned long lastStateChange = 0;
unsigned long timeInThisState = 1000;

void setup() {

  Serial.begin(115200);
  Serial.println("stripped of everything! zeroing servos");

  fingers.attach(4);
  thumb.attach(3);
  wrist.attach(2);

  fingers.write(0);
  thumb.write(0);
  wrist.write(0);

  delay(777);

  //wrist2.attach(10)
  //pinktip.attach(9);
  //pinkybase.attach(8);
  //ringtip.attach(7);
  //ringbase.attach(6);
  //middletip.attach(5);
  //middlebase.attach(4);
  //indextip.attach(3);
  //indexbase.attach(2);
  SPI.begin(); // Init SPI bus
  mfrc522.PCD_Init(); // Init MFRC522
}

void doStateChange ()
{
  lastStateChange = millis ();
  timeInThisState = 1000;
  String tag = "";

  switch (state)
  {
    case initialState:
      state = wantCheckrfid;
      break;

    case wantCheckrfid:
      if (validCardSeen) {
        fingers.write(20);
        thumb.write(30);
        delay (200);
        fingers.write(0);
        thumb.write(0);
        Serial.print("endrfid");

        state = random(2) ? want1 : want2;
        Serial.print("selection");

        timeInThisState = random (1000, 5000);

        validCardSeen = 0; // we acted on this card, so don't again.
      }
      else		// remove this clause when you are tired of the spam on the serial monitor
        Serial.println("waiting on seeing a valid card!");

      break;

    case want1:
      Serial.print("want1: fingers "); Serial.print(120);
      Serial.print(" thumb "); Serial.println(80);
      fingers.write(120);
      thumb.write(80);
      state = wantFistrelax;
      timeInThisState = 2000;
      Serial.print("end want1 ");
      break;

    case wantFistrelax:
      fingers.write(0);
      thumb.write(0);
      state = wantCheckrfid;
      timeInThisState = 3000;
      Serial.print("end wantfistrelax ");
      break;

    case want2:
      fingers.write(120);
      wrist.write(90);
      state = wantThumbsuprelax;
      timeInThisState = 2000;
      Serial.print("end want2 ");
      break;

    case wantThumbsuprelax:
      fingers.write(0);
      wrist.write(0);
      state = wantCheckrfid;
      timeInThisState = 3000;
      Serial.print("end wantthumbuprelax ");
      break;
  }
}

void loop() {
  String tag = "";

  if ( ! mfrc522.PICC_IsNewCardPresent()) {  // Look for new cards
    return;
  }

  if ( ! mfrc522.PICC_ReadCardSerial()) {    // Select one of the cards
    return;
  }

  //Read from the card

  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
    tag.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
    tag.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  tag.toUpperCase();

  if (tag.substring(1) == tagUID) //Checking the card
  {
    validCardSeen = 1;            // did. we saw it. inform the machine.
  }
  else {
    Serial.println("card seen, but not validated.");
  }


  if (millis () - lastStateChange >= timeInThisState)
    doStateChange ();
}

Please read the code carefully. Search for "validCardSeen" to see how I fixed your logic. Also search for "Serial.print", as I try to use those to tell the story. I don't much care for comments (!), but those too should assist your reading.

  • Get the serial monitor issue sorted. Independently. It is a separate issue and will only make life hard if you let it continue to get in the way.

  • Do your initial testing of this with no real servos.

HTH - we here whenever. Just stay (or get calm) and think it through. All 100 percent logical.

a7

So im in london at the moment so cant do a big heavy reply however the principle is the code controls a robotic arm on a stand, the rfid tag is in another device.

The code needs to constantly be looking for that frid tag and make the hand "twitch" anytime its in close promixity. But at rabdom intervals it will make either a fist or a thumbs up.

Thats the short and sweet of what this codes intended to do. I cant believe those brackets where missing though. I guess too much time stsring at the screen trying to work out what was wrong with it.

Ill give your modified code a try tonight when i finally get back home and see what happens, and keep the new version i wrote as a backup project. Which ill likely finish as been having a bit of fun with the new one.

And once more, i thsnk you for your help and patients with me, and my code.

i cant get the serial monitor to work properly. dont know why.

i loaded up the code and tried it, nothing happens on rfid contact and servos arent moving under the case switches either.

honestly i think its time to ditch this code and go with the second one i wrote. its not working and can spend weeks tinkering with it and get no where.

well now im not going anything

An error occurred while uploading the sketch
avrdude: ser_open(): can't set com-state for "\\.\COM9"

reinstalled arduino ide.

this code does what i want it to do, however im unsure how to break the fist section into a seperate part.

essentially it operates correctly, but the fist part of it only activates after the rfid has been detected. (i need to make it repeat at random intervals after getting that part working independantly of the rfid section)

also after a certain amount of time the code seems to stop running entirely. even hitting the reset button doesnt get it functioning again nor does unplugging the arduino and plugging it back in

 #include <Wire.h>
#include <SPI.h>
#include <Servo.h>
#include <MFRC522.h>

MFRC522 mfrc522(10, 9); // MFRC522 mfrc522(SS_PIN, RST_PIN)
Servo myservo;
int angle = 0;
String tagUID = "9A 71 1C B0"; // String to store UID of tag. Change it with your tag's UID
const unsigned long fist = 10000;
const unsigned long thumb = 15000;


void setup() {
  Serial.begin(115200);
  Serial.println("start setup");
  myservo.attach(6);
  SPI.begin(); // Init SPI bus
  mfrc522.PCD_Init(); // Init MFRC522
  myservo.write(0);
  Serial.println("setup complete");

}
void loop() {

  Serial.println("look for new cards");
  if ( ! mfrc522.PICC_IsNewCardPresent()) {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial()) {
    return;
  }

  Serial.println("reading from card");
  String tag = "";
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
    tag.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
    tag.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  tag.toUpperCase();

  Serial.println("checking the card");
  if (tag.substring(1) == tagUID) //change here the UID of the card/cards that you want to give access
  {
    Serial.println("if match novement here");
    if (angle < 90) {
      myservo.write(90);
    }
    else
    { myservo.write(45);
    }
    delay(200);
    myservo.write(0);
    delay(3000);
    
  }

  
//fist section


  {
  Serial.println("checking millis for fist");
  if ( millis() > fist) {
    myservo.write(0);
    delay (200);
    myservo.write(130);
  delay(2000);
    myservo.write(0);
  }
  }

}

I'm burnt and less than fully able.

I cannot give this any more attention until you assure me that you are now working with, and talking about, the code you posted in #73 just now.

It is completely different to where you started, and at a glance cannot possibly be doing anything like what you need or want.

Just wanna be sure you haven't inadvertently posted something that isn't, isn't what you are claiming kinda almost does what you want except when it doesn't.

a7

i am talking about the code in 73.

it worked, but now isnt. so i dont know what the hell is going on. i would place the rfid near the reader, it would move the servo, then 10 seconds later it would move under the fist section.

its also the code posted in 62

it is completely different as the original code wasnt working. i loaded up what you posted and got no responce from the arduino.

That is very vague and again, taken literally, impossible. Unless you are still with problems that have nothing to do with any code or servos, like your IDE serial terminal woes.

The code in #73, if it is running correctly, won't be doing much of interest.

angle is initialised to 0, and never changed, so this

    if (angle < 90) {
      myservo.write(90);
    }
    else
    { myservo.write(45);
    }

Is the same as this
   myservo.write(90);

fist initialised to 10000 and never changed, so this

 {
  Serial.println("checking millis for fist");
  if ( millis() > fist) {
    myservo.write(0);
    delay (200);
    myservo.write(130);
  delay(2000);
    myservo.write(0);
  }
  }

will do nothing for the first ten seconds after reset or power up, and then, for the rest of eternity, move the servo to 0 and block any other activity for 0.2 seconds, then move the servo to 130 and block any other activity for 2 seconds.

So nothing else in your loop() gets much of a chance to do anything. Most of the time it will be finding itself in the delay() function.

If a valid card is seen, assuming you got that code right, then in between those 2.2 second lapses of attention the servo will wag to 90 for 0.2 seconds, then go back to 0 for 3 seconds, and then the fist thing will resume its 2.2 second routine. If we past 10 seconds into the run.

Nowhere in the "new" old version are you doing anything like you started off asking us to help you with, the "state change random feature".

The last thing I will do is take my version of your "frozen" code, remove the RFID stuff as I did very many posts ago and demonstrate that it functions per your original idea, or fix it if it does not and post it, fixed.

I will not add what seems to be a new recent requirement, that in the absence of RFID valid card recognition you want to do want1 or want2 after some random time.

If that was your desire all along, I missed that as it did not appear to be something you were even trying to do originally.

I can only suggest that you step back from what appears to be a bit ambitious for your current level of programming ability. Start with much simpler programs until you can read and write a bit better. There is nothing inherently complex about what you are up to, but the combination of the elements seems to have overwhelmed you.

Read on these fora, try to follow along with what kind of problems people have and how they arrive at solutions to them. Read read read code, google stuff you don't understand, ask questions. Cobbling together sketches from bits and pieces with minimal understanding of how they work will only get you so far, as you may be realizing.

At least you now know how to use Serial.print to help you see what your code is up to. :expressionless:

Once you get that serial monitor / IDE issue sorted, that is.

a7

OK I did make a few changes. But nothing that made it go from "no responce from the arduino" to running the servos quite a bit. No specific show stopper error.

Mostly I added print statements, and a bit of logic so a new card wouldn't mess up any reaction to a valid card that was in progress.

Take the link, run the code. Downloaded, it should behave identically in real life. I remind you that the RFID stuff is all faked, but structurally present and imitated by random results of the tests and data reading.


I don't see why adding back the real RFID stuff should break anything. I am at a disadvantage as I have no RFID reader and cards, so that's where the copious serial printing should let you confirm that the flow is identical to the simulated randomised proxy in my code.

a7

id rather stick with the case statement code, the original one, but as i said, when i put it on the arduino it doesnt do anything, theres no reaction from the arduino at all.

i cannot rely on using the serial print to check anything as it is unreliable, using different usb cables and ports doesnt resolve that problem.

i put your code on the arduino, with the rfid and a single servo hooked up and literally it didnt do anything at all. i cant add more detail than that because there isnt anymore to give sadly

i will try it again tho

    validCardSeen = 0; // we acted on this card, so don't again.

that line, wouldnt that prevent it from reading the same rfid until the arduino is completely reset though? cause that would be bad.

also i dont have a choice but to get this project working so trying easier codes isnt an option. and honestly, its just combining 2 working codes that are verified as working so it shouldnt be this much of a problem. yet it is being

C:\Users\ryder\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.4\cores\arduino\new.cpp: In function 'void* operator new(std::size_t, std::nothrow_t)':
C:\Users\ryder\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.4\cores\arduino\new.cpp:59:60: warning: unused parameter 'tag' [-Wunused-parameter]
 void * operator new(std::size_t size, const std::nothrow_t tag) noexcept {
                                                            ^~~
C:\Users\ryder\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.4\cores\arduino\new.cpp: In function 'void* operator new [](std::size_t, const std::nothrow_t&)':
C:\Users\ryder\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.4\cores\arduino\new.cpp:68:63: warning: unused parameter 'tag' [-Wunused-parameter]
 void * operator new[](std::size_t size, const std::nothrow_t& tag) noexcept {
                                                               ^~~
C:\Users\ryder\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.4\cores\arduino\new.cpp: In function 'void operator delete(void*, const std::nothrow_t&)':
C:\Users\ryder\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.4\cores\arduino\new.cpp:103:55: warning: unused parameter 'tag' [-Wunused-parameter]
 void operator delete(void* ptr, const std::nothrow_t& tag) noexcept {
                                                       ^~~
C:\Users\ryder\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.4\cores\arduino\new.cpp: In function 'void operator delete [](void*, const std::nothrow_t&)':
C:\Users\ryder\Documents\ArduinoData\packages\arduino\hardware\avr\1.8.4\cores\arduino\new.cpp:106:57: warning: unused parameter 'tag' [-Wunused-parameter]
 void operator delete[](void* ptr, const std::nothrow_t& tag) noexcept {
                                                         ^~~

is this anything to worry about?

also im going to order a new arduino, i got this one off ebay like 3 years ago and not entirely sure its a genuine one. so going to order from arduino themselfs a shiney new uno R3 (unless you can recommend a better one, given i rarely ever max out all the pins on an uno, also that isnt going to break the bank) so i'll carry on working with this one until that arrives.

this project is a priority and vitally important as failing would mean breaking a promise to someone very dear

No, because

  if (tag.substring(1) == tagUID) //Checking the card
  {
    validCardSeen = 1;            // did. we saw it. inform the machine.
  }

validCardSeen is called a flag. When we see a valid card, we set the flag.

Elsewhere, when we see that flag set, we act, then clear the flag. That resets the mechanism that makes something happen once each time a valid ID is scanned.

But srsly, you are wasting your time if you don't have a rock solid development environment. It's like trying to drain a swamp when you are up to your ears in alligators.

I'm out until you can state with confidence that you are on solid ground, and that your problems are truly related to code and not the eleven other things that can impede progress, drive a person or two crazy and put things in danger of being thrown through a window.

Trust me, we all been there. First things first.

You did not comment on my observations about your smaller version, I hope you see that it was just not doing anything because it was what you meant. The errors you made should be something you can learn from, at least by understanding why you were seeing what you did.

a7