Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: RFID and LEDs - Help with code? on: January 17, 2013, 06:55:57 am
Haa.

I'm trying to do what you said and just take it a one step at a time rather than jumping into the deep end of RFID'ing all at once.

Code:
int redLed = 11;
int greenLed = 10;
int blueLed = 9;

long randNumb;;

void setup()
{
 pinMode(redLed, OUTPUT);
 pinMode(greenLed, OUTPUT);
 pinMode(blueLed, OUTPUT);
 randomSeed(analogRead(0));
}

void red()
{
 analogWrite(redLed, 255);
 analogWrite(greenLed, 0);
 analogWrite(blueLed, 0);  
}  

void green()
{
 analogWrite(redLed, 0);
 analogWrite(greenLed, 255);
 analogWrite(blueLed, 0);  
}  

void blue()
{
 analogWrite(redLed, 0);
 analogWrite(greenLed, 0);
 analogWrite(blueLed, 255);  
}  

void loop()
{
 randNumb = random(1, 4);
 
 if(randNumb == 1){
  red();
 }  
 if(randNumb == 2){
  green();
 }
 if(randNumb == 3){
  blue();
 }
}

Thanks.
2  Using Arduino / Programming Questions / Re: RFID and LEDs - Help with code? on: January 16, 2013, 07:11:31 pm
I think I should be banned from Arduino and anything to do with code.

I can't even get the Arduino to select red or blue at random through the RGB LED.


3  Using Arduino / Programming Questions / Re: RFID and LEDs - Help with code? on: January 13, 2013, 02:42:42 pm
Thanks.

I can get the LED to turn red no problem - or any other colour for that matter. It becomes a problem when RFID comes into the equation. I'll have a look at the functions you said.

Thank you.
4  Using Arduino / Programming Questions / Re: RFID and LEDs - Help with code? on: January 13, 2013, 12:49:53 pm
Thanks for the reply PaulS.

Quote
What do you think this is doing? It isn't, but we need to know what you think it should do in order to tell you how to "Make it so!".

I thought it said, if the selected colour is red then once tag 1 is read it will turn it off. But after looking back over it, it is just mush!
5  Using Arduino / Programming Questions / Re: RFID and LEDs - Help with code? on: January 13, 2013, 11:01:06 am
Hello - apologises for the confusion and lack of posting.

Quote
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:
Quote
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:
Code:
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!


6  Using Arduino / Programming Questions / Re: RFID and LEDs - Help with code? on: January 11, 2013, 09:24:34 am
Once again, thanks for the replies.

I've gotten this code which I was able to get working with a single LED but when i'm not sure how to get it working with my piranha RGB LED.

Code:
int redPin = 11;
int greenPin = 10;
int bluePin = 9;
int RFID = 0;

//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(){

  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
  resetReader(); //eset the RFID reader
}

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
    turnoffLED(2);

  }else if(compareTag(tag, tag2)){ //if matched tag2, do this
    turnoffLED(3);


  }else{
    Serial.println(tag); //read out any unknown tag
  }

}

void turnoffLED(int pin){

//Turn on LED on pin "pin" for 250ms

  digitalWrite(pin, LOW);
  delay(1000);
  digitalWrite(pin, HIGH);
}

void resetReader(){  // Reset the RFID reader to read again

  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
}


So what I would like to happen is both of the tags will be set up to match with each one of the LED colours.

Then one of the two colours (red (RGB 255, 255, 0) or blue (RGB 0, 255, 255) will turn on at a random and then you put the RFID tag on which will turn on and then it will restart and another colour will come at random. For example if the colour red came on and then it was linked to tag 1, then you would need to place that tag on and then the LED will turn.

I'm hoping this does not sound too confusing and would be gratefully for help. also I am new to Arduino, can you tell? lol.

Cheers!
7  Using Arduino / Programming Questions / Re: RFID and LEDs - Help with code? on: January 10, 2013, 06:07:36 pm
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.
8  Using Arduino / Programming Questions / RFID and LEDs - Help with code? on: January 10, 2013, 12:05:46 pm
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:
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:
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!
9  Using Arduino / Project Guidance / Project - Arduino to know the difference between 2 objects on: November 09, 2012, 08:25:21 am
Hello,

I need help deciding which sensor would do the job. The problem is I am doing a project with a Arduino Uno what is 'acting' like a desktop pet where I have 2 LEDs which notify the user that if one goes off it wants some food and the other if it wants a drink. I have made 2 small physical objects that will act as the food and water. And when you press them against the device the LEDs will go off.

Is there a sensor or something that will know the difference between each object? I was thinking of using a RFID reader and placing the tags into the 2 objects. Will this work, and/or is there another way I can do this?

Sorry if it sounds confusing.

Thanks!
Pages: [1]