Go Down

Topic: RFID and LEDs - Help with code? (Read 1 time) previous topic - next topic

ch_91

Hello,
I'm a Arduino Uno with a ID-12 RFID reader (with two tags) and a piranha RGB LED. What I'm trying to achieve is when the RGB LED turns one colour (e.g. red) you swipe the tag and it turns the LED off. I want this to happen with another colour (blue) and the other tag also.

So far I have set everything up and I've got the tags reading with the RFID with this code:

Code: [Select]
char val = 0; // variable to store the data from the serial port

void setup() {
Serial.begin(9600); // connect to the serial port
}

void loop () {
// read the serial port
if(Serial.available() > 0) {
val = Serial.read();
Serial.write(val); //sends as char
}
}


The two tag ID's are: 67005DC651AD and 67005DB143C8

I have also for my piranha LED lighting up the colours I need. With this code:

Code: [Select]
int redPin = 11;
int greenPin = 10;
int bluePin = 9;

void setup()
{
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT); 
}

void loop()
{
  setColor(255, 255, 0);  // red
  delay(1000);
  setColor(0, 255, 255);  // blue
  delay(1000);
}

void setColor(int red, int green, int blue)
{
  analogWrite(redPin, red);
  analogWrite(greenPin, green);
  analogWrite(bluePin, blue); 
}


The problem is I don't know where to start with putting the codes together to get them to do want I want. Could somebody please offer me some assistance?

Thanks and have a good day!

ash901226

ouh this is some of my humblest of opinion. if you can make it read the rfid why not just use it as a switch case
maybe like switch (val)
case (*) insert the first adress
then do something
break
case(*) insert the second adress
then do something
break.
btw could you explain again what your program suppose to do? couse there is some part that i cant understand like
Quote
What I'm trying to achieve is when the RGB LED turns one colour (e.g. red) you swipe the tag and it turns the LED off. I want this to happen with another colour (blue) and the other tag also.


could you explain more what does that suppose to mean?

Arrch

#2
Jan 10, 2013, 06:41 pm Last Edit: Jan 10, 2013, 06:43 pm by Arrch Reason: 1
Start by saving the RFID strings in to a char array, rather than writing them to the Serial monitor. You'll need a char array big enough to hold the IDs plus 1 for the null terminator, an index variable that keeps track of where you are in the array, and someway to determine when you've received the last char.

ch_91

Quote
What I'm trying to achieve is when the RGB LED turns one colour (e.g. red) you swipe the tag and it turns the LED off. I want this to happen with another colour (blue) and the other tag also.

could you explain more what does that suppose to mean?


ash901226 - What I mean is that I would like there to be two colours that will come on randomly that will notify the user to put the RFID tag on the reader. For example, I want a red LED to come on through the piranha and when the LED comes on, you place the RFID tag on and then it turns the LED off.

I want this to happen with another colour through the piranha LED and another RFID tag also. So there is 2 different coloured LEDS and 2 RIFD tags.

Sorry if it is a bit confusing.

Quote
Start by saving the RFID strings in to a char array, rather than writing them to the Serial monitor. You'll need a char array big enough to hold the IDs plus 1 for the null terminator, an index variable that keeps track of where you are in the array, and someway to determine when you've received the last char.


Thanks Arrch for the reply. How would I go about doing this, if you don't mind talking more in-depth about this?

Cheers.

ash901226


Go Up