wireless gardening with arduino + cc3000 wifi …...2018/08/22  · created by marc-olivier schwartz...

14
Wireless Gardening with Arduino + CC3000 WiFi Modules Created by Marc-Olivier Schwartz Last updated on 2018-08-22 03:39:17 PM UTC

Upload: others

Post on 15-Aug-2020

3 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Wireless Gardening with Arduino + CC3000 WiFi …...2018/08/22  · Created by Marc-Olivier Schwartz Last updated on 2018-08-22 03:39:17 PM UTC 2 3 5 7 10 12 14 Guide Contents Guide

Wireless Gardening with Arduino + CC3000 WiFi ModulesCreated by Marc-Olivier Schwartz

Last updated on 2018-08-22 03:39:17 PM UTC

Page 2: Wireless Gardening with Arduino + CC3000 WiFi …...2018/08/22  · Created by Marc-Olivier Schwartz Last updated on 2018-08-22 03:39:17 PM UTC 2 3 5 7 10 12 14 Guide Contents Guide

2357

101214

Guide Contents

Guide ContentsIntroductionSetting up your Carriots accountConnectionsArduino sketchSending data to CarriotsCreating an email alert

© Adafruit Industries https://learn.adafruit.com/wireless-gardening-arduino-cc3000-wifi-modules Page 2 of 14

Page 3: Wireless Gardening with Arduino + CC3000 WiFi …...2018/08/22  · Created by Marc-Olivier Schwartz Last updated on 2018-08-22 03:39:17 PM UTC 2 3 5 7 10 12 14 Guide Contents Guide

IntroductionIn this guide, we are going to give a modern touch to gardening and connect some informations about your garden tothe Internet. We are going to use a soil moisture & temperature sensor connected to an Arduino and a WiFi chip toautomatically send measurements from your garden to the cloud.

We'll use a service call Carriots (https://adafru.it/d5e) to handle the data and display it nicely on a webpage. Then, anemail or SMS alert can be send to you automatically if the moisture falls below a given threshold. The picture belowrepresents the system when fully assembled and with the sensor buried into the soil next to a plant:

Don't worry, you don't actually need to have a garden or even plants (although we think plants are great to have) touse the content of this article: what you are going to learn can be used for any remote measurement projects. Let's

© Adafruit Industries https://learn.adafruit.com/wireless-gardening-arduino-cc3000-wifi-modules Page 3 of 14

Page 4: Wireless Gardening with Arduino + CC3000 WiFi …...2018/08/22  · Created by Marc-Olivier Schwartz Last updated on 2018-08-22 03:39:17 PM UTC 2 3 5 7 10 12 14 Guide Contents Guide

dive into the project!

© Adafruit Industries https://learn.adafruit.com/wireless-gardening-arduino-cc3000-wifi-modules Page 4 of 14

Page 5: Wireless Gardening with Arduino + CC3000 WiFi …...2018/08/22  · Created by Marc-Olivier Schwartz Last updated on 2018-08-22 03:39:17 PM UTC 2 3 5 7 10 12 14 Guide Contents Guide

Setting up your Carriots accountTo upload data to Carriots (https://adafru.it/d4I), you first need to create an account:

When the account is created, you will have to create a device, which is the entity that will receive the data from our hardware project:

© Adafruit Industries https://learn.adafruit.com/wireless-gardening-arduino-cc3000-wifi-modules Page 5 of 14

Page 6: Wireless Gardening with Arduino + CC3000 WiFi …...2018/08/22  · Created by Marc-Olivier Schwartz Last updated on 2018-08-22 03:39:17 PM UTC 2 3 5 7 10 12 14 Guide Contents Guide

Finally, you will need to know your API key for the rest of the tutorial. You can find the key under the "MY ACCOUNT" menu:

When all these steps are done, congratulations, you are ready to send data to your newly created device! Be sure tokeep the device name and your API key around, you'll need them for the next part of the guide.

© Adafruit Industries https://learn.adafruit.com/wireless-gardening-arduino-cc3000-wifi-modules Page 6 of 14

Page 7: Wireless Gardening with Arduino + CC3000 WiFi …...2018/08/22  · Created by Marc-Olivier Schwartz Last updated on 2018-08-22 03:39:17 PM UTC 2 3 5 7 10 12 14 Guide Contents Guide

ConnectionsThe whole project is based on the Arduino platform, so of course you will need an Arduino board. I will use an ArduinoUno board for this project. Then, you need a board with the CC3000 chip. What I recommend is using the AdafruitCC3000 breakout board, which is the only one I tested that worked without problem.

To measure the temperature & humidity in the soil, you will need an appropriate sensor. For this guide, I used the SoilTemperature/Moisture sensor from Adafruit, which is based on the SHT10 sensor from Sensirion. It's quite easy to usewith Arduino as there is a dedicated library, so it will be easy to interface with our project.

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

First, you need to connect the CC3000 chip to the Arduino Uno board. To get a step-by-step guide on how to connectand use the CC3000 breakout board, I recommend to visit this detailed guide (https://adafru.it/d4J).

Basically, you need to 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.

Connecting the soil sensor is relatively easy. It comes with wires not connected to any pins, so I simply soldered a 4-pins header to the 4 wires of the sensor. Simply connect the GND pin to the GND of the Arduino, VCC to 5V, Clock toArduino pin 7, and Data to Arduino pin 6. The following picture explains the roles of the different wires coming fromthe sensor:

Make sure to run the Adafruit CC3000 test example sketches before you continue - WiFi is easier to debugbefore you add all the sensors and extras!

© Adafruit Industries https://learn.adafruit.com/wireless-gardening-arduino-cc3000-wifi-modules Page 7 of 14

Page 8: Wireless Gardening with Arduino + CC3000 WiFi …...2018/08/22  · Created by Marc-Olivier Schwartz Last updated on 2018-08-22 03:39:17 PM UTC 2 3 5 7 10 12 14 Guide Contents Guide

The following picture summarises all the required connections for the hardware part of this project:

© Adafruit Industries https://learn.adafruit.com/wireless-gardening-arduino-cc3000-wifi-modules Page 8 of 14

Page 9: Wireless Gardening with Arduino + CC3000 WiFi …...2018/08/22  · Created by Marc-Olivier Schwartz Last updated on 2018-08-22 03:39:17 PM UTC 2 3 5 7 10 12 14 Guide Contents Guide

When the project is fully assembled, this is how it should look like:

© Adafruit Industries https://learn.adafruit.com/wireless-gardening-arduino-cc3000-wifi-modules Page 9 of 14

Page 10: Wireless Gardening with Arduino + CC3000 WiFi …...2018/08/22  · Created by Marc-Olivier Schwartz Last updated on 2018-08-22 03:39:17 PM UTC 2 3 5 7 10 12 14 Guide Contents Guide

Arduino sketchFor this project, you simply need the Arduino IDE, the CC3000 library (https://adafru.it/cFn), and the Sensirionlibrary (https://adafru.it/CcZ). Make sure that the libraries are correctly placed in your /libraries folder inside your mainArduino folder.

The code for this project can be found on the GitHub repository for the project (https://adafru.it/d51).

Now everything is set so that you can send data over to the Carriots cloud service. We have to write the sketch thatwill be uploaded to the Arduino Uno board. Because the Carriots service uses a REST API, the sketch will actually bequite similar to what was done in the Arduino & Xively project (https://adafru.it/d52): establishing a connection to theCarriots server, measuring some data from the sensor, and then formatting & sending the data as a JSON object.

I won't detail everything here, you can have a look at the Arduino & Xively project (https://adafru.it/d52) for moredetails, and of course you can find all the code on our GitHub repository for this project (https://adafru.it/d51). The firstdifference with other cloud services is that you need to set your API key in the sketch, but also the device you want tosend data to:

In the loop() part of the sketch, you need to format the data measured by the Arduino according the Carriotsguidelines (https://adafru.it/d53). For example, data sent by our sketch should have the following form:

Then, at the end of each loop, this data is sent along with an HTTP header. We then read the answer back from theserver, and you can check it out on the serial monitor. If the server accepts the data, you should see an "OK" messageprinted out. Finally, the connection is closed and we wait for 10 seconds before the next measurement.

You can get the whole Arduino sketch from the GitHub repository (https://adafru.it/d51), modify the required parts likeyour WiFi SSID & password and your Carriots account data, and finally upload the code to your Arduino board. You cannow open the serial monitor and check if the Arduino is sending data to the Carriots server:

#define WEBSITE "api.carriots.com"#define API_KEY "yourAPIkey"#define DEVICE "yourDeviceName@yourUserName"

{ "protocol":"v2", "at":"now", "device":"yourDevice@yourUserName", "data":{ "Temperature":"21.05", "Humidity":"58.50" }, "checksum":""}

© Adafruit Industries https://learn.adafruit.com/wireless-gardening-arduino-cc3000-wifi-modules Page 10 of 14

Page 11: Wireless Gardening with Arduino + CC3000 WiFi …...2018/08/22  · Created by Marc-Olivier Schwartz Last updated on 2018-08-22 03:39:17 PM UTC 2 3 5 7 10 12 14 Guide Contents Guide

© Adafruit Industries https://learn.adafruit.com/wireless-gardening-arduino-cc3000-wifi-modules Page 11 of 14

Page 12: Wireless Gardening with Arduino + CC3000 WiFi …...2018/08/22  · Created by Marc-Olivier Schwartz Last updated on 2018-08-22 03:39:17 PM UTC 2 3 5 7 10 12 14 Guide Contents Guide

Sending data to CarriotsTo check if the Carriots service received some data, you can simply go in your Carriots account, under "Data streams":

You should see some data recorded for your device:

Pretty cool, right ? But that's not all: Carriots can actually help you to plot this data & embed it into your own website ifyou want. For that, simply go to the "Wizard Widget Graphs" link on the left menu:

From there, you have a nice step-by-step menu to choose the type of graph you want, the data you want to plot, andfinally you will get access to the code that you can embed in a webpage to automatically display the graph. I also

© Adafruit Industries https://learn.adafruit.com/wireless-gardening-arduino-cc3000-wifi-modules Page 12 of 14

Page 13: Wireless Gardening with Arduino + CC3000 WiFi …...2018/08/22  · Created by Marc-Olivier Schwartz Last updated on 2018-08-22 03:39:17 PM UTC 2 3 5 7 10 12 14 Guide Contents Guide

included an example of such a webpage in the GitHub repository of the project (https://adafru.it/d51). This is anexample with the data I recorded:

© Adafruit Industries https://learn.adafruit.com/wireless-gardening-arduino-cc3000-wifi-modules Page 13 of 14

Page 14: Wireless Gardening with Arduino + CC3000 WiFi …...2018/08/22  · Created by Marc-Olivier Schwartz Last updated on 2018-08-22 03:39:17 PM UTC 2 3 5 7 10 12 14 Guide Contents Guide

Creating an email alertTo finish this project, we'll create an automatic alert for one of the variable. For example, we want to know if thehumidity falls under a given threshold, indicating that the plant needs to be watered. In Carriots, this means creating a"Listener" that will automatically send you an email when an event happens, in this case if the data crosses a giventhreshold. You can create a listener with the Carriots wizard:

You will be prompted to enter your email, and then to configure the listener. To test my listener, I simply entered thecondition that an email will be sent if the temperature reaches 23 degrees Celsius:

I then applied some heat on the sensor, and I immediately received an email when a data point above 23 degrees wasrecorded:

You can also add listeners on other variables, and send an SMS to your phone instead of an email. Of course, you canfind the whole code for this project on the GitHub repository of the project (https://adafru.it/d51).

That's all for this article, keep in mind that you can use what you've learned in this guide for a lot of other fields thangardening! You can connect multiple sensors inside & outside of your home to the Carriots service, and create morecomplex conditions to send specific alerts based on the data you are recording. Have fun with the project, experimentwith this cloud service, and share your creations!

© Adafruit Industries Last Updated: 2018-08-22 03:39:12 PM UTC Page 14 of 14