Reader small image

You're reading from  Arduino Home Automation Projects

Product typeBook
Published inJul 2014
Publisher
ISBN-139781783986064
Edition1st Edition
Tools
Right arrow
Author (1)
Marco Schwartz
Marco Schwartz
author image
Marco Schwartz

Marco Schwartz is an electrical engineer, entrepreneur, and blogger. He has a master's degree in electrical engineering and computer science from Supélec, France, and a master's degree in micro engineering from the Ecole Polytechnique Fédérale de Lausanne (EPFL), Switzerland. He has more than five years' experience working in the domain of electrical engineering. Marco's interests center around electronics, home automation, the Arduino and Raspberry Pi platforms, open source hardware projects, and 3D printing. He has several websites about the Arduino, including the Open Home Automation website, which is dedicated to building home automation systems using open source hardware. Marco has written another book on home automation and the Arduino, called Home Automation With Arduino: Automate Your Home Using Open-source Hardware. He has also written a book on how to build Internet of Things projects with the Arduino, called Internet of Things with the Arduino Yun, by Packt Publishing.
Read more about Marco Schwartz

Right arrow

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

pinMode(relay_pin,OUTPUT);

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

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Arduino Home Automation Projects
Published in: Jul 2014Publisher: ISBN-13: 9781783986064

Author (1)

author image
Marco Schwartz

Marco Schwartz is an electrical engineer, entrepreneur, and blogger. He has a master's degree in electrical engineering and computer science from Supélec, France, and a master's degree in micro engineering from the Ecole Polytechnique Fédérale de Lausanne (EPFL), Switzerland. He has more than five years' experience working in the domain of electrical engineering. Marco's interests center around electronics, home automation, the Arduino and Raspberry Pi platforms, open source hardware projects, and 3D printing. He has several websites about the Arduino, including the Open Home Automation website, which is dedicated to building home automation systems using open source hardware. Marco has written another book on home automation and the Arduino, called Home Automation With Arduino: Automate Your Home Using Open-source Hardware. He has also written a book on how to build Internet of Things projects with the Arduino, called Internet of Things with the Arduino Yun, by Packt Publishing.
Read more about Marco Schwartz