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

You're reading from  Arduino Home Automation Projects

Product type Book
Published in Jul 2014
Publisher
ISBN-13 9781783986064
Pages 132 pages
Edition 1st Edition
Languages
Author (1):
Marco Schwartz Marco Schwartz
Profile icon Marco Schwartz

Table of Contents (14) Chapters

Arduino Home Automation Projects
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
1. Building Wireless XBee Motion Detectors 2. Control Lights from Your Phone or Tablet 3. Measuring the Temperature Using Bluetooth 4. Weather Station in the Cloud with Xively 5. Monitor Your Energy Consumption in the Cloud 6. Hack a Commercial Home Automation Device 7. Build Your Own Home Automation System Index

Creating the Arduino sketch


Let's now build a simple sketch to test our sensor via Bluetooth. We are going to build a sketch so that it measures the temperature and humidity from the DHT sensor when a given command is received on the serial port.

We start by including the DHT library so that we can use the DHT11 sensor:

#include "DHT.h"

Then, define the sensor's pin and type:

#define DHTPIN 7
#define DHTTYPE DHT11

Note that if you are using a different DHT sensor, you will need to modify the code here. For example, if you are using a DHT22 sensor, simply type the following:

#define DHTTYPE DHT22

You will also need to define an instance of the DHT sensor and to send the sensor type and sensor pin as an argument:

DHT dht(DHTPIN, DHTTYPE);

In the setup() function of the sketch, you will have to initialize the DHT sensor's instance and start the serial connection:

dht.begin();
Serial.begin(115200);

We need to use a speed of 115,200 bauds here instead of the standard 9600 bauds, as it is recommended in...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}