What is a microcontroller?
A microcontroller (MCU for Microcontroller Unit) is a small computer on a single metal oxide semiconductor (MOS) VLSI integrated circuit (IC) chip. A microcontroller contains one or more CPUs (processor cores) as well as memory and programmable input/output peripherals. Program memory in the form of ferroelectric RAM, NOR flash, or OTP ROM is also typically included on-chip, along with a small amount of RAM. Microcontrollers are designed for embedded applications, as opposed to microprocessors used in personal computers or other general-purpose applications consisting of various discrete chips.

A microcontroller is similar to a system on a chip (SoC), but not as complex. SoCs can interface with external microcontroller chips as motherboard components, but SoCs typically integrate advanced peripherals such as graphics processing units (GPUs) and Wi-Fi interface controllers as their internal microcontroller unit circuitry.
Microcontrollers are used in automatically controlled products and equipment such as automotive engine control systems, implantable medical devices, remote controls, office machines, appliances, power tools, toys and other embedded systems. By reducing size and cost, microcontrollers can economically control more devices and processes digitally than designs using separate microprocessors, memory, and input/output devices. Mixed-signal microcontrollers are common and integrate the analog components needed to control non-digital electronic systems. In the context of IoT, microcontrollers are an economical and popular means of collecting, sensing, and driving the physical world as edge devices.
Some microcontrollers may use four-bit words and operate at frequencies as low as 4 kHz for low power consumption (single-digit milliwatts or microwatts). They typically have the ability to retain functionality while waiting for an event (such as a button press or other interrupt); power consumption while sleeping (CPU clock and most peripherals off) can be as low as nanowatts, making many of these ideal for long-lasting batteries application. Other microcontrollers may play a performance-critical role, and they may need to be more like digital signal processors (DSPs), with higher clock speeds and power consumption.
Microcontroller function
Microcontrollers typically contain several to dozens of general-purpose input/output pins (GPIOs). GPIO pins are software configurable as input or output. When GPIO pins are configured as input, they are typically used to read sensors or external signals. GPIO pins configured as output states can often drive external devices such as LEDs or motors indirectly through external power electronics.
Many embedded systems need to read sensors that generate analog signals. That's what an analog-to-digital converter (ADC) is for. Since processors are built to interpret and process digital data (i.e. 1s and 0s), they can't do anything with the analog signals that a device might send to it. Therefore, an analog-to-digital converter is used to convert the incoming data into a form that can be recognized by the processor. A less common feature found on some microcontrollers is the digital-to-analog converter (DAC), which allows the processor to output an analog signal or voltage level.
In addition to converters, many embedded microprocessors include various timers. One of the most common types of timers is the Programmable Interval Timer (PIT). PIT may count down from a value to zero, or up to the capacity of the count register, overflowing to zero. Once it reaches zero, it sends an interrupt to the processor indicating that it has finished counting. This is useful for devices like thermostats, which periodically test the surrounding temperature to see if they need to turn the air conditioner on/off, the heater on/off, etc.
Dedicated Pulse Width Modulation (PWM) modules allow the CPU to control power converters, resistive loads, motors, and more without using many CPU resources in tight timer loops.
The Universal Asynchronous Receiver/Transmitter (UART) module can receive and transmit data over the serial line with very little CPU load. Dedicated on-chip hardware often also includes the ability to communicate with other devices (chips) in digital formats, such as Inter-Integrated Circuit (I²C), Serial Peripheral Interface (SPI), Universal Serial Bus (USB), and Ethernet.
Difference Between Microcontroller and Microprocessor

Processors generally refer to three types of chips: microprocessors, microcontrollers, and digital signal processors.
The CPU in the PC is called a microprocessor, and the CPU and memory (memory, external memory), I/O devices, buses, etc. constitute a computer.
A microprocessor (MPU) usually represents a powerful CPU, but not a chip designed for any specific computing purpose that exists. Such chips tend to be the core CPUs of personal computers and high-end workstations.
Microcontrollers (MCUs) have a built-in interrupt system that responds to external stimuli (interrupts) in real time, suspending one process to execute another. For example, in a microcontroller-based microwave oven, opening the door will trigger an interrupt. In order to better meet the embedded applications in the control field, some circuit units that meet the control requirements are continuously expanded in the single-chip microcomputer. At present, the single-chip microcomputer has been widely referred to as the microcontroller (MCU).
