Will sketches still work when uploaded to different versions of Arduino?

I currently have an Arduino Uno, and I have learnt to write a few simple sketches for it. I'm planning to get an Arduino Nano and Arduino Micro. Would the sketches that were written for Uno still run the same when uploaded to Nano and Micro?

Similarly, for a sketch that works on Micro, would it work just as the same when uploaded to Nano?

Sketched have to be compiled for the hardware that they are to run on. Depending on what this mysterious sketch does, it may, or may not, work correctly when compiled for the 3 Arduinos you mention.

The sketch that I have is fairly simple. It basically just controls a servo motor, reads input from button, and turns on/off 3 LEDs. The sketch is written in Processing though. So I have to upload the Standard Firmata to the Arduino. And then just run from the Processing application.

This seems to work on Uno. But would it work on the Nano and Micro too?

But would it work on the Nano and Micro too?

It should.

Thanks! Glad to hear that the Firmata works on all the versions.

Just a side question, since it will mostly work, does it then mean that the different versions of Arduino are actually the same in terms of usage? That's they all will work the same and give the same result with the same set of code. The only differences between the versions are just their physical size and the circuit implementations and a memory specifications?

That's they all will work the same and give the same result

No, you can not assume that. There are voltage differences that need to be considered, for one thing. Clock speeds, for another.

Lets see:

  • Different 'Arduinos' support different numbers of pins. If your code uses 14 instead of A0, it will run differently on a Mega where pin 54 is the first Analog pin, or a Leonardo where 18 is the first Analog pin. For example my Teensy 3.0 has 37 pins, my Uno has 20, my Digispark has 6;
  • The number of PWM (i.e. analogWrite) pins varies from board to board;
  • Each board has different numbers of timers, which in turn can affect other things like which pins support servo or pwms;
  • Different systems have different interrupts. For example, on my Uno, I could attach pins 2 and 3 to separate interrupts, but not the others, but on ATtiny85 systems you can.
  • On some boards, you cannot use some analog pins as digital pins;
  • Different boards support different amounts of flash memory (to hold instructions), SRAM (to hold normal variables), and EEPROM (to hold data between power cycles). For example, I have an i2c OLED 128x64 display, and I can't use it on the ATtiny85 based systems (digispark, trinket, gemma), because those systems don't have a kilobyte of read/write memory that is needed to keep the entire screen in memory;
  • On boards based on the Arm cpu (Due, Teensy 3.0, DigiX), the type int is 32-bits while on AVR based processors, int is 16-bits, similarly on Arms, the double type is 64 bits, and on AVRs, the double type is 32-bits, and it holds a smaller range of numbers.
  • Some microprocessors have one or more i2c, spi, can, i2s, and serial connections to deal with off-board electronics, because of this, some of the libraries used in the larger microprocessors don't exist in the smaller ones, or you need to use a different approach (for example, Wire, Serial, SPI, USB, etc.). I have two groups of processors: Uno/Teensy 3.0 that support i2c with the Wire library, and Digispark/Trinket/Gemma that don't support Wire, but can support TinywireM. Due to the IDE, I can't really share code that uses i2c or that does debug prints to the serial monitor between the two sets of processors;
  • Different boards need different ways to download the firmware