Get unique ID from Arduino board

Dear all,

I wonder if it is possible to get a unique ID for each Arduino based board using the serial command...
In my application I would need to get a unique ID from Arduino board at the startup of the board, without connecting it to a PC, since this ID would be required in my program.
Is it possible to get it somehow?

Thanks.

Silvano

You could easily set an ID and save it in EEPROM, but the AVR-based Arduinos don't have a unique ID like many of the 32bit microcontrollers do. You can get specific Unique ID chips in a variety of interfaces, and if fact you can use the cheap DS18B20 temperature sensor since they have a unique ID.

I cannot set an ID in the EEPROM. I just asked beacuse what I need is a unique ID at startup without writing an ID in the EEPROM.

Thanks anyway!

Silvano

Sil83:
I cannot set an ID in the EEPROM. I just asked beacuse what I need is a unique ID at startup without writing an ID in the EEPROM.

Thanks anyway!

Silvano

Gotcha. I've had a few situations where I would have liked to have exactly what you're looking for. What I ended up doing was using an analogRead() on an unconnected analog pin and using the result for the seed of a random() call. Do that a few times and you get a couple of fairly random bytes. You can do that on first boot and store it in EEPROM, then on subsequent boots you check to see if there is already an ID in EEPROM.

It isn't exactly what you're looking for but it is about the closest thing I've seen without using external hardware.

You are right and I have alreadt thaought about that. But the problem is that the board is programmed with a fixed code, I just realize it and then other people will upload the code hoping everything works fine.

Thanks!

Silvano

FYI an arduino DUE has a Unique ID (128-bit unique ID).

I have a board based on ATMega32u4.

What you can do is to generate a unique ID. I'll highly recommend using the Entropy library. It uses the watch dog timer, and does a really good job of generating random numbers.

Ok, but I want the unique id is always the same...

So generate the unique ID with the entropy library and store this in the EEPROM! Then all you need to do is to check the EEPROM content on boot. If the ID is present, skip ID generation. If not present, generate ID. Simple as that.

Thanks to everybody!

hansibull:
So generate the unique ID with the entropy library and store this in the EEPROM! Then all you need to do is to check the EEPROM content on boot. If the ID is present, skip ID generation. If not present, generate ID. Simple as that.

Is there a guarantee that if you run your 'code' on a number of Arduinos, they all will have a different ID?

Is there a guarantee that if you run your 'code' on a number of Arduinos, they all will have a different ID?

Chances are very small if you let the generated number be long enough. You can try it yourself if you like :slight_smile: Use your Arduino to print a bunch of randomly generated numbers and print them out to the Serial monitor. Copy the output into a spreadsheet and do all sorting and number crunching there.

EDIT: you can also insert the outputted number into randomSeed if you prefer this.

hansibull:
Chances are very small if you let the generated number be long enough. You can try it yourself if you like :slight_smile: Use your Arduino to print a bunch of randomly generated numbers and print them out to the Serial monitor. Copy the output into a spreadsheet and do all sorting and number crunching there.

EDIT: you can also insert the outputted number into randomSeed if you prefer this.

Will do when I get back more into Arduino.

I know this might be a little bit late to come back to this thread, but it seems like the ATMega328 may in fact have an undocumented serial number that you can use. See here for details.