We can now dive into the home automation part of this project. The goal is to get the sensor’s data, send it via WiFi to a server (running on your computer), and display the information. The code for each part is quite long, so I will only discuss the important parts. To get the complete code, simply go to the GitHub repository of the project.

To make this part work, you will also need to install the the CC3000 MDNS library and the aREST library.

First, the Arduino sketch. You need to import the right libraries:

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

Then, you need to define inside the code what is specific to your configuration, like your WiFi name & password:

#define WLAN_SSID "yourNetwork"
#define WLAN_PASS "yourPassword"
We can then create the CC3000 instance:
Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT,

We also need to create an instance of the aREST library, which we will use to access the data on the device:

aREST rest = aREST();

We will also create a server running on our board:

Adafruit_CC3000_Server restServer(80);

And let’s not forget to create the instance for the DHT sensor:

In the setup() part of the sketch, we need to initialize the DHT sensor:
And to connect the CC3000 to the network:

In the loop() part, we need to get data from the sensor, and then accept incoming connections to our server. The first part is simple:

temperature = (uint8_t)dht.readTemperature();
humidity = (uint8_t)dht.readHumidity();

At this point you can already test the project. Upload the sketch to your Arduino board (make sure you changed the WiFi name & password!) and then open the Serial monitor. You should see the IP address of the board displayed. 

Then, go a web browser, and type:

You should be greeted with the following message:

{"temperature": 24, "id": "1", "name": "weather_station", "connected": true}

If you can see that, it mean you project is working! If you want to learn more about the aREST framework that we are using here, you can visit the corresponding GitHub repository:


This guide was first published on Sep 25, 2013. It was last updated on Sep 25, 2013.

This page (Arduino sketch) was last updated on Sep 17, 2013.

Text editor powered by tinymce.