Now that the hardware configuration is complete, we can start writing some code to test our project. We'll first write a simple sketch to test a given relay. Go over to your Arduino IDE and you can start writing some code. The most important parts of the code will be detailed below, and you can find the complete code on the GitHub repository of the project at https://github.com/openhomeautomation/arduino-home-automation/tree/master/chapter2.
The first step is to declare which pin the relay you want to test is connected to:
const int relay_pin = 6;
We use a
const int variable here, which is similar to
#define but better, since we are sure the constant is of the right type. In the
setup() function of the sketch, ...