How to get a unique ID for arduino board?

In a project for creating a hardware lock, I need to get a unique ID. I use arduino mega 2560 R3 board. Does arduino boards have a built in unique ID? Or is there another chip for this purpose. It is possible to save an ID in EEPROM but it will not be a fix_forever_value, and someone may change it easily.

Hi, The IDE can get you a serial number. TOOLS > Get Board Info, but not sure if there is a way for code to read it though.

Tom.. :)

Use a DS2401

Use a DS18B20.. Low cost... 3 pins on the DS18B20 1 pin on Arduino

Here is code to read them:

It's unfortunate that there doesn't seem to be an easy way to read the existing USB serial number from the ATmega16U2 that's on your board.

Details from the datasheet: "ATmega8U2/16U2/32U2 includes a unique 10 bytes serial number located in the signature row. This unique serial number can be used as a USB serial number in the device enumeration process. The pointer addresses to access this unique serial number are given in Table 23-6 on page 236.."

Might need to go as far as replacing the bootloader to get access (not sure).

Perhaps someone on this forum would know if this is possible or worth the effort.

The USB-to-serial chip used by the Mega R3 can be programmed to set a serial number (google "DFU-programmer"). Granted that could be changed as easily as the Mega's EEPROM, but given that the dfu-programmer docs are pretty bad it'll be more difficult.

It's a pity that all Arduino boards are not granted with a unique ID like the DUE which has the unique ID of its uc SAM3X8E, it cannot be changed and is easy to read. :)

It's a real pity that frogs don't have wings too. But whatcha gonna do?

There are also uniqueID chips for ethernet MAC addresses, I remember one is used in the Nanode, a 3-pin thing, probably cheaper than a DS18B20 (had a long unmemorable part number)

Easiest to stick a number in EEPROM - if they can reprogram that, they can reprogram your sketch too, its the least of your worries.

Add one-time code to set a code in EEPROM as part of the testing procedure?

Or write a tool to increment a code by editing the .hex file used by avrdude (ie create a bespoke download script). A code in flash is harder to alter, not that that means much, but it allows for some legal redress if the code is cloned as you'll know exactly which unit was pirated.

I realise this is an old thread, but I came across this and later found a better solution to the problem

The following code gives the exact second the sketch was complied on the computer before being uploaded, which will generally be unique:

const String compile_date = __DATE__ " " __TIME__;  //compile date that is used for a unique identifier

This can be used as-is, as a random seed, hash or whatever.

This will give a unique code for each compile. If instead you want it to be unique to the board you can then store this into EEPROM conditionally of there not being a date there already. Giving it the value of the first compile time.

ard_newbie: It's a pity that all Arduino boards are not granted with a unique ID like the DUE which has the unique ID of its uc SAM3X8E, it cannot be changed and is easy to read. :)

Hi ard_newbie,

can you tell me how to do that?

I cannot read the ID from the SAM3X8E from my dues with udevadm info...

Thanks in advance!

There is an example sketch in this thread, reply #4:

Thank you!

Is it possible to do it in Linux in the terminal?
I get a unique serial number through the serial port but not through the native port and my Dues are connected by native port.