1. Microcontrollers vs. Microprocessors
- Microprocessor: Contains only a CPU on a single chip. It requires external RAM, ROM, and I/O controllers to function (e.g., Intel Core i7, Raspberry Pi). Designed for complex general-purpose computing tasks.
- Microcontroller: Contains CPU, RAM, ROM, and I/O interfaces all integrated onto a single silicon chip (e.g., ATmega328p on the Arduino Uno). Designed for specific control systems and hardware interfacing.
2. Arduino Hardware Interfacing
Arduino provides physical pins to control components:
- Digital Pins: Can be set as either input (reading a button switch) or output (switching an LED light on/off). Operating in two states: HIGH (5V) and LOW (0V).
- Analog Pins: Can read varying voltage levels (from 0V to 5V), translating them to integer values (from 0 to 1023) using an Analog-to-Digital Converter (ADC).
3. Sample Arduino LED Blinking Code
Every Arduino sketch consists of two mandatory functions:
// Pin 13 has an LED connected on most Arduino boards.
int ledPin = 13;
void setup() {
// Initialize the digital pin as an output.
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, HIGH); // Turn the LED on (5V)
delay(1000); // Wait for a second
digitalWrite(ledPin, LOW); // Turn the LED off (0V)
delay(1000); // Wait for a second
}