Hardware

An ARTIK-Powered Smart Water Tank


One of many amazing things you can build with your Samsung ARTIK is a smart water tank that can be remotely controlled by phone. In this tutorial we'll show you how to use ARTIK 10 to monitor the water level and make a phone call when the water level gets too low. The phone call will give you the option to remotely refill the tank from a reserve water supply. You can see it all in action in this short video.

This example uses our Nexmo > Voice > CaptureTextToSpeechPrompt Choreo.

Equipment

Before you start working on your application code, you'll need to gather your equipment. To build the application shown in the video, we used the following:

When wiring the water level sensor and pump to your ARTIK, make sure to take note of the GPIO pins you've used - you'll need them later when auto-generating the application code for this system on our website. When connecting the pump to your ARTIK, please be aware that the ARTIK 10 is powered at 5v, and the water pump runs on 12v. This means that a separate power source and transistor are required to have the the pump triggered by your board.

Get Set Up

1First, make sure you have a Temboo account. If you don't already have one, you can register for a free account here.

2If this is your first time using Temboo on ARTIK, you'll need to set up your ARTIK 10 to find the Temboo libraries. To do so, create the file temboo.conf in /etc/ld.so.conf.d. Inside of temboo.conf, paste the following line:

/opt/iothub/artik/temboo/temboo_artik_library/lib

After saving temboo.conf, run ldconfig from the command line to add the Temboo library directory to the system library search path.

You’ll also need to get the IP address of your ARTIK board using ifconfig. The example below shows the results when the ARTIK board is connected to the internet through an ethernet cable. The IP address you'll want to use is listed next to inet.

[root@localhost ~]$ ifconfig
eth0: flags=4163  mtu 1500
        inet 10.11.6.200  netmask 255.255.255.0  broadcast 10.11.6.255

3You'll also need a Nexmo account, which you can create here.

4After you've created your Nexmo account, retrieve your Nexmo API Key and API Secret to use later when you run the Choreo. You can find your Nexmo API Key and Secret in the API Settings menu on the top right of the Nexmo dashboard, as shown in the screenshot below.

Nexmo Dashboard

The API Settings menu on the Nexmo dashboard

Auto-Generate your ARTIK Code

5Go to the Nexmo > Voice > CaptureTextToSpeechPrompt in our Library.

6Select Samsung from the drop down menu at the top of the Choreo page.

Samsung ARTIK 10 IoT Mode

7Using the visual pin board, configure the pin attached to your water level sensor. Repeat this process for the pin attached to your water pump.

Setting up the water level sensor pin

7Now, set an Input Condition to indicate that you want to trigger the phone call when the water sensor being read by your ARTIK reaches a certain level. You'll need to experiment with the water level sensor to figure out the exact value that is appropriate for your application.

Input Condition

8With your Condition in place, test out the Choreo from our website by filling out the Choreo inputs and hitting the Generate Code button. Confirm that your phone gets a call and that when you enter a number of the keypad, that number is returned as part of the Nexmo response in the Output section of the page. You can use the "Save Profile" button to store your Choreo inputs for future reuse. Profiles also enable you to alter the behavior of your running application by editing the stored inputs on our website as opposed to in your code.

Nexmo Inputs

Testing the Nexmo Choreo from our website

9Below the Choreo inputs, you can set an Actuator Trigger Condition to indicate that you want to set your water pump's pin to high if the number "1" is pressed on the phone's keypad after receiving the phone call.

Output Condition

10When you've confirmed that the Choreo runs successfully, you can download the auto-generated ARTIK code from the Code section and get ready to move it to your device.

11We need to make one edit to our code before it's ready to test on our ARTIK. We want to make sure that the pump stops filling the tank in a timely fashion, so that the main tank doesn't overflow. Add the following code to the auto-generated program to ensure that your water tank is truly smart. The code should be placed in the while loop of main(). You will need to edit the max water level value as appropriate for your application.

        if (water < 700) {
            digitalWrite(outputPin, LOW);
        }

12The auto-generated sketch references the TembooAccount.h header file, which contains your Temboo account information. You'll find the code for this file beneath the main auto-generated C code. Make sure to keep both files together on your ARTIK.

13Copy your updated program code and header file to your ARTIK board using scp. From your computer, go to the directory where the zip file is located and type the command below. Make sure you use the IP address for your board you found using ifconfig.

[root@localhost ~]$ scp capturetexttospeechprompt.zip root@xxx.xxx.xxx.xxx:/home

14Now go to the capturetexttospeechprompt directory. To compile your code and start running your smart water tank application, run the first command below. After compiling has finished and no errors have been reported, run your program using the second command.

[root@localhost ~]$ gcc -L/opt/iothub/artik/temboo/temboo_artik_library/lib -ltemboo -I/opt/iothub/artik/temboo/temboo_artik_library/include capturetexttospeech.c -o capturetexttospeech
[root@localhost ~]$ ./capturetexttospeechprompt

Note: If you get an error about cdefs.h not being found, this could mean your ARTIK board was not shipped with glibc-headers. This can be solved by reinstalling glibc-headers using the command below. After reinstalling glibc-headers, run the two commands above to compile and run your code.

[root@localhost ~]$ yum reinstall glibc-headers

What Next?

When you've got this system working, you're in a position to build any number of applications that involve sensing information on the ARTIK and delegating control to a human when its time to make a choice about what to do next. Your IoT projects just got a whole lot smarter.

We'd love to hear where you take this idea next so please don't hesitate to get in touch if you have something to share.

Need Help?

You can learn more about working with Nexmo in the Choreo documentation that we use in this example. You can also find resources on Nexmo's Knowledgebase.

For anything to do with Temboo and how it works with your ARTIK, we're always happy to help. Just email us at support@temboo.com, and we'll answer you as quickly as possible.


Back