Running independent from the computer

Ok. How can I get this to run independent from the computer?

#include <Wire.h>

#include <twi.h>

#include <nfc.h>

/**
  @file    nfc_mifare_mf1s50_reader.ino
  @author  www.elechouse.com
  @brief   example of reading mf1s50 card for NFC_MODULE
  
    For this demo, waiting for a MF1S50 card or tag, after reading a card/tag UID,
    then try to read the block 4/5/6/7 ..
  
  @section  HISTORY
  
  V1.0 initial version
  
    Copyright (c) 2012 www.elechouse.com  All right reserved.
*/

/** include library */


/** define a nfc class */
NFC_Module nfc;

void setup(void)
{
  Serial.begin(9600);
  nfc.begin();
  Serial.println("MF1S50 Reader Demo From Elechouse!");
  
  uint32_t versiondata = nfc.get_version();
  if (! versiondata) 
  {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }
  
  // Got ok data, print it out!
  Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX); 
  Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC); 
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);
  
  /** Set normal mode, and disable SAM */
  nfc.SAMConfiguration();
}

void loop(void)
{
  u8 buf[32],sta;
  
  
  /** Polling the mifar card, buf[0] is the length of the UID */
  sta = nfc.InListPassiveTarget(buf);
  
  /** check state and UID length */
  if(sta && buf[0] == 4){
    /** the card may be Mifare Classic card, try to read the block */  
    Serial.print("UUID length:");
    Serial.print(buf[0], DEC);
    Serial.println();
    Serial.print("UUID:");
    nfc.puthex(buf+1, buf[0]);
    Serial.println();
    /** factory default KeyA: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF */
    u8 key[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
    u8 blocknum = 4;
    /** Authentication blok 4 */
    sta = nfc.MifareAuthentication(0, blocknum, buf+1, buf[0], key);
    if(sta)
    {
      /** save read block data */
      u8 block[16];
      Serial.println("Authentication success.");
      
      // uncomment following lines for writing data to blok 4
     
    //strcpy((char*)block, "eE8080474nosaj");
      //sta = nfc.MifareWriteBlock(blocknum, block);
      //if(sta){
      // Serial.println("Write block successfully:");
     // }
      String strng;

      /** read block 4 */
      sta = nfc.MifareReadBlock(blocknum, block);
      if(sta)
      {
        Serial.println("Read block successfully:");
        
        nfc.puthex(block, 16);
        Serial.println();
      
        char passCode[] = "65 45 38 30 38 30 34 37 34 6E 6F 73 61 6a 00 00";
        
        int n;
        n = memcmp( passCode, block, sizeof(passCode));
        
        //to find n compairison
        //Serial.println(n);
      
        if(n == -47) Serial.println("yes");
        else if (n != -47) Serial.println("no 1");
        else Serial.println("no 2");
         Serial.println();
  
      }
      

    }  
  }



}
     u8 block[16];
 ...

      /** read block 4 */
      sta = nfc.MifareReadBlock(blocknum, block);
      if(sta)
      {
        Serial.println("Read block successfully:");
        
        nfc.puthex(block, 16);
        Serial.println();
      
        char passCode[] = "65 45 38 30 38 30 34 37 34 6E 6F 73 61 6a 00 00";
        
        int n;
        n = memcmp( passCode, block, sizeof(passCode));

The variable "block" is 16 bytes. The variable passCode is 48 bytes. How will they ever compare equal?

        if(n == -47) Serial.println("yes");
        else if (n != -47) Serial.println("no 1");
        else Serial.println("no 2");

You have three conditions here. n is -47, n is not -47 and n is something else. What would that something else be, out of curiosity?

Imo just feeling some things out. Why do I have to keep it plugged in to the computer for it to keep working?

You can plug a wall-wart into it for power when the computer is off.

12v?

7-9 is recommended. 12V will work if you don't have much current demand from things connected to the board.

I have a nfc board.

I believe you will be ok.

Your voltage regulator should remain cool or warm but not hot.

7-10-2013 11-57-13 PM.jpg

        if(n == -47) Serial.println("yes");
        else if (n != -47) Serial.println("no 1");
        else Serial.println("no 2");

You have three conditions here. n is -47, n is not -47 and n is something else. What would that something else be, out of curiosity?

An imaginary number?

XD

Could it be because im using java or because im accessing the serial monitor in my code?

What happens if you use it with an external power supply?

Could it be because im using java or because im accessing the serial monitor in my code?

The Java is transmitted text. You do have plans to connect something to the serial pins, don't you? Something that will use the Java?

Yes the nfc reader. Nothing happens when I unplug thee battery as long as the usb is still inn.

USB supplies 500 mA 5V. What do you expect?

Add: Arduino can have up to 200 mA drawn through it. USB gives enough to cause trouble if you don't care about current drawn =through= the Arduino.

It is when I unplug the usb but still have the battery plugged in. MY troubles start.

What battery you are using? 9v ?

9v

spucoly:
It is when I unplug the usb but still have the battery plugged in. MY troubles start.

What type of battery is it ?

A single 9V "transistor" battery?

I have an arduino duemilanove and the seeedstudio nfc shield running with a 9v block battery with no problems