1.2 LED Blinking
This example blinks an LED on and off with the Soldered NULA MINI board. This is usually the very first project when learning microcontrollers because it introduces you to the most fundamental concept: making a pin go high (on) or low (off).
In this documentation you will learn:
- How to assign a pin to a variable for easier code management.
- How to configure a pin as an output with
Pin.OUT. - How to control pin states with
value()(1 and 0) - How to use
time.sleep()to pause program execution
Hardware required:
- 1x Soldered NULA MINI board
- 1x Breadboard
- 1x LED (any color)
- 1x 330 ohm resistor
- Jumper wires
- USB-c cable
Putting the components together
Build the circuit first. Work through the steps in order, because each one depends on the one before it.
1. Insert the NULA MINI board on the breadboard
If your board has male headers soldered to its pins, push it into the breadboard. Connecting everything else is easier and tidier that way.

If it does not, wire the components straight to the board instead. It is messier, but it works.
2. Connect the LED to the NULA MINI board
Take a piece of jumper wire and connect one end to an available GPIO pin on the board. For the needs of this example, we will be using the IO4 pin. Connect the other end to any free (meaning nothing is connected to it!) row on the breadboard.

Take one 330 ohm resistor and connect one end to the same row as the wire. Connect the other end of the resistor to some other free row.

Look at the two legs of the LED. One is longer than the other:

Connect the longer one (Anode) to the row that is connected to the other end of the 330 ohm resistor.

The shorter leg, the cathode, goes to the GND pin on the NULA board.
Connect the NULA MINI board to your computer via USB-c cable:

Importing what we need
MicroPython keeps the code that talks to the hardware in modules, and you have to import the parts you want before you can use them. The machine module holds everything hardware related, and Pin is the part of it that controls a single pin. The time module is what lets us pause the program.
from machine import Pin
import time
lib folder, as described on the Setting up MicroPython page.Assigning pins to variables
Instead of writing the pin number directly into every function call, you can store it in a variable for better readability. In this example, the variable PIN_NUMBER is assigned the value 4, which corresponds to the IO4 pin on the NULA board. If you decide to change the LED to another pin later, you only need to modify the variable in one place, and the rest of the code will still work.
Any pin marked IO will do. The diagram below shows all of them:

We declare both variables at the top of the file, before anything uses them:
# This is a variable to which we pass the number of pin that we had connected the LED to.
# The NULA board has a pin naming logic as follows: IO4, where 4 is the number that we give to the variable.
PIN_NUMBER = 4
# This is a variable that defines the blinking time, in seconds.
DELAY_S = 1
delay(1000) in a sketch and time.sleep(1) here both wait one second. Passing 1000 to time.sleep() would freeze the LED for over sixteen minutes.PIN_NUMBER and DELAY_S are a Python convention for values that are not meant to change while the program runs. Nothing stops you from writing them in lowercase, but the capitals tell anyone reading the code that these are settings rather than working variables.Configuring a pin as an input or an output
Every IO pin on the NULA MINI can act as either an input (reading signals from buttons, sensors, etc.) or an output (sending signals to LEDs, buzzers, motors, etc.). In this project, since the LED is a component we want to control, the pin must be set as an output. By default, pins do not "know" whether they should listen for signals or send out signals.

In MicroPython you do not call a separate function for this the way pinMode() works in Arduino. Instead, you say what the pin is for at the moment you create it. Pin(PIN_NUMBER, Pin.OUT) creates an object that stands for IO4 and configures it as an output in the same breath. We store that object in a variable called led, and from then on we talk to the pin through it.
led = Pin(PIN_NUMBER, Pin.OUT)
Passing Pin.OUT means the pin will write a value. Pin.IN would mean the opposite, that the pin listens for a signal coming from the outside, such as the state of a pushbutton. An input can take a third argument on top of that, Pin.PULL_UP, which switches on an internal resistor to keep the pin in a known state when nothing is driving it. It goes in a slot of its own rather than replacing Pin.IN, so the full line reads Pin(BUTTON_PIN, Pin.IN, Pin.PULL_UP). You will meet it in 2.1 Button Counter.
Repeating forever
An Arduino sketch is built from two functions: setup() runs once and loop() runs over and over by itself. MicroPython has neither. It reads your file from the first line to the last and then stops, so if you want something to repeat you have to say so yourself, with a loop.
A while loop keeps running the block indented under it for as long as its condition is true. Because True is always true, this loop never ends and the code inside keeps running until you stop the program.
while True:
# everything indented under here repeats forever
Controlling pin states with value()
Once the pin has been configured as an output, you control its state with the value() function. Writing led.value(1) sets the pin to a logic high level (3.3 V on the NULA MINI board), which allows current to flow through the connected circuit, in this case turning the LED on. Writing led.value(0) sets the pin to 0 V, which stops the current flow and turns the LED off.
while True:
led.value(1) # Turn the LED on
led.value(0) # Turn the LED off
HIGH and LOW, MicroPython uses the numbers 1 and 0. They mean exactly the same thing.If you run the code as it stands above, the LED will not appear to blink at all. The two lines run one after another in a few millionths of a second, far faster than your eye can follow, so the LED simply looks dimly lit all the time.
Pausing program execution
To make the blinking visible, we use time.sleep(), which pauses the program for the number of seconds you pass it. Our DELAY_S is 1, so each pause lasts one second: the code turns the LED on, waits a second, turns it off, waits another second, and then the loop starts again from the top.
while True:
# value() changes what our pin writes. As we are working with a digital pin, we can only switch
# between two values, high and low, written here as 1 and 0. On the NULA board, high is 3.3V
# while low is 0V. We start by putting the pin high, giving the LED 3.3V and lighting it up.
led.value(1)
# time.sleep() starts a pause in the code. Its duration is given in seconds.
time.sleep(DELAY_S)
# We put the pin low, turning the LED off.
led.value(0)
# Leave the LED turned off for a bit.
time.sleep(DELAY_S)
Try changing DELAY_S to 0.5 and running it again. Unlike the Arduino delay() function, which only accepts whole milliseconds, time.sleep() happily takes a decimal number, so half a second is a perfectly valid pause.
Full example
Check out the full example code on the link below:
1.2_LED_blinking.py
Example that shows how to control the blinking of a simple LED