Make a WiFi Weather Station With Arduino and the CC3000 chip

cc3000_smallAs open-source hardware users and makers, we love playing with new chips, boards and tools. And there is one chip which is quite popular these days: the CC3000 WiFi chip from TI. This chip comes with many promises: cheap (around $10), easy to use, low-power … It was featured in many articles around the web, but somehow it was quite hard to use with Arduino as there was no breakout board or library available. Luckily, Adafruit solved that for us with a nice breakout board and a working library for Arduino. In this article, I will show you how to use this chip for home automation purposes. Remember that weather station project? We are going to do the same: measure the temperature and the humidity. But this time we won’t display the information on an LCD screen. Instead, we will transmit the data wirelessly via WiFi to your computer and display it there. Excited ? Let’s get started!

Hardware requirements

The whole project is based on the Arduino platform, so of course you will need an Arduino board. I really recommend using the Arduino Uno board for this project, as it is the only board that is currently compatible with the CC3000 library at the time this article was written.

Then, you need the famous CC3000 chip. There are also many alternatives to do that. What I recommend is using the Adafruit CC3000 breakout board, which is the only one I tested that worked without problem. It is nice and compact, has voltage regulators onboard, as well as an onboard antenna. I tried the official TI CC3000 board, but it never worked properly, and you have the use level shifters as well (the CC3000 works with 3.3V, and the Arduino Uno with 5V). The other alternative is to make your own breakout board, there are many PCB layout available online.

You also need a DHT temperature & humidity sensor. I used the DHT11 sensor, but this project would also work fine with a DHT22, you would just have one line of code to change. You will also need a 10K Ohm resistor to be used with the DHT sensor.

Finally, you need a breadboard and some jumper wires to make the connections between the different parts.

Software requirements

For this project, you need the usual Arduino IDE. You will also need the Adafruit’s CC3000 library, as well as the DHT sensor library. To install a library, just download the folders, and put them into your /Arduino/libraries/ folder.

You will also need a web server running on your computer. There are thousands of tutorial for that, but I recommend using MAMP if you are on OS X.

Hardware configuration

The hardware configuration for this project is actually not that complicated, thanks to the good informations that you will find on the CC3000 breakout board. Connect the IRQ pin of the CC3000 board to pin number 3 of the Arduino board, VBAT to pin 5, and CS to pin 10. Then, you need to connect the SPI pins to the Arduino board: MOSI, MISO, and CLK go to pins 11,12, and 13, respectively. Finally, take care of the power supply: Vin goes to the Arduino 5V, and GND to GND.

The DHT sensor is easier to connect: just plug the pin number 1 to the Arduino’s 5V, pin number 4 to GND, and pin number 2 to Arduino pin 7. Finally, put the 10K resistor between the sensor pins number 1 and 2.

The following picture summarizes the hardware connections:

cc3000_weather

Testing the WiFi chip

As this tutorial is really about the CC3000 chip, I don’t want to spend too much time on the DHT sensor. You will find a good test sketch inside the library, and I also included a test sketch inside the project’s GitHub repository.

Note that in this tutorial, we will only cover a tiny part of the possibilities offered by the Arduino platform. If you want to learn more about Arduino, I recommend following the excellent Arduino Step by Step course on Udemy.

To see if your WiFi chip is correctly wired and operational, I recommend to use the test sketches that come with the Adafruit library. I used for example the one called WebClient. Just open it from the library’s folder, and save it to a new file (you need to be able to modify the sketch to enter your WiFi network name & password). Then, modify the sketch with the correct data for you WiFi network, and upload to the board. You can then open your serial monitor, and if everything was wired correctly (and your Internet connection is working!) you should see your Arduino connecting to the web, then connecting to the Adafruit’s website, and printing some information.

Putting it all together

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.

First, the Arduino sketch. If you had a look at the example file from Adafruit, you should already have an idea of what are the important parts of the sketch. Of course, you need to import the right libraries:

Then, you need to define inside the code what is specific to your configuration: WiFi name & password, IP address of your computer, and port of your server (usually 80):

We can then create the CC3000 instance:

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 to send it to the server by doing a GET request. The first part is really simple:

You just need to take care of converting these floats to Strings, because you want to insert this information into an HTTP request. In this case, we just convert the floats to integers, and then transform them to strings:

Finally, I send the request with this send_request() function. This function basically converts the String of the request to an array of chars (for speed reasons), and connect to the server with:

And then send the request with this line:

Finally, it reads out the answer (which we don’t use in this project, but you could perfectly get data back from the server):

We then wait 10 seconds between each temperature & humidity update. Once again, to get the complete code, just go to the GitHub repository of the project.

It’s now time to write the server part. As usual, I used a combination of HTML, JavaScript, and PHP. The PHP part will receive the data from the board at each GET request, and save it into files:

Of course, you could use more elaborate ways to save the data like XML or SQL but I wanted to keep things simple. Then, I used two other PHP scripts to actually display the data on the main HTML page. This is for example the one for the temperature:

Finally, the main page just organizes all this information in two separate blocks. This is for example one of them:

I also used a simple JavaScript part to update the display every second, just where we need it:

It is based on jQuery, which is also included in the GitHub repository of the project. I also put some CSS in the page so it doesn’t look to ugly, I let you see the details in the repository.

That’s all for the software part, so it is time to test it out! Upload the sketch to the Arduino board, open the serial monitor to check that everything is working correctly, and also open the html page inside your favorite browser. Wait a bit so that the board can send the first set of data, and this is what you should see:

Screen Shot 2013-08-20 at 7.34.29 PM

You can play with the sensor to see the data being automatically updated on the page. Congratulations, you just built a simple WiFi-connected weather station! I used temperature & humidity as the “data” in this tutorial, but it can be anything you want: data from a motion detector, door/window contact … You can also modify the server part so that it sends some information back to the board, for example to control a relay.

As always, please comment below if you have any question, a suggestion on how to improve the article, or if you find some nasty bugs in the code! Finally, this is the list of the parts that were used in this project:

Receive the latest news about home automation
Over 100 home automation enthusiasts already joined our list !

Do you want to receive the latest news about open-source hardware and home automation ? Then join our mailing list today by entering your name and email below. It is 100% free and you can unsubscribe at any time if you're not satisfied.

5 replies

Trackbacks & Pingbacks

  1. […] luck that Mark Schwartz wrote a blog post on the Open Home Automation web site that does exactly what we want to do!  In Mark’s […]

  2. […] Make a WiFi Weather Station With Arduino and the CC3000 chip […]

Comments are closed.