Week 4:

Embedded Programming

This week we dove into the world of embedded programming — the process of developing software that directly controls physical hardware. We explored what microcontrollers are, how they work internally, and how to program them using different development boards and toolchains. We compared development boards, read datasheets, and wrote our first programs to interact with input and output devices. It was a foundational week that bridges hardware and software in a very hands-on way.

Datasheet Class Raspberry Pi Pico 2W ESP32 Pinout

Assignments

Group Assignment

  1. Demonstrate and compare the toolchains and development workflow for available embedded architectures.

Individual Assignment

  1. Browse through the datasheet for a microcontroller.
  2. Write and test a program for an embedded system using a microcontroller to interact (with input &/or output devices) and communicate (with wired or wireless connections).
  3. Extra credit:
    1. Assemble the system.
    2. Try different languages &/or development environments.

What is Embedded Programming?

Embedded programming is the process of developing software that controls physical electronic devices (hardware), especially microcontrollers, which act as the brain of the system. An embedded system is made up of three main components: sensors, a microcontroller, and actuators.

Sensors capture information from the environment. The microcontroller plays the central role: it receives that data, processes it according to the loaded program, and makes logical decisions in real time. Finally, the actuators carry out the corresponding physical action — such as turning on a motor, activating a light, or moving a mechanism.

🔍

Sensors

Capture information from the physical environment

🧠

Microcontroller

Processes data and makes real-time logical decisions

⚙️

Actuators

Execute the corresponding physical action

What are Microcontrollers?

A microcontroller is a complete system integrated into a single chip. It is important to distinguish it from a development board: the development board is the physical PCB (printed circuit board) that surrounds and supports the microcontroller chip, adding connectors, voltage regulators, USB ports, and other components that make it easy to program and prototype with. The microcontroller itself is just the chip — the brain — while the development board is the full tool you hold in your hands.

Internally, the microcontroller chip is made up of a microprocessor (CPU) that includes the ALU (Arithmetic Logic Unit), registers, and a control unit — all responsible for executing instructions and performing mathematical and logical operations.

In addition, the microcontroller integrates different types of memory:

It also incorporates peripherals such as:

The operation depends on an oscillator (sometimes with a quartz crystal) that generates the clock signal to synchronize all operations.

Thanks to this integration, the microcontroller can receive digital signals (0 and 1, like a button press) or analog signals (such as temperature or light), process them, and generate a corresponding action.

Microcontrollers on their own do not directly understand programming languages — they only understand binary language (0s and 1s). However, they can be programmed using Assembly, C, C++, MicroPython, and more.

Group Assignment — Compare the Toolchains and Development Workflows

Since it was our first time reading a microcontroller datasheet, our instructor gave us a quick explanation using the pin diagram (pinout) of the Raspberry Pi Pico 2 W as an example. With that diagram, we learned how to interpret what each label means, how to identify the function of each pin, and how to read this type of schematic.

Datasheet class explanation

Instructor explaining the pinout diagram of the Raspberry Pi Pico 2 W

01

Raspberry Pi Pico 2 W

ARM Cortex-M33
Raspberry Pi Pico 2W board Raspberry Pi Pico 2W pinout

The Raspberry Pi Pico 2 W is a development board with integrated WiFi, which allows it to be used in IoT (Internet of Things) projects — devices that can connect to the internet to send and receive data.

The board operates at 3.3V, so its pins deliver that same voltage. Although it can be powered with 5V from a laptop via USB, it includes a voltage regulator that steps it down to 3.3V for internal operation.

Its GPIO pins can be configured as digital inputs or outputs. It cannot directly measure analog signals; for that, it uses an ADC (analog-to-digital converter) that transforms the analog signal into digital data the microcontroller can process. It also supports communication protocols such as SPI, I2C, and UART for connecting to other devices. The red pin typically indicates 3.3V (positive) and the black corresponds to GND.

FeatureSpecification
Main MCURP2350 (ARM Cortex-M33 dual-core)
Total Pins40 (38 GPIO — 19 on each side)
Digital GPIOUp to 30 programmable pins
PWM16 hardware channels
Analog (ADC)12-bit ADC
SPI2 buses
I2C2 buses
UART2 ports
WirelessWiFi + Bluetooth (CYW43439)
Flash / RAM4 MB Flash / 520 KB SRAM

Microcontroller — RP2350

The RP2350 is a 32-bit ARM Cortex-M33 dual-core microcontroller. It is designed for higher performance and security compared to previous RP2040 versions. It includes programmable I/O blocks (PIO), which allow custom hardware communication protocols to be implemented in software.

Raspberry Pi Pico 2W block diagram RP2350 microcontroller
FeatureSpecification
ArchitectureARM Cortex-M33 (dual-core)
FrequencyUp to 150 MHz
SRAMUp to 520 kB
FlashExternal (typically 4 MB)
ADC12-bit
PWM16 channels
PIO2 programmable I/O blocks

Wireless Module — CYW43439

The Pico 2 W integrates the CYW43439 module for wireless communication, enabling WiFi and Bluetooth Low Energy connectivity.

FeatureSpecification
WiFi802.11 b/g/n (2.4 GHz)
BluetoothBLE 5.2
Operating Voltage3.3V

The Raspberry Pi Pico 2 W combines modern ARM architecture with integrated wireless communication. Its dual-core design and programmable I/O (PIO) blocks provide flexibility for advanced hardware control. It supports both traditional C/C++ development and alternative environments such as MicroPython.

Workflow Chain — Raspberry Pi Pico 2 W

The process starts by writing code in MicroPython using Thonny. The Pico 2 W also accepts C/C++ with the official SDK, but Thonny with MicroPython is more direct. Once the code is written, Thonny automatically uploads it to the board via USB without needing to compile or generate intermediate files. The board executes the program instantly, and results appear in the integrated Thonny console where errors can be seen and corrected without disconnecting anything.

StepDescription
1. Write codeIn C/C++ (official SDK) or MicroPython from VS Code or Thonny
2. CompileARM GCC compiler translates the code into RP2350 language
3. Generate binaryA .uf2 file ready to upload is produced
4. FlashPress BOOTSEL + USB, Pico appears as a storage drive, drag the .uf2
5. ExecuteThe board restarts automatically and runs the program
6. MonitorView results via VS Code or Thonny serial monitor

Toolchain — Raspberry Pi Pico 2 W

The Pico 2 W supports two paths: C/C++ with the official SDK (requiring ARM GCC, CMake, and generating a .uf2 file) or MicroPython with Thonny, which simplifies everything. With Thonny, the MicroPython firmware is flashed once to the board from within the program. From that point, Thonny acts as the entire toolchain: editor, uploader, and serial monitor in one tool — no external compiler or .uf2 files needed. Code is sent directly to the Pico via USB and runs immediately. It is the ideal workflow for rapid prototyping while maintaining full access to all RP2350 functions including GPIO, ADC, PWM, I2C, SPI, UART, and WiFi.

ToolPurpose
Pico SDKOfficial library to access RP2350 pins and functions
ARM GCCCompiles code for the Cortex-M33 processor
CMake + MakeOrganizes and builds the project
UF2 FormatFirmware file loaded via USB without extra hardware
VS Code + Pico ExtensionRecommended IDE; configures and compiles with one click
ThonnyMicroPython IDE; simpler and more direct
OpenOCD / SWDAdvanced debugging using a second Pico as debugger
02

Arduino UNO R4 WiFi

ARM Cortex-M4
Arduino UNO R4 WiFi board Arduino UNO R4 WiFi pinout

The Arduino UNO R4 WiFi is an upgraded version of the classic UNO platform. It is designed for embedded programming, rapid prototyping, and IoT applications. This board integrates a powerful 32-bit microcontroller and a WiFi/Bluetooth module, making it suitable for both control systems and wireless communication.

CategoryFunction
DigitalON/OFF control signals
PWMPower control (motors, LEDs)
AnalogVoltage reading
I2C2-wire communication
SPIHigh-speed communication
UARTSerial TX/RX
Power5V system supply
Main MCUR7FA4M1AB3CFM#AA0

Microcontroller — R7FA4M1AB3CFM#AA0

The R7FA4M1AB3CFM#AA0 is a 32-bit ARM Cortex-M4 based microcontroller. It operates at 5V logic level for compatibility with previous Arduino shields. It includes internal memory, ADC, DAC, timers, and advanced communication interfaces for industrial and embedded applications.

Arduino UNO R4 microcontroller chip Arduino UNO R4 microcontroller diagram
FeatureSpecification
Flash256 kB
SRAM32 kB
Data Flash8 kB (EEPROM)
ADC14-bit
DACUp to 12-bit
CANYes
DMAC4 channels

WiFi / Bluetooth Module — ESP32-S3-MINI-1-N8

The ESP32-S3 module acts as a secondary processor dedicated to wireless communication. It operates at 3.3V and communicates with the main MCU through a logic-level translator.

FeatureSpecification
WiFi2.4 GHz (802.11 b/g/n)
BluetoothBLE 5
SRAM512 kB
ROM384 kB
Operating Voltage3.3V

The Arduino UNO R4 WiFi represents a significant evolution from the classic UNO architecture. With a 32-bit ARM Cortex-M4 microcontroller and integrated wireless capabilities, it bridges the gap between beginner-friendly boards and more advanced embedded systems.

Workflow Chain — Arduino UNO R4 WiFi

The process starts by writing code in C/C++ from the Arduino IDE, the main tool for programming this board. Unlike the Raspberry Pi Pico, Arduino uses its own environment that greatly simplifies the process. Once the sketch is written, the IDE compiles it automatically using an ARM GCC compiler adapted for the Cortex-M4. The result is loaded directly to the board via USB with a single click — no button pressing or file dragging needed. The board runs the program immediately and results are monitored in the integrated Arduino IDE Serial Monitor.

StepDescription
1. Write codeIn C/C++ from the Arduino IDE (called a "sketch")
2. CompileArduino IDE uses ARM GCC to translate code for the Cortex-M4
3. Generate binaryA .hex or .bin file ready to upload is produced
4. FlashLoaded directly via USB with one click from the IDE
5. ExecuteThe board restarts automatically and runs the program
6. MonitorResults visible in the Arduino IDE Serial Monitor

Toolchain — Arduino UNO R4 WiFi

The toolchain for the Arduino UNO R4 WiFi is designed to be as simple and accessible as possible. The Arduino IDE concentrates almost the entire toolchain into one tool: editor, compiler, uploader, and serial monitor. Internally it uses the ARM GCC compiler to translate C/C++ code for the Cortex-M4 processor. The Arduino Core for Renesas provides all the libraries and drivers needed to access pins, WiFi, Bluetooth, and other board functions. The program is loaded via USB using the integrated bootloader, with no additional hardware required.

ToolPurpose
Arduino IDEMain environment: editor, compiler, and uploader in one
ARM GCCCompiles C/C++ code for the Cortex-M4 processor
Arduino Core (Renesas)Official libraries and drivers for all pins and modules
USB BootloaderLoads programs directly via USB without extra hardware
Serial MonitorDisplays program results in real time
VS Code + PlatformIOAdvanced alternative with more control over compilation and debugging
WiFiS3 LibraryOfficial library to control the ESP32-S3 module from code
03

Arduino UNO R3

8-bit AVR
Arduino UNO R3 board Arduino UNO R3 pinout

The Arduino UNO R3 is one of the most popular development boards for learning embedded systems. It is widely used in education and beginner projects to control LEDs, sensors, motors, and other electronic components. It provides a simple and accessible way to understand how hardware and software interact.

FeatureSpecification
Digital Pins14
PWM6
Analog Inputs6
Operating Voltage5V
Main MCUATmega328P

Microcontroller — ATmega328P

The ATmega328P is an 8-bit AVR microcontroller running at 16 MHz. It is simple, efficient, and widely supported. It integrates memory, timers, ADC, and communication interfaces in a single chip.

ATmega328P chip ATmega328P diagram
FeatureSpecification
Architecture8-bit AVR
Flash Memory32 kB
SRAM2 kB
EEPROM1 kB
ADC Resolution10-bit
Clock Frequency16 MHz

The Arduino UNO R3 is an ideal board for understanding the fundamentals of embedded systems. Its 8-bit architecture and simple development workflow make it highly suitable for beginners and educational environments. Although it has limited memory and processing power compared to modern boards, it remains a classic reference platform.

Workflow Chain — Arduino UNO R3

The code is written in C/C++ from the Arduino IDE. Upon clicking Upload, the AVR-GCC compiler translates it to a .hex file and AVRDUDE loads it into the ATmega328P's Flash memory through the bootloader via USB. The board restarts automatically, executes the program, and results are visible in the Serial Monitor.

StepDescription
1. Write codeIn C/C++ from the Arduino IDE (called a "sketch")
2. CompileAVR-GCC translates code to instructions for the 8-bit ATmega328P
3. Generate binaryA .hex file ready to upload is produced
4. FlashAVRDUDE communicates with the bootloader via USB and writes the .hex to Flash
5. ExecuteThe board restarts automatically and runs the program
6. MonitorResults visible in the Arduino IDE Serial Monitor

Toolchain — Arduino UNO R3

The Arduino IDE concentrates the entire toolchain into one tool. It uses AVR-GCC to compile for the 8-bit AVR architecture and AVRDUDE to transfer the program to the chip via the pre-flashed bootloader. No external hardware or additional configuration is required. Its only limitation is the lack of on-chip debugging, so errors can only be detected through the Serial Monitor.

ToolPurpose
Arduino IDEMain environment: editor, compiler, and uploader in one
AVR-GCCCompiles C/C++ code for the 8-bit AVR architecture of the ATmega328P
AVRDUDETransfers the .hex file to the microcontroller via USB and bootloader
Bootloader (pre-flashed)Allows loading programs via USB without external programmer hardware
Arduino Core LibrariesLibraries that simplify access to pins, ADC, timers, and UART
Serial MonitorDisplays program results in real time
04

Seeeduino XIAO nRF52840

ARM Cortex-M4F
Seeeduino XIAO nRF52840 board Seeeduino XIAO nRF52840 pinout

The Seeeduino XIAO nRF52840 is a compact and powerful development board designed for IoT and Bluetooth applications. Despite its small size, it integrates wireless communication and advanced low-power features.

FeatureSpecification
Digital PinsUp to 14
Analog InputsYes (12-bit ADC)
PWMYes
USBNative USB
Main MCUnRF52840

Microcontroller — nRF52840

The nRF52840 is a 32-bit ARM Cortex-M4F microcontroller optimized for wireless communication and low-power applications. It integrates Bluetooth and advanced peripherals for IoT systems.

nRF52840 block diagram
FeatureSpecification
ArchitectureARM Cortex-M4F (32-bit)
Flash Memory1 MB
RAM256 kB
ADC Resolution12-bit
BluetoothBLE 5.0
USBFull-speed USB 2.0

The Seeeduino XIAO nRF52840 is a compact and powerful development board based on a 32-bit ARM Cortex-M4 microcontroller with integrated Bluetooth Low Energy (BLE). Despite its small size, it offers strong processing capabilities and low power consumption.

Workflow Chain — Seeeduino XIAO nRF52840

The code is written in C/C++ from the Arduino IDE after installing the Seeed nRF52 Boards package. It also accepts MicroPython and CircuitPython. Upon clicking Upload, ARM GCC translates the code to instructions for the Cortex-M4F and transfers it to the chip via UF2 bootloader over USB-C. If the board is unresponsive, a double-click on the reset button activates USB storage mode to reactivate the port. The board executes the program immediately and results appear in the Serial Monitor.

StepDescription
1. Write codeIn C/C++ (Arduino IDE), MicroPython, or CircuitPython
2. CompileARM GCC translates code for the Cortex-M4F at 64 MHz
3. Generate binaryA .hex / .uf2 file ready to upload is produced
4. FlashLoaded via USB-C bootloader; double reset for storage mode if needed
5. ExecuteThe board restarts automatically and runs the program
6. MonitorResults visible in the Arduino IDE Serial Monitor

Toolchain — Seeeduino XIAO nRF52840

ToolPurpose
Arduino IDEMain environment: editor, compiler, and uploader in one
ARM GCCCompiles C/C++ code for the Cortex-M4F at 64 MHz
Seeed nRF52 BoardsOfficial library for BLE and low-power functions
Seeed nRF52 mbed-enabledLibrary for Machine Learning (TinyML) and advanced sensors
UF2 BootloaderLoads program via USB-C without external programmer hardware
Serial MonitorDisplays program results in real time
VS Code + PlatformIOAdvanced alternative with more control over compilation and debugging
SWD + JLinkAdvanced on-chip debugging to inspect the program during execution
05

ESP32 (ESP32-WROOM)

Xtensa LX6
ESP32 development board ESP32 pinout

The ESP32 development board is designed for IoT and wireless applications. It integrates a powerful dual-core processor and built-in WiFi and Bluetooth. It operates at 3.3V logic level and is widely used for smart devices, home automation, and wireless control systems.

FeatureSpecification
Digital GPIOUp to 34 pins
PWMHardware PWM (LEDC)
Analog12-bit ADC
DAC2 channels (8-bit)
SPI4 buses
I2C2 buses
UART3 ports
Main MCUXtensa LX6
WirelessWiFi + Bluetooth

Microcontroller — Xtensa LX6

The ESP32 uses a 32-bit dual-core Xtensa LX6 architecture. It is optimized for wireless communication and real-time applications. It integrates advanced peripherals, hardware encryption, and deep sleep modes for low power consumption.

Xtensa LX6 chip ESP32 microcontroller diagram
FeatureSpecification
ArchitectureXtensa LX6 (dual-core)
FrequencyUp to 240 MHz
SRAM520 kB
FlashExternal (usually 4 MB)
ADC12-bit
DAC2x 8-bit
WiFiIntegrated
BluetoothClassic + BLE

The ESP32 is a powerful dual-core microcontroller designed for IoT and wireless applications. Its integrated WiFi and Bluetooth capabilities make it ideal for connected systems. Compared to traditional Arduino boards, it offers significantly higher processing speed and memory, allowing for more complex and real-time applications.

Workflow Chain — ESP32 (ESP32-WROOM)

The code is written in C/C++ from the Arduino IDE with the ESP32 by Espressif package, or using ESP-IDF for advanced projects. The Xtensa GCC compiler translates it for the dual-core Xtensa LX6 processor and generates a .bin file. The esptool.py tool loads it via USB, sometimes requiring the BOOT button to be held during flashing. The board restarts automatically and results appear in the Serial Monitor.

StepDescription
1. Write codeIn C/C++ (Arduino IDE or ESP-IDF) or MicroPython
2. CompileXtensa GCC translates code for the dual-core Xtensa LX6 at 240 MHz
3. Generate binaryA .bin file ready to load into external Flash is produced
4. Flashesptool.py transfers the binary via USB; may require pressing BOOT during upload
5. ExecuteThe board restarts automatically and runs the program
6. MonitorResults visible in the Arduino IDE or ESP-IDF Serial Monitor

Toolchain — ESP32 (ESP32-WROOM)

ToolPurpose
Arduino IDE + ESP32 CoreAccessible environment with WiFi, BT, and dual-core support in Arduino syntax
Xtensa GCCCompiles C/C++ code for the Xtensa LX6 dual-core architecture at 240 MHz
esptool.pyOfficial Espressif tool to load firmware to Flash via USB
ESP-IDFProfessional framework with full chip access: FreeRTOS, dual-core, low power
FreeRTOSIntegrated real-time OS; allows tasks to run on both cores simultaneously
VS Code + PlatformIOAdvanced alternative compatible with Arduino and ESP-IDF
Serial MonitorDisplays program results in real time
06

Arduino Nano

8-bit AVR
Arduino Nano board Arduino Nano pinout

The Arduino Nano offers similar functionality to the UNO but in a much smaller form factor. It is commonly used in compact or space-limited projects, such as wearable devices or small embedded prototypes. It allows users to control electronic components while maintaining a minimal physical size.

FeatureSpecification
Digital Pins14
PWM6
Analog Inputs8
Operating Voltage5V
Main MCUATmega328P

Microcontroller — ATmega328P

The Arduino Nano uses the same 8-bit AVR ATmega328P microcontroller found in the Arduino UNO R3. It runs at 16 MHz and includes internal Flash memory, SRAM, EEPROM, ADC, timers, and communication interfaces.

ATmega328P chip on Nano Arduino Nano diagram
FeatureSpecification
Architecture8-bit AVR
Flash32 kB
SRAM2 kB
EEPROM1 kB
ADC10-bit
Frequency16 MHz

Difference Between Arduino Nano and Arduino UNO R3

Although both boards use the same microcontroller, the main differences are physical size and pin layout.

FeatureArduino NanoArduino UNO R3
SizeCompactLarger board
USBMini/Micro USBUSB Type-B
Analog Pins86
Shield CompatibilityNo direct shield stackingCompatible with Arduino shields
Form FactorBreadboard friendlyStandard Arduino layout

In summary, both boards behave almost identically in programming, but the Nano is preferred for compact designs, while the UNO is better for prototyping with shields.

Workflow Chain — Arduino Nano

Uses the same workflow as the UNO R3 since it shares the same ATmega328P microcontroller. The code is written in C/C++ in the Arduino IDE, AVR-GCC compiles it to a .hex file, and AVRDUDE loads it via USB through the bootloader. The board runs the program and results appear in the Serial Monitor.

StepDescription
1. Write codeIn C/C++ from the Arduino IDE
2. CompileAVR-GCC translates code for the 8-bit ATmega328P at 16 MHz
3. Generate binaryA .hex file ready to upload is produced
4. FlashAVRDUDE loads the .hex via USB through the pre-flashed bootloader
5. ExecuteThe board restarts automatically and runs the program
6. MonitorResults visible in the Arduino IDE Serial Monitor

Toolchain — Arduino Nano

ToolPurpose
Arduino IDEMain environment: editor, compiler, and uploader in one
AVR-GCCCompiles C/C++ code for the 8-bit AVR architecture
AVRDUDETransfers the .hex to the chip via USB and pre-flashed bootloader
Arduino Core LibrariesLibraries for accessing pins, ADC, timers, and UART
Serial MonitorDisplays program results in real time
07

Development Board Comparison

Summary
All development boards comparison
Feature UNO R3 Nano UNO R4 WiFi ESP32 Pico 2 W XIAO nRF52840
Main MCUATmega328PATmega328PR7FA4M1 (ARM M4)Xtensa LX6RP2350nRF52840
Architecture8-bit AVR8-bit AVR32-bit Cortex-M432-bit Xtensa (dual-core)32-bit Cortex-M33 (dual-core)32-bit Cortex-M4F
Clock Speed16 MHz16 MHz48 MHzUp to 240 MHzUp to 150 MHz64 MHz
Flash Memory32 kB32 kB256 kB~4 MB~4 MB1 MB
SRAM2 kB2 kB32 kB520 kB520 kB256 kB
ADC10-bit10-bit14-bit12-bit12-bit12-bit
DAC NoNo 12-bit2× 8-bit NoNo
Digital Pins141414Up to 34Up to 30Up to 14
Analog Inputs686Up to 183Yes
PWM666Hardware (LEDC)16 channelsYes
I2C111221
SPI111421
UART112321
USBUSB-BMini USBUSB-CMicro USBMicro USBUSB-C (native)
WiFi NoNo 2.4 GHz2.4 GHz 2.4 GHzNo
Bluetooth NoNo BLE 5Classic + BLE BLE 5.2BLE 5.0
Voltage5V5V5V3.3V3.3V3.3V
CAN Bus NoNo Yes NoNoNo
Low Power NoNoNo Deep sleepDormant modeUltra low power
Special FeatureShield compat.Compact UNODual processor (MCU + ESP32-S3)Dual-core FreeRTOSDual-core RISC-V compat.Tiny size, BLE optimized
Best ForEducation basicsCompact projectsIoT intermediateIoT advanced / smart homeIoT WiFi connectedWearables / low power
Price ~$5 ~$4 ~$27 ~$8 ~$7 ~$10

Final Decision

Having reviewed all available microcontrollers in my node, I decided to work with the ESP32 DEVKIT V4 with the ESP-WROOM-32 processor, programmed using Thonny. Its dual-core architecture, integrated WiFi and Bluetooth, high speed (240 MHz), and generous memory make it the most versatile board for the type of projects I have in mind.

Individual Assignment

Recently, specifically at the end of 2025, I took a course at Universidad del Pacífico where we learned to program in Arduino to develop a final project.

My project consisted of a smart garage — an embedded system controlled by an Arduino. It used a proximity sensor that emitted electromagnetic waves to detect when a person or vehicle was approaching, allowing the door to open or close automatically. It also incorporated a light sensor (LDR) that measured light intensity: if it was nighttime, it would turn on the light; during the day, it would turn it off. Additionally, it had a Bluetooth connection so a mobile application could function as a remote control to open and close the garage.

Smart garage project — Arduino-controlled embedded system

This experience gave me a solid foundation to start exploring other microcontrollers. However, to work with new boards it is necessary to understand the internal components and functions of microcontrollers, since they are the core of every embedded system.

ESP32 DEVKIT V4 (38-pin Slim Version) Datasheet

ESP32 DEVKIT V4 pinout diagram

ESP32 DEVKIT V4 — Full pinout reference

ESP32 DEVKIT V4 board ESP32 DEVKIT V4 pinout
Xtensa LX6 microcontroller ESP32 microcontroller diagram

I identified the components that are directly relevant to my smart menstrual product dispenser.

ESP32 Internal Architecture — Annotated for My Final Project

Each block is highlighted based on its relevance to the smart menstrual dispenser. Hover to expand details.

In-Package Flash / PSRAM
Stores the program code. Runs the full dispenser logic permanently without reloading.
SPI
High-speed bus. Could connect an SD card for logging dispense events.
I2C
2-wire protocol for connecting an OLED display or secondary sensors.
I2S
Audio interface. Not used in current design.
SDIO
SD card interface. Possible future use for data logging.
UART
Serial communication for programming and debugging the dispenser.
TWAI®
CAN bus protocol. Not required for this project.
ETH
Ethernet interface. WiFi is used instead for this project.
RMT
Remote control signal generator. Could drive IR or WS2812 LEDs for visual feedback.
PWM
Controls motor speed and dispensing time. Essential for precise 1-product-per-activation.
Touch Sensor
Capacitive touch pins. Alternative to buttons for triggering dispensing.
DAC
Analog output. Not needed in current design.
ADC
Analog-to-digital converter. Reads stock-level sensors. ADC1 preferred (ADC2 conflicts with WiFi).
Timers
Precise timing for motor activation. Prevents over-dispensing with timed pulses.
Bluetooth Link Controller
Handles BLE protocol stack. Enables low-energy connection with the mobile app.
Bluetooth Baseband
Physical BT layer. Manages the BLE signal for app communication.
Wi-Fi MAC
Manages WiFi access. Sends low-stock alerts and receives app commands.
Wi-Fi Baseband
Physical WiFi signal layer. Handles 2.4 GHz transmission.
Core and Memory
2 × Xtensa® 32-bit LX6 Microprocessors

The dual-core brain. Core 0 handles WiFi/BT stack; Core 1 runs the dispenser logic — sensor reading, motor control, stock monitoring — simultaneously.

ROM
SRAM
RTC
PMU
ULP Coprocessor
Recovery Memory

Real-Time Clock and ultra-low-power coprocessor. Could enable deep sleep between dispensing events to save battery.

RF Receive
Receives incoming WiFi and Bluetooth signals from the mobile app.
Clock Generator
Generates clock signals for synchronizing wireless modules.
RF Transmit
Sends notifications and status data to the mobile app.
Switch
Switches between WiFi and BT on the shared antenna.
Balun
Converts differential RF signal to single-ended for the antenna.
Cryptographic Hardware Acceleration
SHA
RSA
AES
RNG

Hardware encryption for secure app communication. Protects user data and health notifications.

Critical for project WiFi / BT GPIO / I/O Not used

Key Notes for My Final Project

⚙️ GPIO & Peripherals

  • Digital inputs → hand detection sensor
  • ADC1 → stock-level sensors
  • PWM → motor speed control
  • UART → programming & debugging
  • GPIO34–39: input only (good for sensors)
  • GPIO0: Boot pin — handle with care
  • 3.3V logic only — NOT 5V tolerant

📡 WiFi & Bluetooth

  • No external wireless module needed
  • Sends low-stock notifications
  • Receives app commands
  • Delivers motivational messages
  • ADC2 disabled when WiFi is active — use ADC1 only

🔁 PWM & Timers

  • Controls motor speed per compartment
  • Defines dispensing duration precisely
  • Prevents over-dispensing per activation
  • Ensures exactly 1 product released at a time

⚡ Power Management

  • Can be powered via USB, 5V, or 3V3 header
  • ⚠ Use only ONE power source at a time
  • Must ensure stable 3.3V supply
  • WiFi peaks require sufficient current
  • ESP32 cannot drive motors directly — use external driver (L298N / DRV8833)
ESP32 project setup

Setup Program Guide

In the Group Assignment Toolchain section for the ESP32, I mentioned several ways to program the board. Among those options, I chose Arduino IDE + ESP32 Core — the most accessible option, which allows using WiFi, Bluetooth, and dual-core in Arduino syntax.

Here are the steps I followed to set everything up.

01
Connect the ESP32 and Check for Drivers
Verify the board is recognized by Windows

Connect the ESP32 to your laptop with a USB Type-C cable and open Device Manager:

Windows Key + X → Device Manager → Ports (COM & LPT)

In my case, I saw a yellow warning sign next to the port — this meant the driver was missing and the laptop could not correctly read the ESP32.

Device Manager showing missing driver warning

Yellow warning sign in Device Manager — driver missing

This confirmed that the chip is a CP2102.

💡 If the driver is already installed and the port appears correctly, skip the next sub-steps and go directly to Step 2.

Install the CP2102 Driver:

  1. Go to: silabs.com/developers/usb-to-uart-bridge-vcp-drivers
  2. Download "CP210x Windows Drivers"
    Silicon Labs driver download page
  3. Extract the ZIP file
  4. Run CP210xVCPInstaller_x64.exe
    CP2102 installer executable
  5. Click Next → Next → Finish
  6. Open Device Manager again → Ports (COM & LPT)
    You should now see: Silicon Labs CP210x USB to UART Bridge (COM5)
02
Download Arduino IDE
From the official Arduino website

Download the Arduino IDE from: arduino.cc/en/software

I already had it installed from previous projects, so I skipped this step.

Arduino IDE interface

Arduino IDE — main interface

03
Add the ESP32 Board Manager URL
Register the Espressif boards in Arduino IDE

With Arduino IDE open:

  1. Go to File → Preferences (or Ctrl + ,)
    Arduino IDE Preferences menu
  2. Find the field "Additional boards manager URLs"
  3. Paste this URL:
    https://raw.githubusercontent.com/espressif/arduino-esp32/gh-pages/package_esp32_index.json
    Pasting the ESP32 board manager URL
  4. Click OK
04
Install the ESP32 Core
Add ESP32 support to the Arduino IDE
  1. Go to Tools → Board → Boards Manager
    Opening Boards Manager
  2. In the search box type: esp32
  3. Find esp32 by Espressif Systems and click Install
    Installing ESP32 Core by Espressif Systems
05
Select the Board
Tell Arduino IDE which ESP32 variant to use
Tools → Board → ESP32 Arduino → ESP32 Dev Module
Selecting ESP32 Dev Module

Selecting ESP32 Dev Module from the board list

06
Select the Port
Connect the IDE to the correct COM port
Tools → Port → COM5
Selecting the COM port

Selecting the COM5 port assigned to the ESP32

07
Upload My First Test Program
Blink the built-in LED on pin 2

This program turns the ESP32's built-in LED on and off every second — a classic first test to confirm the setup works.

Arduino C++ Blink — built-in LED (pin 2)
void setup() {
  pinMode(2, OUTPUT);
  Serial.begin(115200);
}

void loop() {
  digitalWrite(2, HIGH);   // LED on
  Serial.println("Hola");  // Print Hola
  delay(1000);              // wait 1 second
  digitalWrite(2, LOW);    // LED off
  Serial.println("Adios");  // Print Adios
  delay(1000);              // wait 1 second
}

📤 How to upload:

  1. Click the Upload → button
  2. Watch the console at the bottom
  3. When you see Connecting.... appear
  4. Press and hold the BOOT button on the ESP32
  5. Once uploading starts, release the button
Arduino IDE showing successful upload

Successful upload and the ESP32 LED blinking

Notes on Arduino IDE

En mi universidad llevé el curso de Física, donde nos enseñaron a programar en Arduino IDE. Gracias a eso adquirí un amplio conocimiento sobre códigos generales y el manejo de componentes especiales como pantallas LCD, sensores PIR de movimiento, sensor de humedad, buzzer, LEDs, entre otros.

Aquí estaré compartiendo mis apuntes de códigos de Arduino que realicé durante el curso, por si a alguien le pueden servir.

Algunas cosas clave a tener en cuenta en Arduino IDE: los comandos base más importantes son pinMode(2, OUTPUT) para declarar un pin como salida y digitalWrite(2, HIGH) para encenderlo. También es importante recordar que el delay() trabaja en milisegundos, por lo que si quieres esperar 1 segundo debes escribir delay(1000).

⬇ Download PDF

Any questions? Let's Contact

  • micaela.cordova.carmelino@gmail.com
  • ml.cordovac@alum.up.edu.pe
follow me: