Tutorial 2 - Hello LED

YouTube Video

Introduction

Turning an LED on and off is often called the “Hello World” of hardware programming. It’s the simplest way to test that your board is working and to learn the basics of controlling a digital output pin. Just like printing “Hello World” in software shows you the language syntax, blinking an LED introduces you to hardware timing and pin control.

With the ESP32-S3 Pico, we can start with a basic blink example and then expand into something more exciting—the classic Knight Rider effect, where multiple LEDs sweep back and forth in sequence. This builds directly on the first program and shows how simple concepts scale into more dynamic projects.

Turning LED On / Off

Components Needed

ComponentQuantity
ESP32S3 Pico1
USB C Cable1
Breadboard1
WiresSeveral
Resistor1 (330Ω)
LED1

Fritzing Diagram

Code

from machine import Pin
import utime

led = Pin(40, Pin.OUT)
while True:
    led.value(1)
    utime.sleep(2)
    led.value(0)
    utime.sleep(2)

Code Explanation

from machine import Pin
import utime

These lines import two MicroPython modules, Pin from the machine module and utime. The Pin class is used to represent a pin on the ESP32S3 Pico and utime provides functions for working with time.

led = Pin(40, Pin.OUT)

This line sets up a Pin object for pin 40 on the ESP32S3 Pico, and sets it to be an output pin (i.e., one that can be used to control a device like an LED). The Pin constructor takes two arguments: the pin number, and the mode (in this case, Pin.OUT).

while True:
    led.value(1)
    utime.sleep(2)
    led.value(0)
    utime.sleep(2)

This is the main loop of the program, which will run indefinitely (since True is always true). The loop consists of two steps:

  1. Turn the LED on by setting the value of the led pin to 1 (which will typically result in the LED being illuminated).
  2. Wait for 2 seconds using the utime.sleep function.
  3. Turn the LED off by setting the value of the led pin to 0 (which will typically result in the LED being turned off).
  4. Wait for another 2 seconds using the utime.sleep function.

This loop will repeat indefinitely, resulting in the LED blinking on and off every 2 seconds.