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.
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.