Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Free Learning
Arrow right icon
Arduino Home Automation Projects
Arduino Home Automation Projects

Arduino Home Automation Projects: Automate your home using the powerful Arduino platform.

Arrow left icon
Profile Icon Marco Schwartz
Arrow right icon
Can$12.99 Can$26.99
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (10 Ratings)
eBook Jul 2014 132 pages 1st Edition
eBook
Can$12.99 Can$26.99
Paperback
Can$32.99
Subscription
Free Trial
Arrow left icon
Profile Icon Marco Schwartz
Arrow right icon
Can$12.99 Can$26.99
Full star icon Full star icon Full star icon Full star icon Empty star icon 4 (10 Ratings)
eBook Jul 2014 132 pages 1st Edition
eBook
Can$12.99 Can$26.99
Paperback
Can$32.99
Subscription
Free Trial
eBook
Can$12.99 Can$26.99
Paperback
Can$32.99
Subscription
Free Trial

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Arduino Home Automation Projects

Chapter 2. Control Lights from Your Phone or Tablet

In this chapter, we are going to tackle another very common project in any home automation project: controlling lights. There are many devices that you can buy off the shelves that will give you the ability to control devices in your home, but these devices usually have a high price point. And even if they are wireless, they usually come with a remote control.

In this project, we are going to take another approach and control lights directly from your computer, phone, or tablet, all via Wi-Fi. The following will be the major takeaways from this chapter:

  • First, we are going to build the hardware part of our project by connecting a Wi-Fi chip to Arduino and the device we want to control (here, a simple lamp) to a relay module. We'll actually use two relay modules in this project, but this can, of course, be extended to any number you want.
  • Then, we are going to write some basic code to test the different parts of the project...

Hardware and software requirements

Let's first see what you will need to create this project. Similar to many other projects of this book, this project is based on the Arduino platform, and we will once again use an Arduino Uno board. Note that an Arduino Mega board will work as well.

Then, you also need some relay modules so that you can control the lamps. A relay is basically an electromechanical switch. They are usually used when you want to command a high voltage device (for example, a lamp plugged into a wall socket) with a much smaller command voltage (for example, the 5V of the Arduino board). For more information on relays, you can visit the following web page:

http://en.wikipedia.org/wiki/Relay

For this project, I used a 5V relay module from Polulu that can handle up to 250V (thus supporting 110V and 230V devices) and a maximum of 10 A. The following image displays the relay module:

Hardware and software requirements

I used two of them, as I want to command two lamps from my Arduino board. Of course, the project...

Hardware configuration

Let's now see how to connect the different parts of the project. We are first going to take care of connecting all the components to the Arduino board, basically the relay module and the CC3000 Wi-Fi chip. To give you an idea, this is what you should end up with:

Hardware configuration

To know exactly which wires and pins you have to connect, the following image describes all the connections of the project:

Hardware configuration

Note that this schematic only displays the connections for one relay module. Let's first see how to connect a single relay module. To get started on the hardware connection, first place the different components next to each other and plug the CC3000 module on the breadboard. We are first going to take care of the power supply part. Connect the ground (GND) pin of the Arduino board to the GND pin of the CC3000 board. Then, connect the Arduino Uno board 5V pin to the Vin pin of the CC3000 board.

Now, let's look at the CC3000 chip. There are quite a few pins to connect to the...

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

Building a graphical interface to control the relays

Although it's good to use commands directly inside your browser to test the project, it's not so convenient to actually use the project for daily use. That's why we are going to build a dedicated interface so that you can control your relays from your computer, just by clicking on some buttons.

Since we'll use web technologies to do so, this interface will also be accessible from your mobile phone or tablet, as long as you are connected to the same Wi-Fi network.

Just as seen in the first chapter of this book, we are going to use a mix of HTML, CSS, JavaScript, and PHP to build the interface. Let's first see the important part of the HTML file. It is basically composed of several blocks, each corresponding to a relay. For each relay, there are two buttons: one to set the relay on and one to set it off. The following is the code which is responsible for that part:

<div class="relayBlock"><span class...

Testing the graphical interface

It's now time to test the interface. Make sure that the web server is running on your computer. Also, make sure that all the files of the interface are placed inside a folder at the root of your web server. You can go over to this folder in your browser (by typing in localhost) and open the HTML file. This is what you should see:

Testing the graphical interface

To test the interface, simply try to click on these different buttons. You will see that the lights switch instantly whenever you press the right button. If it doesn't work at this point, there are several things you can check.

The first thing is to check that your web server is running correctly. Also, check that you have entered the right name for your Arduino board (or the right IP address) inside the PHP file. Finally, make sure that your Arduino sketch is working correctly by typing the commands inside your web browser directly. Also, note that at this point, you should also have set the relay pins to be outputs, as...

Hardware and software requirements


Let's first see what you will need to create this project. Similar to many other projects of this book, this project is based on the Arduino platform, and we will once again use an Arduino Uno board. Note that an Arduino Mega board will work as well.

Then, you also need some relay modules so that you can control the lamps. A relay is basically an electromechanical switch. They are usually used when you want to command a high voltage device (for example, a lamp plugged into a wall socket) with a much smaller command voltage (for example, the 5V of the Arduino board). For more information on relays, you can visit the following web page:

http://en.wikipedia.org/wiki/Relay

For this project, I used a 5V relay module from Polulu that can handle up to 250V (thus supporting 110V and 230V devices) and a maximum of 10 A. The following image displays the relay module:

I used two of them, as I want to command two lamps from my Arduino board. Of course, the project will...

Left arrow icon Right arrow icon

Description

This book is divided into projects that are explained in a step-by-step format, with practical instructions that are easy to follow. If you want to build your own home automation systems wirelessly using the Arduino platform, this is the book for you. You will need to have some basic experience in Arduino and general programming languages, such as C and C++ to understand the projects in this book.

What you will learn

  • Connect home automation sensors to the Arduino platform
  • Use the XBee technology to build lowpower wireless motion sensors
  • Interface a relay with Arduino to control devices in your home
  • Utilize WiFi to control a lamp remotely
  • Employ Bluetooth and Arduino to measure the temperature remotely
  • Send energy consumption data to the cloud
  • Hack an existing home automation device using Arduino

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jul 23, 2014
Length: 132 pages
Edition : 1st
Language : English
ISBN-13 : 9781783986071
Category :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jul 23, 2014
Length: 132 pages
Edition : 1st
Language : English
ISBN-13 : 9781783986071
Category :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Can$6 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just Can$6 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total Can$ 131.97
Arduino Robotic Projects
Can$61.99
Arduino Networking
Can$36.99
Arduino Home Automation Projects
Can$32.99
Total Can$ 131.97 Stars icon
Banner background image

Table of Contents

8 Chapters
1. Building Wireless XBee Motion Detectors Chevron down icon Chevron up icon
2. Control Lights from Your Phone or Tablet Chevron down icon Chevron up icon
3. Measuring the Temperature Using Bluetooth Chevron down icon Chevron up icon
4. Weather Station in the Cloud with Xively Chevron down icon Chevron up icon
5. Monitor Your Energy Consumption in the Cloud Chevron down icon Chevron up icon
6. Hack a Commercial Home Automation Device Chevron down icon Chevron up icon
7. Build Your Own Home Automation System Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
(10 Ratings)
5 star 40%
4 star 40%
3 star 10%
2 star 0%
1 star 10%
Filter icon Filter
Top Reviews

Filter reviews by




Garegin Ghukasyan Sep 17, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
High quality and delivered on time.
Amazon Verified review Amazon
Charlie Brown Jan 29, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Written where I could understand
Amazon Verified review Amazon
Stephen J. Aldrich Sr. Jan 22, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
well written with great information.
Amazon Verified review Amazon
Cliente Kindle Jan 31, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
9.I like this book for your proyects about measurements with sensors and wireless communications.I recommend this book. It's for electronics engineer and people interested in technology.
Amazon Verified review Amazon
Amazon Customer Feb 21, 2016
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Good book. Covers what you need to get started. Would recommend having some experience with Arduino before this book.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.