> For the complete documentation index, see [llms.txt](https://brlabelectronics.gitbook.io/tutorials-1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://brlabelectronics.gitbook.io/tutorials-1/control-relays-with-the-nextion-hmi-and-arduino/nano-every-code/writing-the-code/void-setup.md).

# void setup()

This section of the code is executed once at startup. This is were you can initialize code or just run a task once when the device first powers on.&#x20;

For this application I need to open the serial port that the Nextion will use to send messages to the Arduino Nano Every. I also need to define the relay pins as outputs.

```arduino
void setup() {
  // open serial port with computer; use for debugging  
  //Serial.begin(9600); 
  
  // open serial port between HMI and Arduino Nano Every; recieve and send messages
  Serial1.begin(9600); 

  pinMode(relay1, OUTPUT); // configure relay 1 pin as an output
  pinMode(relay2, OUTPUT); // configure relay 2 pin as an output
}
```
