This automatic watering system application is part of a series of how-to Intel IoT code sample exercises using the Intel® IoT Developer Kit, Intel® Edison development platform, cloud platforms, APIs, and other technologies.
From this exercise, developers will learn how to:
- Connect the Intel® Edison development platform, a computing platform designed for prototyping and producing IoT and wearable computing products.
- Interface with the Intel® Edison platform IO and sensor repository using MRAA and UPM from the Intel® IoT Developer Kit, a complete hardware and software solution to help developers explore the IoT and implement innovative projects.
- Run this code sample in Intel® XDK IoT Edition, an IDE for creating applications that interact with sensors and actuators, enabling a quick start for developing software for the Intel® Edison or Intel® Galileo board.
- Set up a web application server to store watering system data using Azure Redis Cache* from Microsoft* Azure*, cloud services for connecting IoT solutions including data analysis, machine learning, and a variety of productivity tools to simplify the process of connecting your sensors to the cloud and getting your IoT project up and running quickly.
- Invoke the services of the Twilio* API for sending text messages.
What it is
Using an Intel® Edison board, this project lets you create an automatic watering system that:
- Turns a water pump on or off based on a configurable schedule;
- Detects if the pumping occurs when expected, by using a water flow sensor;
- Can be accessed with your mobile phone via the built-in web interface to set the watering times;
- Keeps track of watering events, using cloud-based data storage;
- Sends text messages to alert recipients if the system is not working as expected.
How it works
This watering system allows you to set the watering schedule via a web page served directly from Intel® Edison, by using your mobile phone.
It automatically checks moisture sensor data at periodic intervals, and displays this data on the web page.
If the water pump is supposed to be on, but the water flow sensor does not detect that the pumping is talking place as expected, it sends a text message to a specified number through Twilio* so the watering system can be repaired.
Optionally, it can also log watering system events using the Intel IoT Examples Datastore running in your own Microsoft* Azure* account.
Grove* Environment & Agriculture Kit containing:
1. Intel® Edison with an Arduino* breakout board
2. Grove* Moisture Sensor
3. Water Pump
4. Water Flow Sensor
5. Grove* Dry-Reed Relay
1. Intel® XDK IoT Edition
2. Microsoft* Azure* account
3. Twilio* account
How to set up
To begin, clone the How-To Intel IoT Code Samples repository with Git* on your computer as follows:
$ git clone https://github.com/intel-iot-devkit/how-to-code-samples.git
Want to download a .zip file? In your web browser, go to https://github.com/intel-iot-devkit/how-to-code-samples and click the Download ZIP button at the lower right. Once the .zip file is downloaded, uncompress it, and then use the files in the directory for this example.
Adding the program to Intel® XDK IoT Edition
In Intel® XDK IoT Edition, select Import Your Node.js Project:
Then, navigate to the directory where the example project exists, and select it:
You need to connect to your Intel® Edison board from your computer to send code to it.
Click the IoT Device menu at the bottom left. If your Intel® Edison is automatically recognized, select it.
Otherwise, select Add Manual Connection. In the Address field, type 192.168.2.15. In the Port field, type 58888. Click Connect to save your connection.
Installing the program manually on Intel® Edison
Alternatively, you can set up the code manually on the Intel® Edison board.
Clone the How-To Intel IoT Code Samples repository to your Intel® Edison board after you establish an SSH connection to it, as follows:
$ git clone https://github.com/intel-iot-devkit/how-to-code-samples.git
Then, navigate to the directory with this example.
To install Git* on Intel® Edison, if you don’t have it yet, establish an SSH connection to the board and run the following command:
$ opkg install git
Connecting the Grove* sensors
You need to have a Grove* Shield connected to an Arduino*-compatible breakout board to plug all the Grove* devices into the Grove* Shield. Make sure you have the tiny VCC switch on the Grove* Shield set to 5V.
You need to power Intel® Edison with the external power adapter that comes with your starter kit, or substitute it with an external 12V 1.5A power supply. You can also use an external battery, such as a 5V USB battery.
In addition, you need a breadboard and an extra 5V power supply to provide power to the pump. Note: you need a separate battery or power supply for the pump. You cannot use the same power supply for both the Intel® Edison board and the pump, so you need either 2 batteries or 2 power supplies in total.
You need to use the Grove* Dry-Reed Relay board to connect the water pump.
1. Plug one end of a Grove* cable into the Grove* Dry-Reed Relay, and connect the other end to the D4 port on the Grove* Shield.
2. Connect one wire from the pump to the 5V power source reserved for the pump.
3. Connect the other wire from the pump to one of the power connectors on the Grove* Dry-Reed Relay board.
4. Connect the other power connector on the Grove* Dry-Reed Relay board to the ground of the 5V power source reserved for the pump.
5. Connect the Water Flow Sensor by plugging the red wire into the 5V pin, the black wire into the GND pin, and the yellow wire into digital pin 2 on the Grove* Shield.
6. Plug one end of a Grove* cable into the Grove* Moisture Sensor, and connect the other end to the A0 port on the Grove* Shield.
Manual Intel® Edison setup
If you're running this code on your Intel® Edison manually, you need to install some dependencies.
To obtain the Node.js* modules needed for this example to execute on Intel® Edison, run the following command:
Twilio* API key
To optionally send text messages, you need to register for an account and get an API key from the Twilio* web site:
You cannot send text messages without obtaining a Twilio* API key first. You can still run the example, but without the text messages.
Pass your Twilio* API key and authentication token to the sample program by modifying theTWILIO_ACCT_SID and TWILIO_AUTH_TOKEN keys in the config.json file as follows:
Microsoft* Azure* server setup
Optionally, you can store the data generated by this example program in a backend database deployed using Microsoft* Azure*, Node.js*, and a Redis* data store.
For information on how to set up your own cloud data server, go to:
Configuring the example
To configure the example for sending optional text messages, obtain an API key from the Twilio* web site as explained above, and then change the TWILIO_ACCT_SID and TWILIO_AUTH_TOKEN keys in theconfig.json file as follows:
To configure the example for the optional Microsoft* Azure* data store, change the SERVER andAUTH_TOKEN keys in the config.json file as follows:
To configure the example for both the text messages and the Microsoft* Azure* data store, change theTWILIO_ACCT_SID, TWILIO_AUTH_TOKEN, SERVER, and AUTH_TOKEN keys in the config.json file as follows:
Running the program using Intel® XDK IoT Edition
When you're ready to run the example, make sure you saved all the files.
Click the Upload icon to upload the files to the Intel® Edison board.
Click the Run icon at the bottom of Intel® XDK IoT Edition. This runs the code on Intel® Edison.
If you made changes to the code, click Upload and Run. This runs the latest code with your changes on Intel® Edison.
You will see output similar to the above when the program is running.
Running the program manually
To run the example manually on Intel® Edison, establish an SSH connection to the board and execute the following command:
Setting the watering schedule
The schedule for the watering system is set using a single-page web interface served from Intel® Edison while the sample program is running.
The web server runs on port 3000, so if Intel® Edison is connected to Wi-Fi* on 192.168.1.13, the address to browse to if you are on the same network is http://192.168.1.13:3000.
Determining the Intel® Edison IP address
You can determine what IP address Intel® Edison is connected to by running the following command:
ip addr show | grep wlan
You will see the output similar to the following:
3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
inet 192.168.1.13/24 brd 192.168.1.255 scope global wlan0
The IP address is shown next to inet. In the example above, the IP address is 192.168.1.13.
For a complete list of How-To Intel IoT Code Samples, go to Intel® Developer Zone.
For more details about this code sample, go to GitHub*.
For more such intel IoT resources and tools from Intel, please visit the Intel® Developer Zone
Other Popular Deals
- The 10 best job hunting apps on AndroidTop 10 Android launchers (December 2016)
- The 10 scariest horror games on AndroidAndroid app stores: 5 best alternatives to Google Play Store
- Best Android apps for rooted devices18 apps for a memorable Valentine's Day
- Top 15 Android games that you should playThe 20 best looking games for mobile phones
- 8 Android apps to tickle your funny bone17 must have apps for any Android device (plus alternatives)
- 5 apps to get the Android Lollipop look on your smartphoneTake control of your Android device with these apps
- 7 weird and strange apps for your Smartphone10 neat Google apps you may not know of
- 10 essential Indian apps for Android devicesPerfect Viewer