You're probably looking to read this in your code but it's worth mentioning that a feature was just added in the hourly build a couple days ago: Tools > Board Info > SN: For some reason my Pro Micro clone shows the SN: (null) but my Mega 2560 does show a serial number, I suppose that's from the ATmega16u2.
The nightly-build reads that information from the operating system USB information.
A sketch can read it's own serial number, since that data is in the "Signature Row" and can be read with the "boot_signature_byte_get(address)".
The Arduino Uno and Mega 2560 have the ATmega16U2 serial-usb chip and the ATmega16U2 has the official serial number.
The ATmega32U4 doesn't have the official serial number. Why did Atmel 'forgot' to give this one an unique serial number ? That is weird. Perhaps it is still there, but not documented ?
It seems that the Atmel Studio can show those bytes, they are lot numbers and wafer coordinates and the serial number is a combination of those. It also seems that there is more beyond the 0x1F address ( http://www.avrfreaks.net/comment/1419041#comment-1419041 ).
It would be handy to have a unique number in some of my projects. There are also questions on this forum how to distinguish different Arduino boards when they are connected together (via wires or RF). But a sketch can not read the serial number from the usb-serial chip, and the ATmega328P or ATmega2560 doesn't have it, and also the ATmega32U4 doesn't have it. That means the serial number is useless for Arduino projects ?
Test sketch to read the complete address range (256 bytes) of 'signature' bytes:
#include <avr/boot.h>
void setup()
{
Serial.begin(9600);
while(!Serial); // For Lenoardo: wait for serial monitor.
Serial.println("\nRunning");
// According to avr/boot.h the maximum address is 0x1F, but after testing, it reads more data.
// If the offset is a byte, the sequence repeats at 256 anyway.
for( int i=0; i<256; i++)
{
if( i%16 == 0)
{
char buffer[20];
Serial.println();
sprintf( buffer, "%5d ", i);
Serial.print( buffer);
}
else
{
Serial.print( " ");
}
int x = boot_signature_byte_get( i);
if( x < 0x10)
Serial.print( "0");
Serial.print( x, HEX);
}
Serial.println();
}
void loop()
{
}
I tested a few Arduino Uno boards. The Uno and Leonardo repeat the data after 128 bytes, the Arduino Mega 2560 repeats after 256 bytes. Most values are FF, but the first 32 byte do contain data.
(I have rewritten this post, and updated the sketch to read 255 bytes).