MODULE 02

Microcontrollers

Arduino ยท ESP32 ยท Raspberry Pi Pico

3 Boards12 ProjectsFull Setup GuidesCode Included

Arduino Uno

The Arduino Uno is the world's most popular microcontroller board for beginners. Based on the ATmega328P chip, it gives you 14 digital I/O pins, 6 analog inputs, and a simple USB programming interface.

ATmega328P USB ARDUINO UNO
Arduino Uno R3
AVR ยท ATmega328P ยท 16 MHz
The Uno is the ideal starting point. Its forgiving 5V logic level, abundant community resources, and affordable shields make it unbeatable for learning. The Arduino IDE abstracts away low-level C++ details so you can focus on building things.
16 MHz
Clock Speed
32 KB
Flash Memory
14 Digital
I/O Pins
6 Analog
Input Pins

Arduino IDE Setup

Getting your Arduino Uno ready to program takes about 5 minutes. Follow these steps and you'll be uploading code in no time.

INSTALLATION STEPS

  • 1

    Go to arduino.cc/en/software and download the Arduino IDE 2.x for your operating system (Windows/Mac/Linux). The installer is around 200MB.

  • 2

    Run the installer. On Windows, accept the driver installation prompts โ€” these USB drivers are essential for communication with the board.

  • 3

    Plug your Arduino Uno into your computer via USB. The green power LED should light up on the board.

  • 4

    Open Arduino IDE โ†’ Tools โ†’ Board โ†’ Select "Arduino Uno". Then Tools โ†’ Port โ†’ Select the COM port (Windows) or /dev/ttyUSB0 (Linux) that appeared when you plugged in the board.

  • 5

    Go to File โ†’ Examples โ†’ 01.Basics โ†’ Blink. Click the Upload button (right arrow icon). The built-in LED on pin 13 should start blinking!

๐Ÿ’ก Can't find the port? On Windows, open Device Manager and look for "Ports (COM & LPT)". If you see an unknown device with a yellow warning, you need to install the CH340 or CP2102 USB driver for your specific board variant.

Arduino Uno Pinout

Understanding the pins is crucial. Each pin has a specific function โ€” some can only do digital I/O, others can measure analog voltages, and some support special protocols.

D0-TX RESET 3.3V 5V GND GND Vin A0 A1 A2 A3 D13 SCK D12 MISO D11 MOSI ~ D10 SS ~ D9 ~ D8 D7 D6 ~ D5 ~ D4 ARDUINO UNO ATmega328P โ€” 16MHz Digital I/O (~=PWM) Analog In Power
~ means PWM: Pins marked with ~ (3, 5, 6, 9, 10, 11) support analogWrite() which outputs PWM โ€” perfect for dimming LEDs, controlling motor speed, and generating tones.

Reading Sensors

Sensors are how microcontrollers perceive the physical world. Here we'll read analog sensors and the popular DHT11 temperature sensor.

ANALOG READ โ€” POTENTIOMETER / LDR

void setup() { Serial.begin(9600); } void loop() { int rawValue = analogRead(A0); // 0 to 1023 float voltage = rawValue * (5.0 / 1023.0); Serial.print("Raw: "); Serial.print(rawValue); Serial.print(" Voltage: "); Serial.println(voltage); delay(200); }

DHT11 TEMPERATURE & HUMIDITY

// Install: Tools โ†’ Manage Libraries โ†’ search "DHT sensor library" #include <DHT.h> DHT dht(4, DHT11); // DHT11 connected to pin 4 void setup() { Serial.begin(9600); dht.begin(); } void loop() { float temp = dht.readTemperature(); // Celsius float hum = dht.readHumidity(); Serial.print("Temp: "); Serial.print(temp); Serial.print("ยฐC "); Serial.print("Humidity: "); Serial.println(hum); delay(2000); }

ESP32 Overview

The ESP32 is a powerhouse microcontroller with built-in WiFi and Bluetooth. 240MHz dual-core processor, 520KB RAM, and countless peripherals โ€” all for a fraction of the cost of dedicated modules.

ESP32 Micro USB ESP32 DevKit
ESP32 DevKit V1
XTENSA LX6 ยท DUAL CORE ยท WIFI + BLE
The ESP32 replaces the ESP8266 with significantly more power. It has two cores running at 240MHz, 18 analog input channels, capacitive touch sensing, hardware encryption, and enough memory to run a full web server. Programs with Arduino IDE โ€” just install the ESP32 board package.
240 MHz
Dual Core
520 KB
SRAM
WiFi + BT
Wireless
36 GPIO
Pins
โšก Adding ESP32 to Arduino IDE: File โ†’ Preferences โ†’ add this URL to "Additional Board URLs":
https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
Then Tools โ†’ Board โ†’ Boards Manager โ†’ search ESP32 โ†’ Install.

ESP32 WiFi Web Server

Create a web page hosted on the ESP32 that lets you control an LED from any browser on your local network โ€” no internet required!

#include <WiFi.h> #include <WebServer.h> const char* ssid = "Your_WiFi_Name"; const char* password = "Your_Password"; WebServer server(80); bool ledState = false; void handleRoot() { String html = "<h1>ESP32 LED Control</h1>"; html += "<p>LED is: <b>" + (ledState ? "ON":"OFF") + "</b></p>"; html += "<a href='/on'><button>Turn ON</button></a> "; html += "<a href='/off'><button>Turn OFF</button></a>"; server.send(200, "text/html", html); } void setup() { pinMode(2, OUTPUT); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) delay(500); Serial.println(WiFi.localIP()); // Open this IP in browser server.on("/", handleRoot); server.on("/on", [](){ledState=true;digitalWrite(2,HIGH);handleRoot();}); server.on("/off",[](){ledState=false;digitalWrite(2,LOW);handleRoot();}); server.begin(); } void loop() { server.handleClient(); }

ESP32 Bluetooth

Send commands from your phone to the ESP32 via Bluetooth โ€” no WiFi needed. Perfect for wireless sensor displays and robot control.

#include "BluetoothSerial.h" BluetoothSerial SerialBT; void setup() { Serial.begin(115200); SerialBT.begin("ESP32_Robot"); // BT device name pinMode(2, OUTPUT); } void loop() { if (SerialBT.available()) { char cmd = SerialBT.read(); if (cmd == '1') digitalWrite(2, HIGH); if (cmd == '0') digitalWrite(2, LOW); SerialBT.print("Command received: "); SerialBT.println(cmd); } }
๐Ÿ“ฑ Phone App: Install "Serial Bluetooth Terminal" from the Play Store. Pair with "ESP32_Robot" and send '1' to turn LED on, '0' to turn off.

Raspberry Pi Pico

The RP2040-based Pico is a dual-core ARM Cortex-M0+ board from Raspberry Pi Foundation. Incredibly capable, programmable in Python, and costs just a few dollars.

RP2040 MICRO USB Raspberry Pi Pico
Raspberry Pi Pico
RP2040 ยท DUAL ARM CORTEX-M0+ ยท 133 MHz
The Pico excels at MicroPython and CircuitPython. It has 26 GPIO pins, 3 ADC channels, I2C, SPI, UART, and even Programmable I/O (PIO) for custom hardware interfaces. The Pico W adds built-in WiFi.
133 MHz
Dual Core
264 KB
SRAM
2 MB
Flash
26 GPIO
Pins

MicroPython Setup

MicroPython is a lean Python 3 implementation for microcontrollers. On the Pico, setup takes under 2 minutes!

  • 1

    Download the MicroPython .uf2 firmware from micropython.org/download/rp2-pico

  • 2

    Hold the BOOTSEL button on the Pico and plug it into your PC via USB. It appears as a USB drive called RPI-RP2.

  • 3

    Drag and drop the .uf2 file onto the RPI-RP2 drive. The Pico will reboot and MicroPython is now installed!

  • 4

    Install Thonny IDE (thonny.org) and select MicroPython (Raspberry Pi Pico) as the interpreter.

  • 5

    Click the Shell at the bottom and type: print("Hello Pico!") โ€” you should see a response!

# Blink LED on Raspberry Pi Pico with MicroPython from machine import Pin import utime led = Pin(25, Pin.OUT) # Built-in LED on GPIO 25 while True: led.value(1) # LED ON utime.sleep(0.5) led.value(0) # LED OFF utime.sleep(0.5)

Pico Projects

Here are some exciting projects to build with your Raspberry Pi Pico.

TEMPERATURE LOGGER WITH OLED DISPLAY

from machine import Pin, I2C, ADC import ssd1306, utime i2c = I2C(0, sda=Pin(0), scl=Pin(1)) oled = ssd1306.SSD1306_I2C(128, 64, i2c) sensor_temp = ADC(4) # Built-in temperature sensor while True: reading = sensor_temp.read_u16() * (3.3 / 65535) temp_c = 27 - (reading - 0.706) / 0.001721 oled.fill(0) oled.text("Pico Thermometer", 0, 0) oled.text(f"Temp: {temp_c:.1f} C", 0, 24) oled.show() utime.sleep(1)