A microcontroller is an integrated circuit (IC) device used for controlling other parts of an electronic system, usually via a central processing unit (CPU), memory, and some peripherals. The prefix “micro” implies its extremely small size while "controller" implies an increased ability to implement certain control functions. A microcontroller is often small and low cost and is used to control the functions of embedded systems in office machines, robots, home appliances, vending machines, motor vehicles, and a number of other gadgets.
The microcontroller receives data from its I/O peripherals which are interpreted using the central processor. The temporary information that the microcontroller receives is stored in its data memory, where the processor accesses it and uses instructions stored in its program memory to decipher and apply the incoming data. It then uses its I/O peripherals to communicate and enact the appropriate action.
Central Processing Unit (CPU) -- It is an internal hardware unit that performs mathematical calculations and is treated as the brain of the device. Processors are usually made of silicon material that contains tiny electrical components. In short "it is a complete computation engine fabricated on a single chip". A microprocessor executes a collection of machine instructions that tell the processor what to do. It processes and responds to various instructions that direct the microcontroller's function. This involves performing basic arithmetic, logic and I/O operations. It also performs data transfer operations, which communicate commands to other components in the larger embedded system.
Memory -- A microcontroller's memory is used to store the data that the processor receives and uses to respond to instructions that it's been programmed to carry out. Basically, it helps to increase the operation's overall speed.
A microcontroller has two main types of memory:
Program memory, which stores long-term information about the instructions that the CPU carries out. Program memory is non-volatile memory, meaning it holds information over time without needing a power source. It is also known as the Flash Memory.
Data memory, which is required for temporary data storage while the instructions are being executed. Data memory is volatile, meaning the data it holds is temporary and is only maintained if the device is connected to a power source. It is where you can place your variables and can read and write values. It is also known as Random Access Memory (RAM).
I/O peripherals -- The input and output devices are the interface of the processor to the outside world. The input ports receive information and send it to the processor in the form of binary data (0 and 1). The processor receives that data and sends the necessary instructions to output devices that execute tasks external to the microcontroller.