how to compare a data stored in eeprom memory using serial port monitor

#include<EEPROM.h>
#include <PN532.h>
#include <SPI.h>
#include<String.h>
int led = 13;
int EEsize = 1;
int taha;
String input = "";
#define PN532_CS 10
PN532 nfc(PN532_CS);
#define NFC_DEMO_DEBUG 1
void setup(void) {
#ifdef NFC_DEMO_DEBUG
Serial.begin(9600);
Serial.println("Hello!");
#endif
nfc.begin();
pinMode(led, OUTPUT);
uint32_t versiondata = nfc.getFirmwareVersion();
if (! versiondata) {
Serial.print("Didn't find PN53x board");

while (1); // halt
}
#ifdef NFC_DEMO_DEBUG
Serial.print("Found chip PN5");
#endif
nfc.SAMConfig();
}
void loop(void) {
uint32_t id;long randNumber;
id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);
if (id==2999603015)
{
  Serial.println("ACCESS GRANTED");
Serial.println(" The unique number is sent to your registered mobile");

  for (int i = 0; i < EEsize; i++)
  {
    randNumber=random(255);
    Serial.println(randNumber);
    EEPROM.write(i, randNumber);
  }
  Serial.println();
  for (int a=0; a<EEsize; a++)
  {
    taha = EEPROM.read(a);
    Serial.print("EEPROM position: ");
    Serial.print(a);
    Serial.print(" contains ");
    Serial.println(taha);
    delay(2000);
    
   //Serial.print("\r");
  //delay(1000);                  
  //Serial.println("AT+CMGF=1\r");    
  //delay(1000);
  //Serial.println("AT+CMGS=\"+91944xxxxxx8\"\r");    //Number to which you want to send the sms
  //delay(1000);
  //Serial.println(" randNumber \r");   //The text of the message to be sent
  //delay(1000);
  //Serial.write(0x1A);
  //delay(1000); 
  //
  if(Serial.available()){
  input += (int)Serial.read();
  delay(30);
if(input=="taha");
  Serial.println("The unique number you entered is correct");
}

}
}
 
else if(id!=0)
{
 Serial.println("ACCESS DENIED");
 delay(2000);
 digitalWrite(led, HIGH); 
}
else
{
  Serial.println(" PLEASE DISPLAY YOUR MOBILE");
  delay(2000);
}
}[quote][quote][/quote][/quote]

working_nfc_3.ino (1.77 KB)

Serial.read() will return the ASCII characters from the serial input, not numbers so when you type say 5 you will receive the number 53 or in hex 0x35. It is only half a byte or a nibble, that is 4 bits.
Then you need to assemble these nibbles into a byte by using shift and the bitwise OR operation, only then can you compare it to a byte stored in EEPROM.

Please edit your post, select the code, and put it between [code] ... [/code] tags.

You can do that by hitting the # button above the posting area.

Read this before posting a programming question

How to use this forum

hello guys... actually i am a team member of taha...

 if(Serial.available()){
  input += (int)Serial.read();
  delay(30);
//if(input =="taha");
  Serial.println("The unique number you entered is correct");
}

by the way here is where i have problem in program...
wen the program creates a random number and saves it in EEPROM.
next step i need to give a serial monitor input ans compare that to the EEPROM data.. what shud i do...??? plzzz helppp

  input += (int)Serial.read();

Serial.read() returns an int. Why do you feel the need to cast the int to an int?

blackfury007:
what shud i do...??? plzzz helppp

You should:

  • Use proper English.
  • Post your actual code.
  • Explain what the problem is with it.

PeterH:

blackfury007:
what shud i do...??? plzzz helppp

You should:

  • Use proper English.
  • Post your actual code.
  • Explain what the problem is with it.

AND
read the answer that has already been given to you.

hello guys... actually i am a team member of taha..

I have no idea what that means.

Grumpy_Mike reported to moderator with:

can you just give me example program or link...so that i can assemble the ascii characters from serial port monitor

Don't "report" your questions to the moderator. Just post them here.

How to use this forum

for (int i = 0; i < EEsize; i++)
  {
    randNumber=random(255);
    Serial.println(randNumber);
    EEPROM.write(i, randNumber);
  }
  Serial.println();
  for (int a=0; a<EEsize; a++)
  {
    taha = EEPROM.read(a);
    Serial.print("EEPROM position: ");
    Serial.print(a);
    Serial.print(" contains ");
    Serial.println(taha);
}
{
if(Serial.available()){
  input += (int)Serial.read();
  delay(30);
if(input=="taha");
  Serial.println("The unique number you entered is correct");
}

in this program the random number function creates a random number upto 255, save dat to the EEPROM position and display it in serial monitor.
and that random number should be given as input in serial monitor and compared to the EEPROM position.
i tried it alot but only singlr digit is possible. i need to get output for three digit comparision..

Is there some good
reason that your code
wanders all over the
place?

There was a lot of effort put
into the Tools + Auto Format
menu item to take
care of that
problem.

  input += (int)Serial.read();

I'm sure that there is some good reason why you are casting an int to an int. I can't wait to hear it,

Is taha a byte or a string? In the second for loop, you are using taha as a byte. In the third, you are comparing the serial input that you have received so far to the string "taha".

What is this snippet supposed to be doing?

input += (int)Serial.read();

And I am dying to find out why adding up ASCII characters is is supposed to generate a string.

If you received the characters 1 and 3 this would add 49 and 51 to give you 100 or 0x64 which would give you a lower case d