Getting DEVICE ID

When you compile for the ATmega328P, the AVR_ATmega328P macro will be defined. When you compile for the ATmega2560, the AVR_ATmega2560 macro will be defined. So you can do things like this:

#if defined(__AVR_ATmega328P__)
  Serial.print("It's an ATmega328P");
#elif defined(__AVR_ATmega2560__)
  Serial.print("It's an ATmega2560");
#else
  Serial.print("It's some other microcontroller");
#endif

Reference:
https://www.microchip.com/webdoc/avrlibcreferencemanual/using_tools_1using_avr_gcc_mach_opt.html