Go Down

Topic: Unable to make LED light when RFID is read (Read 1 time) previous topic - next topic


I've got some code from someone else to finally read tags and do an action based on what tag is read however no mater what i do when i put an RGB LED in the mix to light up a certain color based on the tag (just adding one line of code to light up a pin) it doesn't work for shit. when i hook it up the LED is ALWAYS on. Please tell me where im messing up.
Code: [Select]
int  val = 0;
char code[12];
int bytesread = 0;
char tagArray[12];     // the array for the tags
char Devin[12] = {'0', '4', '1', '5', 'D', '8', 'B', '3', '0', '4'};
char Paige[12] = {'0', 'F', '0', '3', '0', '4', '0', 'D', 'E', '4'};
int RedLED=4;
int GreenLED=5;
int BlueLED=6;

void setup() {

Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
pinMode(2,OUTPUT);   // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(2, LOW);                  // Activate the RFID reader

void loop() {

  if(Serial.available() > 0) {          // if data available from reader
    if((val = Serial.read()) == 10) {   // check for header
      bytesread = 0;
      while(bytesread<10) {              // read 10 digit code
        if( Serial.available() > 0) {
          val = Serial.read();
          if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
            break;                       // stop reading
          code[bytesread] = val;         // add the digit           
          bytesread++;                   // ready to read next digit 

      if(bytesread == 10) {              // if 10 digit read is complete
        Serial.print("TAG code is: ");   // possibly a good TAG
        Serial.println(code);     // print the TAG code         
        if(strcmp(code,Devin) == 0) {   
          Serial.println("Devin, you're in");
          digitalWrite(GreenLED, HIGH);
              if(strcmp(code,Paige) == 0) {   
          Serial.println("Paige, you're in");
          digitalWrite(GreenLED, HIGH);
          if ((strcmp(code,Devin) !=0) && (strcmp(code,Paige)!=0)){
          Serial.println("Illegal attempted entry");
          digitalWrite (RedLED,HIGH);
      bytesread = 0;
           delay(3000);                       // wait for a second

// extra stuff
// digitalWrite(2, HIGH);             // deactivate RFID reader


Is it a common cathode RGB LED? Is there a resistor in each of the anodes, not just one in the cathode?
How have you got it wired up?
Can you just flash it with another sketch, in other words are you sure it is a software fault?


To my knowledge i have it wired up correctly. it has a common anode that i have grounded, and the cathodes are connected to the pins. when i have only the pin 5 wire connected its constantly green. a friend says i have to have it wired wrong but unless breadboards have changed since 2 yrs ago when i took ac/dc classes then things are hooked up correctly.


that is one of 3 sites i checked for diagrams and i am doing all of them correctly to my knowledge. im using 330 ohm resistor. is it because i only have the green led connected right now? do the other leds have to have a connection for this to work correctly even though i'm only testing the green led now?


If it is truly a common anode then the anode should be connected to +5 and the cathode through a resistor to the arduino pin. Then a digital write low will turn on the LED and writing high will turn it off.

Go Up