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

Building the Arduino sketch

At this point, we have working sensors on our Arduino board, and we also have an account on Xively that is ready to receive some data. We are now going to write the sketch that will connect to your Wi-Fi network and upload data automatically to your Xively account.

We are now going to write down the code in the Arduino IDE. We start by including the correct libraries as shown:

#include <Adafruit_CC3000.h>
#include <SPI.h>
#include "DHT.h"

Then, just as in Chapter 2, Control Lights from Your Phone or Tablet, we need to define on which pins the CC3000 board is connected:

#define ADAFRUIT_CC3000_IRQ   3
#define ADAFRUIT_CC3000_VBAT  5
#define ADAFRUIT_CC3000_CS    10

And define the pin and type of the DHT sensor:

#define DHTPIN 7
#define DHTTYPE DHT11

We can now create the instance of the CC3000 chip:

Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIV2);

Now, you will have a few things to modify...