Introduction of Microcontrollers
What is Microcontrollers?
A microcontroller is a compact integrated circuit (IC) designed to perform specific tasks within an embedded system. It consists of a processor (CPU), memory (RAM and ROM), and input/output (I/O) peripherals, all embedded into a single chip. Unlike general-purpose computers, microcontrollers are optimized for real-time control applications, such as automation, robotics, consumer electronics, and industrial machinery. They operate on low power, making them ideal for battery-powered devices. Popular microcontroller families include Arduino, PIC, AVR, and ARM Cortex. With advancements in IoT and AI, microcontrollers continue to evolve, enabling smarter and more efficient electronic systems.
🧠 CPU – The Brain of a Microcontroller
The CPU is the ‘brain’ of the microcontroller. It is the processor that runs your code and communicates with connected devices. CPUs can have one or more cores, allowing them to work together to execute instructions efficiently.
💡 Did You Know? A CPU operates on a clock cycle, ticking millions or billions of times per second. Each tick synchronizes the CPU’s operations, enabling it to process instructions.
CPU Speed & Clock Cycles:
- Measured in Hertz (Hz)
- 1 MHz = 1 million cycles per second
- 1 GHz = 1 billion cycles per second
🔎 Research Task: Check the clock speed of your computer. How many times faster is it than a microcontroller like the Wio Terminal (120MHz)?
💡 Power & Heat Consideration: The faster a CPU, the more power it consumes and heat it generates. Microcontrollers are designed to be power-efficient, sometimes running for years on small batteries!
🔍 Fun Fact: Some PCs, like the Apple M1 chip, use a mix of high-power and efficiency cores, similar to microcontrollers.
📦 Memory – Where Data Lives
Microcontrollers use two types of memory:
- Program Memory (Non-Volatile): Stores your program code permanently.
- RAM (Volatile): Used for temporary storage while the program runs.
💡 Key Differences:
- A typical PC has 8GB of RAM (8,000,000,000 bytes)
- The Wio Terminal has 192KB of RAM (192,000 bytes) – over 40,000 times smaller!
🔎 Research Task: Check how much RAM your computer has. Compare it with a microcontroller!
🔌 Input/Output (I/O) – Connecting to the World
Microcontrollers need I/O connections to interact with sensors and actuators. They use GPIO (General-Purpose Input/Output) pins, which can be:
- Input Pins: Read values from sensors (e.g., temperature, motion)
- Output Pins: Send signals to actuators (e.g., motors, LEDs)
✅ You’ll learn more about GPIO in an upcoming lesson.
🔎 Hands-on Task: If using a Wio Terminal, find its GPIO pins. Look at the Pinout diagram and attach the sticker with pin numbers if you haven’t already.
📏 Physical Size – Tiny Yet Powerful
Microcontrollers are much smaller than desktop CPUs. Check out these size comparisons:
Device | Size |
---|---|
Freescale Kinetis KL03 | 1.6mm x 2mm x 1mm |
Wio Terminal | 72mm x 57mm x 12mm |
Intel i9 CPU + Heat Sink & Fan | 136mm x 145mm x 103mm |
💡 Fun Fact: The smallest microcontroller is small enough to fit in the dimple of a golf ball! 🏌️♂️
🛠 Frameworks & Operating Systems
Unlike PCs, microcontrollers don’t run traditional OSes like Windows or macOS. Instead, they:
- Run bare-metal code (direct hardware control)
- Use lightweight real-time operating systems (RTOS) for multitasking & networking
Popular RTOS options:
- Azure RTOS
- FreeRTOS
- Zephyr
🔎 Research Task: Read about one RTOS and explore how it works!
🔷 Arduino – A Microcontroller Superstar
Arduino
is one of the most popular microcontroller platforms. It provides:
- Hardware: Arduino-compatible boards
- Software: Arduino framework (written in C/C++)
📝 Arduino Code Structure:
void setup() {
// Runs once at startup
}
void loop() {
// Runs repeatedly
}
💡 How it Works: The setup()
function initializes components, and the loop()
function runs continuously, responding to inputs.
🔎 Hands-on Task:
- Find the
setup()
andloop()
functions in your Arduino code. - Monitor the serial output to see how
loop()
runs repeatedly. - Add code to
setup()
that prints a message. Reboot the device and observe how it only prints once!
🎯 Summary
✅ Microcontrollers have low-power CPUs, small memory, and GPIO pins for interfacing.
✅ They can run bare-metal code or RTOS.
✅ Arduino is a popular microcontroller framework using C/C++.
🚀 Next Steps: Explore microcontroller applications in real-world projects!