Stream Sensor Readings Data with TI LaunchPad

4 min read Michael Carroll on Nov 21, 2014

Hello world! The kind folks at PubNub were nice enough to let me hijack their blog today. In this tutorial, I’d like to showcase what is possible when we combine PubNub with embedded hardware, in the form of the LaunchPad Development Kits from Texas Instruments.

We are going to use PubNub to stream sensor readings from 4 different sensors (from Seeed Studio) & visualizing those readings on

  • Potentiometer (turn knob)
  • Moisture sensor
  • PIR motion sensor
  • Ambient light sensor

Exciting stuff! Within a few minutes, we can easily demonstrate how real-world information can simply become just another variable for web developers & iOS/Android developers to incorporate into their applications. This enables “app-cessories” like a phone-connected tennis racket, or the cloud-enabled crock pot, or maybe (just maybe) we can finally live in a world that has the quintessential “Internet of Things” product — the tweeting fridge!

Introducing the TI LaunchPad and Energia

The brain of this operation is a tiny microcontroller from Texas Instruments. TI offers a broad portfolio of low-cost, easy-to-use microcontroller development kits, called “LaunchPad”. These LaunchPad development kits start at just $9.99 and offer a low-cost & intuitive point of entry for microcontroller development (

These LaunchPad development kits can be programmed using intuitive programming tools, including the easy-to-use Energia IDE ( Energia is an open source project that is a fork of the popular Wiring framework.

stream sensor readings
This means a HUGE repository of code examples & libraries will work on these LaunchPad development kits. The same Wiring APIs that you may already be used to will work on these LaunchPad boards (i.e. analogRead(), digitalWrite(), etc). Even the Wiring-based Ethernet & WiFi libraries have been ported over. Energia is open source, cross platform & free.

With the latest version of Energia (v14 & newer), the PubNub library comes pre-packaged with the tool.

So let’s get on with the tutorial!


  • MSP-EXP430F5529LP LaunchPad Kit
  • CC3100 WiFi BoosterPack plug in module
  • Grove Base BoosterPack from Seeed Studio
  • Grove sensor modules
    • Ambient Light (plugged into pin 23)
    • PIR motion (plugged into pin 24)
    • Potentiometer (plugged into pin 25)
    • Moisture (plugged into pin 26)

Once we plug them all together, our hardware is ready to go!

The video below walks through plugging in the hardware:

So how about the software?

Download the latest version of Energia @

You will want version 14 or newer, since this is when we started to package the PubNub library in Energia. Once installed, go ahead & launch it.

Once launched, we need to configure Energia. First, we need to tell Energia which board we are using. In this tutorial, I am using the TM4C123 LaunchPad. However, the MSP430F5529 LaunchPad can be used as well.

File > Tools > Board > [Select your LaunchPad]

Then, we need to tell Energia which Serial Port we are using:

File > Tools > Serial Port [Select your COM port. Check your computer’s device manager to identify which one.

Now, we can use the example sketch below, which is a modified version of the default “PubNubJsonWifi” example that comes packaged in Energia. A few changes were made to interface with the sensors in our example.

In the example sketch below, we are only publishing data to PubNub. However, the PubNub Energia library also enables the LaunchPad kit to subscribe to specific PubNub channels as well to enable bi-directional communication with the cloud. PubNub also provides several SDKs for different runtimes & environments, which makes it possible for our cloud-connected LaunchPad kits to interface with different environments!

Lastly, this demo is encoding the 4 sensor readings into a JSON message that is published to a single PubNub channel. Alternatively, it is possible for the sketch to publish the individual sensor readings to independent PubNub channels — up to you & your application’s needs!

The video below walks through the software:

In short, the Energia example does a few things:

  • setup() function
    • Start & configure Serial port
    • Connect to WiFi
    • Connect to PubNub
  • loop() function
    • Read analog sensor readings
    • add latest sensor readings into a JSON object
    • Publish and stream sensor readings data to PubNub
    • Here’s the code:

Visualizing Sensor Data with

Now that our LaunchPad is publishing sensor data, let’s visualize it using
Let’s start to visualize our data! Navigate to & create an account. Freeboard offers PubNub integration as a data source. The video below showcases how to quickly receive data from PubNub. Freeboard offers intuitive JSON parsing, which can break up our incoming sensor data that we can associate to different cloud-side widgets.

That’s a wrap!

Rapid prototyping internet-connected applications are getting easier than ever. The TI LaunchPad development kits, especially when paired with the Grove Starter Kit from Seeed Studio, offer an easy & affordable open source, modular approach to create hardware solutions that can interact to the cloud.


Adrian Fernandez is LaunchPad Product Manager at Texas Instruments.