# How to get a unique ID for arduino board?

**URL:** <https://forum.arduino.cc/t/how-to-get-a-unique-id-for-arduino-board/427574>\
**Category:** General Guidance\
**Created:** [December 29, 2016, 8:02am UTC](https://forum.arduino.cc/t/how-to-get-a-unique-id-for-arduino-board/427574 "2016-12-29T08:02:56Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![moham14](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@moham14](https://forum.arduino.cc/u/moham14)\
**Post date:** [December 29, 2016, 8:02am UTC](https://forum.arduino.cc/t/how-to-get-a-unique-id-for-arduino-board/427574/1 "2016-12-29T08:02:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [December 29, 2016, 8:06am UTC](https://forum.arduino.cc/t/how-to-get-a-unique-id-for-arduino-board/427574/2 "2016-12-29T08:06:32Z")

</div>

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.. 🙂

---

<div class="post-metadata">

**Author:** ![Grumpy\_Mike](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/grumpy_mike/32/213521_2.png) [@Grumpy\_Mike](https://forum.arduino.cc/u/Grumpy_Mike)\
**Post date:** [December 29, 2016, 10:56am UTC](https://forum.arduino.cc/t/how-to-get-a-unique-id-for-arduino-board/427574/3 "2016-12-29T10:56:08Z")

</div>

Use a DS2401

> **[DS2401 Silicon Serial Number | Analog Devices](https://www.analog.com/en/products/ds2401.html)**
>
> The DS2401 enhanced Silicon Serial Number is a low-cost, electronic registration number that provides an absolutely unique identity which can be determined with a minimal electronic interface (typically, a single port pin of a microcontroller). The...

---

<div class="post-metadata">

**Author:** ![terryking228](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/terryking228/32/214478_2.png) [@terryking228](https://forum.arduino.cc/u/terryking228)\
**Post date:** [December 29, 2016, 1:19pm UTC](https://forum.arduino.cc/t/how-to-get-a-unique-id-for-arduino-board/427574/4 "2016-12-29T13:19:26Z")

</div>

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

[Here is code to read them:](https://arduino-info.wikispaces.com/Brick-Temperature-DS18B20#Read%20individual)

---

<div class="post-metadata">

**Author:** ![dlloyd](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dlloyd/32/751911_2.png) [@dlloyd](https://forum.arduino.cc/u/dlloyd)\
**Post date:** [December 29, 2016, 3:37pm UTC](https://forum.arduino.cc/t/how-to-get-a-unique-id-for-arduino-board/427574/5 "2016-12-29T15:37:44Z")

</div>

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).

> **[GitHub - NicoHood/Hoodloader: Advanced HID Firmware for Arduino Uno/Mega](https://github.com/NicoHood/Hoodloader)**
>
> Advanced HID Firmware for Arduino Uno/Mega. Contribute to NicoHood/Hoodloader development by creating an account on GitHub.

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

---

<div class="post-metadata">

**Author:** ![Chagrin](https://avatars.discourse-cdn.com/v4/letter/c/57b2e6/32.png) [@Chagrin](https://forum.arduino.cc/u/Chagrin)\
**Post date:** [December 29, 2016, 4:37pm UTC](https://forum.arduino.cc/t/how-to-get-a-unique-id-for-arduino-board/427574/6 "2016-12-29T16:37:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ard\_newbie](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@ard\_newbie](https://forum.arduino.cc/u/ard_newbie)\
**Post date:** [December 29, 2016, 5:14pm UTC](https://forum.arduino.cc/t/how-to-get-a-unique-id-for-arduino-board/427574/7 "2016-12-29T17:14:08Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![MarkT](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@MarkT](https://forum.arduino.cc/u/MarkT)\
**Post date:** [December 29, 2016, 10:21pm UTC](https://forum.arduino.cc/t/how-to-get-a-unique-id-for-arduino-board/427574/9 "2016-12-29T22:21:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![woody363](https://avatars.discourse-cdn.com/v4/letter/w/2acd7d/32.png) [@woody363](https://forum.arduino.cc/u/woody363)\
**Post date:** [November 20, 2017, 12:07pm UTC](https://forum.arduino.cc/t/how-to-get-a-unique-id-for-arduino-board/427574/10 "2017-11-20T12:07:03Z")

</div>

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:

```cpp
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.

---

<div class="post-metadata">

**Author:** ![adrianka](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/adrianka/32/1146509_2.png) [@adrianka](https://forum.arduino.cc/u/adrianka)\
**Post date:** [September 28, 2018, 3:30pm UTC](https://forum.arduino.cc/t/how-to-get-a-unique-id-for-arduino-board/427574/11 "2018-09-28T15:30:49Z")

</div>

> 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!

---

<div class="post-metadata">

**Author:** ![ard\_newbie](https://avatars.discourse-cdn.com/v4/letter/a/45deac/32.png) [@ard\_newbie](https://forum.arduino.cc/u/ard_newbie)\
**Post date:** [September 28, 2018, 3:57pm UTC](https://forum.arduino.cc/t/how-to-get-a-unique-id-for-arduino-board/427574/12 "2018-09-28T15:57:06Z")

</div>

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

[https://forum.arduino.cc/index.php?topic=325999.0](https://forum.arduino.cc/index.php?topic=325999.0)

---

<div class="post-metadata">

**Author:** ![adrianka](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/adrianka/32/1146509_2.png) [@adrianka](https://forum.arduino.cc/u/adrianka)\
**Post date:** [October 16, 2018, 9:11am UTC](https://forum.arduino.cc/t/how-to-get-a-unique-id-for-arduino-board/427574/13 "2018-10-16T09:11:12Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 5, 2021, 6:04pm UTC](https://forum.arduino.cc/t/how-to-get-a-unique-id-for-arduino-board/427574/14 "2021-05-05T18:04:22Z")

</div>


