Make a WiFi Weather Station With Arduino and the CC3000 chip

cc3000_small

If you found this article after doing a search on Google, welcome! On this website you will find plenty of content around DIY home automation using open-source hardware. Enjoy the article!

As 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. We will also use a library called aREST to really simplify the whole project. Excited ? Let’s get started!

Hardware & Software 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.

This is a list of all the components that are required for this project:

On the software side, you need the usual Arduino IDE. Note that for this project, you need the Arduino IDE in version 1.5.x, because this version drastically reduce the size of the final Arduino sketch when uploaded to the board. With 1.0.5, it will not work because the sketch would be too big after compilation.

You will also need the Adafruit’s CC3000 library, the CC3000 MDNS library, the aREST 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 to install Node.js on your computer, so you can run the server part. You can get it at the following address:

http://nodejs.org/

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, like your WiFi name & password:

We can then create the CC3000 instance:

And an instance of a server that will run on the Arduino microcontroller:

We also create an instance of the aREST library:

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

We also need to create two variables that will contain the measurements of the sensor:

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

We also have to expose the two measurement variables to the aREST API:

After that, we connect the CC3000 to the network:

Before the end of the setup() function, we start the server and display the connection details, like the IP address of the CC3000 chip:

In the loop() part, we need to get data from the sensor, and store it in the variables we defined before:

Then, we simply handle the incoming request with:

Once again, to get the complete code, just go to the GitHub repository of the project.

You can now upload the code to your Arduino board. Make sure that you modified the code with your own WiFi name and password. Then, we are going to test it by making call to the aREST API. Go to your favorite browser, and type:

arduino.local/temperature

You should be greeted with the following message:

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

Congratulations, you can now read the value of the temperature via WiFi!

If it doesn’t work at this point, don’t worry: it can just be that the mDNS service (that allows you to access the project using arduino.local) is not working on your computer. To get around that, open the Serial monitor of the Arduino IDE. Wait a moment, and you should see the IP address of the board being printed:

IP Addr: 192.168.1.104

You can then use the IP address directly to access the board:

192.168.1.104/temperature

It’s now time to write the server part. The code is based on Node.JS, and it is made so you only have one line of code to modify so it can work with your configuration. This interface will simply get the data from the board by making calls to the aREST API just as we did before, and then display this data on a page.

First, download the code from the GitHub repository of the project. Then, go inside the interface folder, and find a file called interface.js. Inside this file, you will be able to change the target IP address that we got before:

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 go to the folder of the interface using your favorite Terminal software. Then, type:

sudo npm install express arest

That will install the required modules for Node.JS. Then, type:

node app.js

You should be greeted by a message:

Listening on port 3700

After that, go to this URL in your favorite web browser:

http://localhost:3700/interface

Wait a bit so that the board can send the first set of data, and this is what you should see:

interface

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!