Hello - apologises for the confusion and lack of posting.
That code does something. What does it do? Does it turn the LED on or off?
That code in post 7 I got working through just one normal LED. so that when you scan a RFID tag it turned the LED on. I tried to change it to work with my RGB LED and to do the opposite so the LED is always on but when you scan the tag the LED goes off but I'm struggling a tad.
As ash901226 as correctly said this is what I have managed to do so far:
manage to read the RFID and transmit the value to computer via serial.
however i think that he is unable to use the data to read and set the necessary action when the RFID card had been scan
Right now, what I am trying to do is with the RGB Led and the RFID reader is:
I have the colours red and blue on my RGB LED,
I want to match tag 1 (67005DC651AD) with red and tag 2 (67005DB143C8) with blue.
I want this to happen by the Arduino randomly selecting one of those two colours to come on and then when you scan the right tag, the LED will turn off.
Then it select one of the two colours again to go back on after 10 seconds.
At this present moment I found some code and added some bits in to make this but this doesn't seem to work:
int redPin = 11;
int greenPin = 10;
int bluePin = 9;
int RFID = 0;
int red = 0;
int green = 0;
int blue = 0;
int randomVal;
byte colours[3][3] = {
// three colours 0-3, and
// each has three components 0-2 for red, green, blue
255, 0, 0, // red
0, 0, 255, // blue
0, 255, 0, // green
};
//Register your RFID tags here
char tag1[13] = "67005DC651AD";
char tag2[13] = "67005DB143C8";
void setup(){
Serial.begin(9600);
pinMode(RFID, OUTPUT);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop(){
randomSeed(analogRead(0));
char tagString[13];
int index = 0;
boolean reading = false;
while(Serial.available()){
int readByte = Serial.read(); //read next available byte
if(readByte == 2) reading = true; //begining of tag
if(readByte == 3) reading = false; //end of tag
if(reading && readByte != 2 && readByte != 10 && readByte != 13){
//store the tag
tagString[index] = readByte;
index ++;
}
}
checkTag(tagString); //Check if it is a match
clearTag(tagString); //Clear the char of all value
}
void checkTag(char tag[]){ //Check the read tag against known tags
if(strlen(tag) == 0) return; //empty, no need to contunue
if(compareTag(tag, tag1)){ // if matched tag1, do this
red;
if (red = LOW);
{
}if(compareTag(tag, tag2)){ //if matched tag2, do this
blue;
if (blue = LOW);
}else{
Serial.println(tag); //read out any unknown tag
}
}
digitalWrite(RFID, LOW);
digitalWrite(RFID, HIGH);
delay(150);
}
void clearTag(char one[]){
//clear the char array by filling with null - ASCII 0
//Will think same tag has been read otherwise
for(int i = 0; i < strlen(one); i++){
one[i] = 0;
}
}
boolean compareTag(char one[], char two[]){
//compare two value to see if same,
//strcmp not working 100% so we do this
if(strlen(one) == 0) return false; //empty
for(int i = 0; i < 12; i++){
if(one[i] != two[i]) return false;
}
return true; //no mismatches
}
void chooseColour() {
int randomVal = random(0, 2); // Choose a random value, 0-2
byte red = colours[randomVal][0];
byte blue = colours[randomVal][1];
byte green = colours[randomVal][2];
analogWrite(redPin, red);
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
delay(1000);
}
Cheers everyone!