Use serial.write for programming the arduino.

I read serial.write() transmits data to the serial port. Then I saw this code here-

It is a library which resets the arduino.

Now suppose I use serial.write to transmit a program in the serial port and then use this library to reset my arduino. Will the bootloader take the program from the serial port and execute it?

P.S.- I'm new to microcontrollers.

rahulmaurya10:
Now suppose I use serial.write to transmit a program in the serial port and then use this library to reset my arduino. Will the bootloader take the program from the serial port and execute it?

NO.

As you send each byte with Serial.write() it is lost forever unless you have a computer with a suitable program at the other end to receive and save the data.

...R

Now suppose I use serial.write to transmit a program in the serial port and then use this library to reset my arduino. Will the bootloader take the program from th e serial port and execute it?

No. serial.write in an Arduino sketch (program) writes from the Arduino out of the port. You’re talking about reading-in data (written from the PC or another device).

I’ve never studied the details of the bootloader and it’s interaction with the Arduino IDE, but it’s not that simple. If you want to load a program into the Arduino, use the IDE.

If you want to control the Arduino with a computer, that can be done but don’t try to dynamically load different programs on-the-fly… A program loaded into the Arduino could have multiple features/functions so it’s running a different part of the Arduino sketch and appears to be running a different program, if that’s what you want to do…

P.S.- I’m new to microcontrollers.

The bootloader (and associated IDE) is one of the things that makes the Arduino special. If you buy a “plain” microcontroller (including the ATmega chip used in the Arduino) you generally need a separate programmer (hardware & software). And you’d need a circuit board to plug (or solder) the chip into before you could program it. Or, sometimes the programmer has a socket for the chip.

You might also need to buy a “development board” (which could also be used for programming) to get started with your hardware design.

The Arduino is already a development board and a USB programmer, as well as the finished board (or finished “main board”) in your project/product.

(The Raspberry PI has some of these same advantages, but it’s “single board computer”, so it’s a bit of a “different philosophy.”)