Filter results by

This post updates our previous article to use the ARTIK Cloud endpoint and Java/Android SDK.

In this article we will build a remote monitoring system using ARTIK Cloud, off-the-shelf sensors, Arduino UNO, Raspberry Pi, and an Android application. Using our Android app, we can remotely monitor data from temperature and flame sensors that are connected to ARTIK Cloud via the IoT development platform. Note that if you attended our SAMI Developer Meet-up, you will recognize this IoT setup from the live demo I presented with Dr. Luc Julia.

This is the first in a series of articles exploring the DIY smart home with ARTIK Cloud. Read the second tutorial, An IoT Remote Control. For a basic IoT implementation, see our tutorial Your first IoT device. However, this article can be read independently. You will learn how to do three things:

Combine data from multiple sensors on Arduino UNO to send to Raspberry Pi.

Set up a WebSocket connection on Raspbery Pi to send data to ARTIK Cloud.

ARTIK Cloud creates an open ecosystem

In a system like this, ARTIK Cloud acts as back-end storage for IoT devices. Meanwhile, application developers use ARTIK Cloud APIs to develop mobile/web applications for these IoT devices.

Device developers do not need to build their own apps. Instead, application developers can learn the device Manifests and build applications for the devices that interest them. Each of the players in the ecosystem can focus on what they do best, instead of building a complicated end-to-end system.

Demo video

Build the sensor monitor system

Step 1: Connect a device in My ARTIK Cloud

I have published a device type “SAMI Example IoT DIY Sensor” with multiple fields (temperature and flame detection) as below. Any ARTIK Cloud developer can now use this device type as part of an IoT setup.

First, sign into My ARTIK Cloud. If you don’t have a Samsung account, you can create one at this step.

On the dashboard, click to connect a new device. Choose the pre-defined device type “SAMI Example IoT DIY Sensor”.

Name this device using your name (e.g., “Yujing IoT Sensor”).

Click “Connect Device…”. You’re taken back to the dashboard.

Click the Settings icon of the device you just added. In the pop-up, click “GENERATE DEVICE TOKEN…”.

Copy the device ID and device token on this screen. You will use these in the code.

Step 2: Set up the Arduino

Now let’s wire the sensors to the Arduino.

The two sensors are wired as follows:

Next, upload the Sketch program (read_temperature_flame_sensors.ino from GitHub) to the Arduino UNO using the Arduino IDE. This code reads the data from the temperature sensor and IR flame sensor, and then sends them to the serial port every 5 seconds (you can change this parameter in the code later, since ARTIK Cloud has rate limits for the number of messages per day). Below is a data sample:

84,1002,1

The first value is the temperature (in Fahrenheit) from DHT11; the second value is the analog reading ([01023]) from the flame sensor; and the third value is the digital reading ([0,1]) from the flame sensor. For the digital readings, “0” means that a fire is detected and “1” means no fire.

Step 3: Set up the Raspberry Pi

Connect your Raspberry Pi to a monitor, mouse and keyboard. Ensure that an Ethernet or WiFi connection is working, and make sure the OS is up-to-date:

$ sudo apt-get update
$ sudo apt-get upgrade

If not already installed, install Node.js for ARM, then add the packages ‘serialport’ and ‘ws’ via npm:

$ npm install serialport
$ npm install ws

Now connect the serial port from the Arduino to the USB on the Raspberry Pi.

Finally, download the Node.js code (send_data_to_artik_cloud.js from GitHub) to the Raspberry Pi. Replace the placeholders in the code with the device token and device ID you collected from My ARTIK Cloud.

View your device data as it’s generated by clicking the device name in the device box. This takes you to Data Visualization. From there, click the “+/- CHARTS” button and check “temp” and “onFire” to visualize a chart for each field. (Read this post for more information on Data Visualization.)

Step 5: Build the Android monitoring app

The sensor data is now being sent to ARTIK Cloud. Now we can build an Android app to read the data from ARTIK Cloud in real-time. It’s important to note that any developer can build such a mobile app, since the “SAMI Example IoT DIY Sensor” with the appropriate fields has already been published in the Developer Dashboard. Again, thanks to the openness of the ARTIK Cloud ecosystem, any developer can build an application for any published devices.

Below is a screenshot of our app. The status and time continually refreshes as new data comes in. The Android app uses a firehose WebSocket API /live to listen in real-time for each message sent to ARTIK Cloud by the Raspberry Pi. This type of WebSocket is primarily used by applications with monitoring functionalities.

Check out the Android code on GitHub. Follow the instructions there to build the Android application. Please do remember to replace the placeholders in ArtikCloudSession.java with the device token and device ID you collected from My ARTIK Cloud.

Once ARTIK Cloud receives a message from the Raspberry Pi, it notifies the Android app about this message via the firehose WebSocket. This notification invokes the callback method onMessage. The callback eventually triggers the new data to show up on the UI.

Where to go from here?

For a home monitoring system, you may want to monitor locks on your doors, the moisture level in your garden, lights in your rooms, and the earth’s movements under your house (we live in California), etc. For the sake of fun, think of using different IoT open-source development modules (e.g., various Arduino boards, Raspbery Pi, ARTIK modules, Galileo) or using different module combinations to build these DIY devices.

You may be interested in writing an iOS app to do the monitoring. Or how about enhancing the Android app to monitor multiple device types instead of only one type? In addition, beyond monitoring, you may want to use your mobile app to control your DIY devices, such as turning on/off lights. With ARTIK Cloud and various IoT modules, building a comprehensive DIY smart home can be both intuitive and enjoyable.

We will continue building our DIY smart home in the future. Stay tuned for more development blog posts by joining our mailing list at http://developer.artik.cloud/.

Yes! Connect me with Samsung IoT partners to hear more about their products and services. *

* By checking either box, you may receive notifications by phone, email, text, and/or other electronic means from Samsung Semiconductor, Inc. and its affiliates. If you choose to receive partner notifications, we may forward your contact information to ourpartners. You may unsubscribe from these services at any time by clicking on the unsubscribe link in our communications or by submitting a request here. Please see our Privacy Policy and Terms of Use for more information about how your data is stored and used.