> For the complete documentation index, see [llms.txt](https://reacoda.gitbook.io/reacoda/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://reacoda.gitbook.io/reacoda/control-leds-using-nodemcu-and-micropython-part-1/using-micropython-on-thonny-ide.md).

# Using microPython on Thonny IDE to blink a built-in LED

In this tutorial, we will be setting and using microPython firmware on the Thonny IDE.

### Things Needed&#x20;

1. Windows computer&#x20;
2. Thonny IDE installed&#x20;
3. microPython Firmware installed&#x20;
4. NodeMCU dev kit and a USB cable&#x20;

### Getting Started

To start programming on your NodeMCU (esp8266) using Thonny IDE, you will need to open the Thonny IDE and then click on **Tools > Options** and select the **Interpreter tab.**

On the options, choose the **Micropython (esp8266)**  and then choose the port name (number ) to which your nodeMCU dev board is connected. In this case we chose COM11.

![](/files/-MBFB2iyumxsX3I0Sxbw)

Thonny should now be connected to your NodeMCU board and you should the following message on the shell window.

![](/files/-MBFFIp1DLrb15hwL9jk)

To test the configuration, type the command help() and see what you get in response. when everything is in order you should see the following.

![](/files/-MBFGTdcHK-0aAFXcv6A)

### &#x20;Testing MiicroPython&#x20;

Write the following commands on the Thonny IDE and execute them to light up the on-board LED&#x20;

```
>>> from machine import Pin 
>>> Pin(2, Pin.OUT).value(0)
```

![](/files/-MBJEONmNuhGLToqaYZR)

When using the esp8266 board, the logic works in the opposite. That is to say, the value () argument will be 0 instead of 1 which is usually reserved for "ON".

### Blinking the built-in LED&#x20;

In this section, we will be programming the nodeMCU board to blink it's built-in LED. The following script will be run on the Thonny IDE's editor.

![](/files/-MBJks1Xe0WDQjFxkA1e)

N.B. when uploading the code as ledblink.py it will be saved as main.py on the board regardless of what you saved it as on your computer.&#x20;

Once you are done uploading the code press the Reset (RST) button on the board.

### Explanation of the code:

```
from machine import Pin 
```

Here we are importing a module called machine and from it we are accessing the class.

```
from time import sleep
```

From the module time we get the class sleep.&#x20;

```
led = Pin(2, Pin.OUT)
```

Here we create a Pin object called led. We are using the pin 2 that is where the built-in LED is connected. The pin is also declared as an output device.&#x20;

&#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://reacoda.gitbook.io/reacoda/control-leds-using-nodemcu-and-micropython-part-1/using-micropython-on-thonny-ide.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
