Building a realtime temperature sensor with Atmel and PubNub


PubNub’s Bhavana Srinivas demonstrates how to build a realtime temperature sensor with PubNub and Atmel.


With the buzzword being Internet of Things (IoT), PubNub recently wanted to build something simple, yet powerful, that could extend beyond the hackerspace and be applied to the real world. It had to combine software and hardware, and allow people at home to build it and try it themselves.

Arduino came to mind, but seeing as though the team has already written a great deal of realtime tutorials using the Arduino board, they sought out to try something a bit different. Instead, the group decided upon employing Atmel | SMART SAM D21 Xplained Pro and PubNub to devise a realtime temperature sensor.

Project Overview

The Atmel temperature sensor monitors temperatures and streams the data to a live-updating dashboard, in realtime, anywhere in the world. The temperature sensor measures the ambient temperature and publishes it as a data stream to a channel via the PubNub Data Stream Network. A web browser that subscribes to this channel displays the data stream on a live visualization dashboard.

The Concept

demofunctionality

  • The Atmel I/O1 Xplained Pro sensor measures the ambient temperature.
  • This connects to the Wi-Fi using the ATWINC1500 module.
  • The PubNub code running on the Atmel chip enabled the team to publish the temperature in realtime to anyone subscribing to the same channel as a data stream.
  • Through the PubNub Developer Console, you can receive this stream of information from as many sensors as you like in realtime.

What Will You Need?

Hardware

components-1024x576

Software

  • Windows PC
  • To get your unique pub/sub keys, you’ll first need to sign up for a PubNub account. Once you sign up, you can get your unique PubNub keys in the PubNub Developer Dashboard. PubNub’s free Sandbox tier should give you all the bandwidth you need to build and test your messaging app with the web messaging API.
  • Install Atmel Studio 6.2
  • Install updates to Atmel Studio as suggested during installation
  • Install terminal software like putty or teraterm

A prerequisite is that you upgrade the firmware for SAMD21 using the .bat file provided with the PubNub Atmel example before you run this demo. Make sure no other software like putty or teraterm is using the com port). Close Atmel Studio and the putty terminal. The firmware upgrade is successful if you see a PASS sign on the terminal after running the code.

Connecting the Hardware, the Right Way

atmel1-1024x576

  • Connect WINC1500 XPRO board to SAMD21 XPRO connector EXT1
  • Connect I/O1 XPRO board to SAMD21 XPRO connector EXT2
  • Connect OLED1 XPRO board to SAMD21 XPRO connector EXT3
  • Connect SAMD21 XPRO to a free USB port on your PC (make sure no other USB port on your PC is in use)
  • Connect the power to the port that says “DEBUG USB”

The Software

Open the PubNub example: pubnubAtmel/PubNub_EXAMPLE.atsln (included in the code download) in Atmel Studio and you will see the following page. Make sure you choose the debugger/programmer and interface as shown below.

opening-1024x576

Include the following lines in pubnubAtmel/src/main.h:

123
#define TEST_MODE_SSID “Enter-your-SSID” (choose THE Wi-Fi access point you want the chip to connect to)
#define TEST_MODE_PASSWORD “Enter-the password-for-the-SSID” (enter the password for the same Wi-Fi connection)
#define TEST_MODE_WITHOUT_PROVISION

In pubnubAtmel/src/main.c, add the channel name and pub, sub keys.

channel-1

Build (F7 / Build -> build solution), run(continue/ green arrow/ F5/ debug -> continue).

build

Open PubNub Developer Console, use the same channel name and pub,sub keys as in the code and SUBSCRIBE.If all is well, you should see a constant stream of messages in the following format: {“columns”:[[“temperature”,”55.00″]]}

fullsetup

From there, the PubNub crew was able to collect and stream temperature data in realtime. But what’s next, you ask? Well, they needed to do something with that data, right? Visualize it!

Visualizing the Data Stream

xplained_pro_demo_gif

Bhavana and the PubNub bunch didn’t just want to display raw data off the sensor as a live-updating number; instead, their partner-in-crime Tomomi built the beautiful temperature visualization, which mocks nursery or greenhouse monitor (a typical realworld use case for realtime temperature sensors).

The interface runs in the browser, and the technology behind is quite simple, using PubNub JavaScript APIs to subscribe the data sent from the Atmel chip. It’s simple, lightweight, built entirely in JavaScript, and accessible from anywhere in the world with any kind of device – mobile phones, tablets, and any smart device, as long as you have a web browser. The main purpose behind this is to present information in most efficient manner without losing its accuracy.

In this scenario, the UI shows the current temperature, also a simple line graph, updating in realtime so that you can tell the relative changes of the temperature, raising and dropping. This particular data is simple, but when you have multiple, more complicated data, data visualization plays more crucial role.

Go Conquer IoT

This demo is read-only and reads the ambient temperature, but in reality, you want to develop products that lets your users monitor and control, i.e, bidirectional communication between devices. For instance, if you have a smart A/C, not only monitoring the current room temperature, but you need to make it controllable from a remote devices.

“With the power of PubNub APIs, you can achieve this with no hassle. I hope I am leaving you guys with enough excitement to try this demo out, and also build cooler ones,” Bhavana concludes.

In the meantime, be sure to follow our friends at PubNub and Bhavana Srinivas on Twitter!

4 thoughts on “Building a realtime temperature sensor with Atmel and PubNub

  1. Pingback: Building a realtime temperature sensor with Atmel and PubNub - Internet of Things | Wearables | Smart Home | M2M

  2. Pingback: RealTimeWeekly | Real Time Weekly: WebRTC, websockets, IoT

  3. Pingback: Creating realtime IoT dashboards and maps with PubNub | Atmel | Bits & Pieces

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s