Arduino Nano 33 IoT - Code Structure
To learn how to code for the Arduino Nano 33 IoT, you need to understand its code structure. This guide explains how the code for the Arduino Nano 33 IoT is organized.
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Basic Code Structure
The Arduino Nano 33 IoT sketch, also known as its code, is organized just like regular Arduino programs. It has two main sections: one to set things up and one that runs continuously.
Setup Code
- The setup code is the code inside the setup() function.
- The setup code runs as soon as the device is powered on or reset.
- The setup code runs only one time.
- The setup code is used to set up variables, define pin settings, and begin using libraries.
Loop Code
- The loop code is the code inside the loop() function.
- It runs right after the setup code.
- It runs over and over again without stopping.
- It handles the main job of the program.
Example
Detailed Instructions
If you are new to the Arduino Nano 33 IoT, be sure to check out our Getting Started with Arduino Nano 33 IoT tutorial. Then, follow these steps:
- Connect the components to the Arduino Nano 33 IoT board as depicted in the diagram.
- Use a USB cable to connect the Arduino Nano 33 IoT board to your computer.
- Launch the Arduino IDE on your computer.
- Select the Arduino Nano 33 IoT board and choose its corresponding COM port.
- Copy the code above and paste it into the Arduino IDE.
- Click the Upload button in the Arduino IDE to compile and send the code to your Arduino Nano 33 IoT board.
- Open the Serial Monitor in the Arduino IDE.

- Check the result on the Serial Monitor.
On the Serial Monitor, you can see that "This is Arduino Nano 33 IoT the setup code" prints only once, while "This is Arduino Nano 33 IoT loop code" prints many times. This means the setup part of the Arduino Nano 33 IoT code runs only one time, and the loop part runs many times. The setup code always runs first.
※ NOTE THAT:
When coding for an Arduino Nano 33 IoT, you must include both the setup() and loop() functions. If you leave them out, an error will occur.
Other Parts
Besides the setup and loop code, an Arduino Nano 33 IoT sketch can also have parts like these:
- Block comment: usually used to write some information about the author, the wiring instruction, the license ... Arduino Nano 33 IoT will ignore this part.
- Libraries inclusion: is used to include libraries into the sketch.
- Constant definition: used to define constant
- Global variables declaration
For instance:
Detailed Instructions
- Copy the code above and paste it into the Arduino IDE.
- Click the Upload button in the Arduino IDE to compile and send the code to your Arduino Nano 33 IoT board.
- Open the Serial Monitor in the Arduino IDE.

- Check the result on the Serial Monitor.
We don't need to understand each line of code right now. We only need to know the overall structure. Each line will be explained in future tutorials.