Go Down

Topic: Arduino,rfid,serial lcd and bluetooth... (Read 1 time) previous topic - next topic

ishben

Hola que tal ,siendo este mi primer post primero que nada quiero agradecer por la oportunidad de usar este foro,paso alo siguiente tengo un projecto en mente que se lo estoy agregando a mi carro este consta como menciono en el titulo del post arduino,rfid,serial lcd y modulo de bluetooth tengo los sketches del arduino uno para el rfid y el otro para el modulo de bluetooth que trabaja como "standalone" , y les pido su ayuda como buen novato que soy para integrar los dos sketches en uno solo para que pueda abrir mi carro atravez de "rfid tags" y via "bluetooth pass".
"ACLARO LOS SKETCHES LOS ENCONTRE COMO DOMINIO PUBLICO Y CREDITOS AQUIEN CORRESPONDA"
esto es lo que tengo:

#include <SoftwareSerial.h>
SoftwareSerial BtSerial (5,7);
int lock = 8;          //pin 8 on Arduino
char final[4];         //Characters the Arduino will receive
char correct[4] = {'1','2','3','4'};    //User-Defined Password
int pass_correct = 0;          //Does Password match, 0=false 1=true

void setup()
{
  BtSerial.begin(9600);

  pinMode(lock, OUTPUT);
Serial.begin(9600);
digitalWrite(lock, HIGH);  //By default, lock is active(locked)
}
void loop(){
bluetooth ();

}
void bluetooth (){
  while(BtSerial.available())
{
  for(int i=0; i<4; i++)   //While data is available read 4 bytes
  {
   final = BtSerial.read();  //Read 4 bytes into the array labled "final"
  }
for(int i=0; i<4; i++)
  {
   if(final==correct) //Compare each char received to each car in our password in order
   {
    pass_correct = 1;   //If we compare two chars and they match, set the pass_correct variable to true(1)
   }
   else
   {
    pass_correct = 0;  //if the two compared chars do NOT match, set pass_correct variable to false(0)
    break;   //End loop and stop comparing chars
   }
  }
}

if(pass_correct==1)  //If all chars compared match, deactivate(unlock) the lock for 5 seconds
{
  BtSerial.println("Unlocked");
  digitalWrite(lock, LOW);
  delay(5000);
  BtSerial.println("Locked");
  pass_correct = 0;
}
else
{
digitalWrite(lock, HIGH); //Else if there was not a complete match, keep the lock high(locked)
}
delay(500);





Y me gustaria incorporarlos en un solo sketch gracias por su ayuda .



ishben

Esta es la continuacion del post de arriba este es lo del rfid:

#define NumberOfKeys  10  //This defines the amount of keys in the access list
#define WAIT_TIME 2000     //Time door will remain open
#define BLINKS 3               //The amount of times the indicators blink when blinking is required
#define ON_TIME 200         //time in milliseconds the relay stays energized
const int TxPin = 7; //FOR PARALLAX SERIAL LCD and we use rx in the arduino for SEROUT from RFID module

#include <SoftwareSerial.h>
SoftwareSerial mySerial = SoftwareSerial(255, TxPin); //FOR SERIAL LCD

//External Equipment
#define ENABLE 2               //Pin connected to the Enable pin of RFID parallax
#define LOCK 9                  //Pin that is connected to NPN transistor that energizes lock

//LED Indicators
#define OPEN_LIGHT 11              //LED indicator. Indicates the correct key was entered
#define DENIED_LIGHT 12          //LED indicator. Indicates the wrong key was entered
#define PROGRAMMING_LIGHT 13 //LED indicator. Indicates Programming mode is activated

int     val = 0;
int     bytesread = 0;
String  Master = "123456789";  //"PERSONAL RFID CARD NUMBER"
String  empty = "0000000000";
String  keyCode;
String  accessList[NumberOfKeys];
char    code[10];
boolean programmingMode,isInAccessList,KeyFound = false;

void setup() {
pinMode(OPEN_LIGHT,OUTPUT);
pinMode(DENIED_LIGHT,OUTPUT);
pinMode(PROGRAMMING_LIGHT,OUTPUT);
pinMode(ENABLE,OUTPUT);
pinMode(LOCK,OUTPUT);

//Generates an array of size corresponding to the size of the access list
for(int i = 0;i<NumberOfKeys;i++){
 accessList = empty;
}

Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
digitalWrite(OPEN_LIGHT,LOW);
digitalWrite(DENIED_LIGHT,LOW);
digitalWrite(PROGRAMMING_LIGHT,LOW);
digitalWrite(ENABLE, LOW);                  // LOW Activates the RFID reader, HIGH deactivates it
digitalWrite(LOCK,LOW);
pinMode(TxPin, OUTPUT);
digitalWrite(TxPin, HIGH);
 

/////////////////////////////FOR PARALLAX SERIAL LCD ///////////////////////////////////////
 mySerial.begin(9600);
 delay(100);
  mySerial.write(12);           // Clear            
  mySerial.write(17);           // Turn backlight on
 delay(5);                           // Required delay
mySerial.print("CHECKING SYSTEM");  // First line
 mySerial.write(13);                //LET'S GO THE NEXT LINE
 mySerial.print("  CALIBRATING");   //SECOND LINE
  mySerial.write(212);          // Quarter note
  mySerial.write(220);          // A tone
  delay(3000);                 //LET'S WAIT FOR THE MESSAGE ON THE LCD DISPLAY
 mySerial.write(12);   //LET'S CLEAN UP THE DISPLAY
mySerial.write(18);    //LET'S TURN OFF THE LCD BACKLIGHT
delay(5);            //REQUIRES THIS DELAY
}  


void loop() {
  /**** EXTRACTION OF DATA FROM CARD ****/
 if(Serial.available() > 0) {            // if data available from reader
   if((val = Serial.read()) == 10) {   // check for header [Header of data = 10]
     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
     digitalWrite(ENABLE, HIGH);        // deactivate the RFID reader for a moment so it will not flood
      keyCode = code;
      keyCode = keyCode.substring(0,10);
      /*** INTERPRETATION OF DATA ***/
      //At this point, data was read, and there is a keycode in the keyCode variable      
      if((keyCode == Master) && (programmingMode == false))
      {programmingMode = true;
       digitalWrite(PROGRAMMING_LIGHT,HIGH);
    mySerial.print("  SETUP READY");
   mySerial.write(13);
 mySerial.print(" ADD OR DELETE");
 mySerial.write(17);
}
      else
      {if(programmingMode == false)
     
      {
         for(int i = 0;i<NumberOfKeys;i++)  //check entered key against saved keys
         {
            if(keyCode.equals(accessList)){
               KeyFound = true;}                  //if the key is in the access list, KeyFound = true;
         }
         if(KeyFound)
         {
           accessGranted();
           KeyFound = false;
         }
         else{
           accessDenied();
     
       }
     }
     else if(programmingMode)
     {
       if(keyCode.equals(Master)){  //Master Key swipped during programming mode
       }else
       {
        isInAccessList = false;               //this is an initialization value, if the key is in the access list, this variable will be true later.        
         for(int i = 0;i< NumberOfKeys;i++)   //Scans Access List
           {if(keyCode.equals(accessList)) //if the card read is in the Access List
              {
               accessList = empty;         //delete it
               isInAccessList = true;         //isInAccessList set to true, meaning the key was in the access list
               keyDeleted();
            mySerial.print("  A CARD JUST ");  
            mySerial.write(13);  
            mySerial.print("  BEEN DELETED");
            mySerial.write(17);
          }
           }
          if(isInAccessList == false)             //if the key swipped is not in the access list and...
          {
             for(int i = 0;i< NumberOfKeys;i++){
               if(accessList.equals(empty))    //...if current Access List Slot is Empty
               {accessList = keyCode;          //Enter Key into Access List Slot
               newKeyEntered();
                mySerial.print("  A CARD JUST ");  
            mySerial.write(13);  
            mySerial.print("  BEEN ADDED");
            mySerial.write(17);
                break;
                }  
               if(i == (NumberOfKeys - 1))       //if you get to this point at last interation of loop, access List is full
                   listFull();              
             }
          }
       }
       
       digitalWrite(PROGRAMMING_LIGHT,LOW);
   
       programmingMode = false;                   //Programming is done, turn programming mode and indicator off

 }
      }
      resetIndicators();

 }    //end of data reading

 }
}
}

/*** CLEARS DATA FROM BUFFERS TO AVOID DOUBLE READS***/
void flushBuffers(){
  while(Serial.available() > 0)          //if there is still data remaining in the RFID reader buffer
      Serial.read();                         //read it into arduino buffer
  Serial.flush();                             //then flush it
}

/*** RESETTING INDICATORS ***/
void resetIndicators(){
     
     delay(WAIT_TIME);                 //wait a little
     flushBuffers();                       //clear buffers
     
     digitalWrite(LOCK,LOW);              //return everything to starting position
     digitalWrite(OPEN_LIGHT,LOW);
     digitalWrite(DENIED_LIGHT,LOW);
     digitalWrite(ENABLE,LOW);
  mySerial.write(12);
   mySerial.write(18);
}







ishben

esta es la continuacion del rfid sketch :


/*** BEHAVIOR OF LED INDICATORS IF A KEY IN THE ACCESS LIST IS SWIPPED ***/
void accessGranted(){
  mySerial.print("     WELCOME");  // First line
  mySerial.write(13);
  mySerial.print("      HOME");
  mySerial.write(17);
  digitalWrite(OPEN_LIGHT,HIGH);
  digitalWrite(LOCK,HIGH);//Sends 5V to transistor to energize door lock
  delay(ON_TIME);            //Relay stays energized for ON_TIME milliseconds
  digitalWrite(LOCK,LOW); //Immediately after delay, de-energize door.
}
/*** BEHAVIOR OF LED INDICATORS IF A KEY THAT'S NOT IN THE ACCESS LIST IS SWIPPED ***/
void accessDenied(){
  digitalWrite(DENIED_LIGHT,HIGH);
  digitalWrite(LOCK,LOW);
mySerial.print(" WHO ARE YOU ??");  // First line
  mySerial.write(13);
  mySerial.print(" !!!STRANGER!!!");
  mySerial.write(17);
}

/*** BEHAVIOR OF LED INDICATORS IF A NEW KEY IS ENTERED IN THE ACCESS LIST ***/
void newKeyEntered(){
  for(int i = 0; i<BLINKS;i++)
    {
      digitalWrite(PROGRAMMING_LIGHT,LOW);
      delay(250);
      digitalWrite(PROGRAMMING_LIGHT,HIGH);
      delay(250);
    }
   // digitalWrite(OPEN_LIGHT,HIGH);
}

/*** BEHAVIOR OF LED INDICATORS IF A KEY IS DELETED FROM ACCESS LIST ***/
void keyDeleted(){
  for(int i = 0; i<BLINKS;i++)
    {
      digitalWrite(PROGRAMMING_LIGHT,LOW);
      delay(250);
      digitalWrite(PROGRAMMING_LIGHT,HIGH);
      delay(250);
    }
    digitalWrite(DENIED_LIGHT,HIGH);
   
}

/*** BEHAVIOR OF LED INDICATORS IF ACCESS LIST IS FULL ***/
void listFull(){
  for(int i = 0; i<BLINKS;i++)
    {
      delay(250);
      digitalWrite(PROGRAMMING_LIGHT,HIGH);
      digitalWrite(DENIED_LIGHT,HIGH);
      digitalWrite(OPEN_LIGHT,HIGH);
      delay(250);
      digitalWrite(PROGRAMMING_LIGHT,LOW);
      digitalWrite(DENIED_LIGHT,LOW);
      digitalWrite(OPEN_LIGHT,LOW);
    } 
      digitalWrite(PROGRAMMING_LIGHT,HIGH);
      digitalWrite(DENIED_LIGHT,HIGH);
      digitalWrite(OPEN_LIGHT,HIGH);
}

y una foto :

ishben

Alos moderadores y al publico en general pido una disculpa si postie de esta manera ya que no podia ponerlo en un solo menjase, y como ven soy un novtao y les pido su ayuda para poner los 2 sketches en uno solo y asi tenga mi bluetooth y rfid tags trabajando .

gracias

fm

Mejor usar el Tag para incluir código  ;)
   

Go Up