Book Image

Arduino Home Automation Projects

By : Marco Schwartz
Book Image

Arduino Home Automation Projects

By: Marco Schwartz

Overview of this book

Table of Contents (14 chapters)
Arduino Home Automation Projects
About the Author
About the Reviewers

Testing the relays and Wi-Fi connection

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

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, we need to specify that this pin is a digital output with the pinMode() function:


Then, inside the loop() function, we are basically going to activate the relay, wait for 5 seconds, switch it off again, wait for 5 seconds...