yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
ESP32 Core Board📖
1. ESP32 Introduction
  • 1. ESP32S3 Overview
  • 2. Environment Setup Introduction
  • 3. Dev Board Introduction
2. ESP-IDF Development Tutorial
1. Before Development
  • 1. Environment Setup (Windows)
  • 2. Environment Setup (Linux)
  • 3. Build and Flash
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. ESP_TIMER
  • 5. GPTIMER
  • 6. Watchdog Timer
  • 7. DMA
  • 8. ADC
  • 9. PWM Breathing LED
  • 10. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication Experiment
  • 2. I2C_OLED Display Experiment
  • 3. SPI Bus Communication Experiment
  • 4. PSRAM External Memory Experiment
  • 5. Flash Read and Write Experiment
  • 6. USB Emulated Mass Storage Experiment
4. FreeRTOS operating system
  • 1.FreeRTOS Core Concepts Theory
  • 2.Task Creation and Management
  • 3.Queue
  • 4.Binary Semaphore
  • 5.Mutex
  • 6.Event Groups
  • 7.Software Timer
  • 8.Task Scheduler
  • 9.Low Power Mode
  • 10.Deadlock
  • 11.Priority Inversion
5. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Client Experiment
  • 5. UDP Server Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. Socket Programming Basics
  • 9. HTTP Client Experiment
  • 10. HTTP Server Experiment
  • 11. MQTT IoT Communication Protocol
  • 12. WIFI OTA Upgrade
  • 13. Bluetooth Fundamentals
  • 14. Bluetooth Slave Mode
  • 15. Bluetooth Master Mode
6. Audio Applications
  • 1.I2S Microphone Recording and U-Disk Playback
  • 2.I2S Audio Playback Experiment
  • 3.Repeater Experiment
7. Xiaozhi AI Voice
  • 1. Burn Xiaozhi Firmware
  • 2. Network and Configuration
  • 3. AI Agent Settings
  • 4. Program Analysis
  • 5. Free Chat
3. Arduino Development Course
1. Before Development
  • 1. Environment Setup
  • 2. Build and Flash
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. ESP_TIMER
  • 5. GPTIMER
  • 6. Watchdog Timer
  • 7. ADC
  • 8. PWM Breathing LED
  • 9. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication
  • 2. I2C OLED Display
  • 3. SPI Bus Communication
  • 4. Flash Read and Write
  • 5. USB Emulated Mass Storage
4. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Server Experiment
  • 5. UDP Client Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. HTTP Client Experiment
  • 9. HTTP Server Experiment
  • 10. MQTT IoT Communication Protocol
  • 11. WIFI OTA Upgrade
  • 12. Bluetooth Fundamentals
  • 13. Bluetooth Slave Mode
  • 14. Bluetooth Master Mode
5. Audio Applications
  • 1.I2S Microphone Recording and U-Disk Playback
  • 2.I2S Audio Playback Experiment
  • 3.Repeater Experiment
4. MicroPython Development Course
1. Before Development
  • 1. Environment Setup
  • 2. Build and Flash
  • 3. Thonny IDE
2. Basic Peripherals
  • 1. LED Control
  • 2. Button Detection
  • 3. Peripheral Interrupts
  • 4. TIMER_IT
  • 5. Watchdog Timer
  • 6. ADC
  • 7. PWM Breathing LED
  • 8. RGB LED Effects
3. Serial Communication and Storage System
  • 1. Serial UART Communication Experiment
  • 2. I2C_OLED Display Experiment
  • 3. SPI Bus Communication Experiment
  • 4. Flash Read and Write Experiment
  • 5. Print Storage
4. Network Protocols and Wireless Communication
  • 1. WIFI Network Basics
  • 2. WIFI STA Mode
  • 3. WIFI AP Mode
  • 4. UDP Client Experiment
  • 5. UDP Server Experiment
  • 6. TCP Client Experiment
  • 7. TCP Server Experiment
  • 8. HTTP Client Experiment
  • 9. HTTP Server Experiment
  • 10. MQTT
  • 11. Bluetooth Fundamentals
  • 12. Bluetooth Slave Mode
  • 13. Bluetooth Master Mode
5. Audio Applications
  • 1. I2S Audio Playback Experiment
  • 2. Repeater Experiment
Download
  • Code
  • Hardware_Info
  • 3D_Model_File
  • Software_Tools
  • VMware
  • VM_File
Download ZIP

Welcome to ESP32 Core Board repository

1. LED Control

LED Control


LED Control1. LED Control Overview2. Core Concepts2.1 Common Anode Configuration2.2 Core API3. Hardware Dependencies4. Project Architecture and Flow5. Source Code Details5.1 File Header and Macros5.2 setup() — Initialization5.3 loop() — Main Loop6. Operation Flow6.1 Build and Flash6.2 Normal Behavior6.3 Verification Methods7. Common Issues


1. LED Control Overview

GPIO is the most fundamental peripheral interface of MCUs. Pins can be configured as output mode via software to drive external circuits. This experiment demonstrates the basic usage of three core functions (pinMode, digitalWrite, delay) by blinking two onboard LEDs synchronously at 1Hz.

Typical Application Scenarios:

Application TypeExample
Digital OutputLED blinking, relay control, buzzer driving
Digital InputButton detection, switch state reading, sensor digital signals
Bidirectional I/OI2C bus (SDA), single-wire protocol
Interrupt InputExternal event triggering
Analog InputADC sampling
Multiplexed FunctionsUART / SPI / I2C / PWM and other peripheral signals

2. Core Concepts

2.1 Common Anode Configuration

The onboard LEDs use common anode configuration: anode is fixed at 3.3V, cathode connects to GPIO through a current-limiting resistor.

VDD(3.3V) → LED anode → LED cathode → current-limiting resistor → GPIO pin
GPIO OutputLED StatePrinciple
LOW (0V)ONGPIO pulls internal to GND, current flows through LED
HIGH (3.3V)OFFGPIO at same potential as VDD, no current

digitalWrite(pin, LOW) = ON, which is the opposite of the intuition "1=ON". Refer to the table above to understand.

2.2 Core API

pinMode(pin, mode) — Configures GPIO direction.

modeDescription
OUTPUTPush-pull output, can drive ~10mA, suitable for LED
INPUTHigh-impedance input (floating level is uncertain, not used alone)
INPUT_PULLUPInput + internal ~45kΩ pull-up

digitalWrite(pin, value) — Writes GPIO output level. LOW = 0V, HIGH = 3.3V. Writes directly to register, single call < 0.1μs.

delay(ms) — Blocking delay, underlying is FreeRTOS vTaskDelay(): task enters Blocked state and yields CPU, automatically wakes up when expired.

Do not use for loop busy-wait — it will starve IDLE and trigger watchdog.


3. Hardware Dependencies

GPIOPeripheralModeDescription
43LED0OUTPUTOnboard LED, common anode, LOW=ON
44LED1OUTPUTSame as above

Both LEDs are onboard, no external components required.


4. Project Architecture and Flow

​x
setup()                     // Executes only once
  ├─ pinMode(43, OUTPUT)    // GPIO43 push-pull output
  └─ pinMode(44, OUTPUT)    // GPIO44 push-pull output

loop()                      // Infinite loop
  ├─ digitalWrite(43, LOW)  // ON
  ├─ digitalWrite(44, LOW)
  ├─ delay(500)             // Hold for 500ms
  ├─ digitalWrite(43, HIGH) // OFF
  ├─ digitalWrite(44, HIGH)
  └─ delay(500)             // Hold for 500ms → back to start

5. Source Code Details

Full source code: Source Code → Arduino → 1.Basic Peripherals → 1.GPIO_LED → 1.GPIO_LED.ino

5.1 File Header and Macros

Define pin numbers first, then reference all GPIO operations through macro names for better readability and easier modification.

xxxxxxxxxx
#define LED0_PIN  43   // Onboard LED0
#define LED1_PIN  44   // Onboard LED1

digitalWrite(LED0_PIN, LOW) is instantly recognizable as operating LED0, compared to digitalWrite(43, 0); if hardware revision moves LED to GPIO48, only one macro line needs changing.

5.2 setup() — Initialization

Configure both GPIOs as output mode so they can drive the LEDs.

xxxxxxxxxx
void setup() {
  pinMode(LED0_PIN, OUTPUT);
  pinMode(LED1_PIN, OUTPUT);
}

pinMode(pin, OUTPUT) calls gpio_set_direction() underneath, setting GPIO to push-pull output with ~10mA drive current.

5.3 loop() — Main Loop

ON then OFF, each delay 500ms. The repeated execution of loop() creates 1Hz blinking. In common anode configuration, LOW=ON — when GPIO pulls low, current flows through LED to GND, LED illuminates.

xxxxxxxxxx
void loop() {
  // ON — LOW: GPIO pulls to GND, LED has voltage difference
  digitalWrite(LED0_PIN, LOW);
  digitalWrite(LED1_PIN, LOW);
  delay(500);

  // OFF — HIGH: GPIO pulls to 3.3V, LED at equal potential
  digitalWrite(LED0_PIN, HIGH);
  digitalWrite(LED1_PIN, HIGH);
  delay(500);
}

digitalWrite writes directly to GPIO output register, single call < 0.1μs. delay(500) uses vTaskDelay() underneath, task enters Blocked state and yields CPU, automatically wakes up after 500ms, completely different from busy-wait.


6. Operation Flow

6.1 Build and Flash

Arduino flash process: See Arduino → 1. Before Development → 2. Build and Flash.

6.2 Normal Behavior

After power-on, both LEDs blink synchronously at 1Hz: ON 500ms → OFF 500ms → repeat.

LED灯闪烁例程(亮)

LED灯闪烁例程(灭)

6.3 Verification Methods

OperationExpected Result
Power on and observeBoth LEDs blink synchronously, period ~1s
Change delay(500) to delay(100)Blinking significantly faster, ~5Hz
Comment out only one digitalWriteOnly one LED blinks

7. Common Issues

PhenomenonCauseSolution
Build fails "LED0_PIN was not declared"Macro definition commented or deletedConfirm #define LED0_PIN 43 exists
LED does not light upPin number inconsistent with board silkscreenConfirm GPIO43/44
LED always stays onCommon anode/common cathode reversedSwap LOW/HIGH
Button unresponsive during delay()delay is blockingSee button detection experiment for non-blocking solutions
Build and Flash
Button Detection

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文