> 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/define-global-variables.md).

# Define Global Variables

Now we need to define some global variables that the code will use to define things such as digital outputs and string variables to store messages in.

```arduino
const int relay1 = 7; // relay 1 is on digital pin 7
const int relay2 = 8; // relay 2 is on digital pin 8

String cmd =""; // string variable to store messages in
```

We need to be able to control each relay with a digital I/O pin from the device thus we define a variable that is of the constant integer type and set it equal to the I/O pin that is going to be used to send the signal to the circuit that will energize the relay coil. In this case I am going to use D7 for relay 1 and D8 for relay 2.

A constant integer means that the variable can not be redefined later in the code.

We also need a string variable to store the serial data in so that they can be proccessed.&#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, and the optional `goal` query parameter:

```
GET https://brlabelectronics.gitbook.io/tutorials-1/control-relays-with-the-nextion-hmi-and-arduino/nano-every-code/writing-the-code/define-global-variables.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
