Tools to Help You Write Apps That Use Sensors

  January 22, 2014

Sensors increase computers’ capabilities to interact with the environment. Sensors provide unique data input, such as the computer’s location on earth or the amount of ambient light in which the computer is operating. These inputs can give your mobile apps even more useful functionality. However, writing sensor code from scratch is both time consuming and difficult, so it’s essential to know which tools can help your software perform the task. Here are a few resources to help you get started.

Computing systems require input, and the traditional devices have been keyboards, mice, and joysticks. For specialty purposes, your software might also get data from touch, vocal, and musical instrument sources. In every case, the input is provided in numeric form; even pressing a key on a keyboard generates numbers.

Sensors provide another type of data input (also in numeric form). The difference is that the data source is an interaction with the real world in some way: location, temperature, movement, etc. Even a Global Positioning System (GPS) sensor relies on input from a geostationary satellite. With people relying on mobile devices to perform all sorts of tasks – from getting to a friend’s house to determining whether an exercise routine is working properly – more and more developers are engaged in working with specialty sensors.

If you’re new to incorporating sensors in your application development, you aren’t the only one. Today, 38% of North American developers write software that uses sensors, according to Evans Data's North American Development Survey, and those developers feel the primary problem in doing so is a lack of tools to help them with the task. In this article, I give you a few ideas of where to start.

Understanding the Sensor Types

Sensors can monitor internal conditions, external conditions, or a combination thereof. Most sensors are built right into the system, so you might have access to a wealth of sensors and not even know it. The most common sensors attached to computers (and mobile devices) today include:

  • Fan speed (internal)
  • Temperature (internal/external)
  • Voltage (internal/external)
  • GPS (external)
  • Ambient light (external)
  • Compass (external)
  • Accelerometer (external)
  • Gyroscope (external)

However, the number of sensors you can attach to a system is basically unlimited. For example, many medical monitors (heart, EKG, and others) attach to PCs. Security systems rely on sensors (such as breaking glass detectors) attached to PCs to protect your home and valuables. Astronomers use sensors to take pictures of the heavens; biologists rely on other sensors to photograph the microcosm in a glass of water. Industrial processes use exotic sensors to monitor the structure of materials, and your car’s computer uses sensors to monitor the condition of your brakes. In short, you’re surrounded by sensors that monitor your environment and protect you from harm.

These also spell new opportunities for developers. For example, the new Tao Wellshell is a motion tracker and fitness gadget that uses isometrics to build a workout; it measures compressive power and produces precise exercises using the body’s own muscle power against it.

Many sensors don’t directly connect to the computer, but rather communicate with it through a network connection or via the Internet. For example, Rest Devices produces Mimo, which monitors babies via clothing with embedded sensors that communicate with a parent’s smartphone to alert parents to conditions leading to Sudden Infant Death Syndrome (SIDS). An app for your bicycle uses Bluetooth together with sensors to provide athletes with real-time training data. The point is that sensors often communicate with a computer through a network connection, which means a developer must create an app to monitor the sensor input.

Operating System Support

A few operating systems provide some level of support for common sensors. For example, Windows 7 and Windows 8 provide support through the Windows Sensor and Location Platform, an API that greatly simplifies the task of interacting with various kinds of common sensors. Likewise, you can find sensor API support for the Windows Phone. Android developers will also be happy to note an established API that works much like the API for Windows. Linux developers are currently working on a sensor API for their platform.

The problem is finding a place to put the required API in the operating system. There is definitely a difference between human and sensor input, so ensuring the required API interacts with underlying operating system correctly is a major consideration.

Mac developers have the hardest time obtaining access to sensors. In order to access a sensor for iOS, developers must often resort to writing low-level code in Objective C. This is the kind of worst-case scenario that developers want to avoid.

However, it’s not absolutely essential that a platform provide direct sensor support. Where operating systems fall short, software development tool vendors see opportunity. Thus, you always have third-party options you can rely on.

[dfads params='groups=937&limit=1&orderby=random']

Third-Party Platform APIs

Operating systems generally support the common sensor types, such as ambient light detectors. If you want to work with something a little more exotic, you must generally turn to a third party supplier. The problem is that some sensors require truly custom programming today (we’re talking reacting to individual bits within an embedded system), so you need to ensure that the sensor you want to use has an associated API to support it.

Fortunately, companies such as Arduino produce prototyping boards and associated software to work with a broad range of sensor types. These setups can directly react to the input to perform tasks such as controlling lights based on the kind of input received. In addition, the board provides the means to communicate directly with computer systems over a network connection. Arduino software works with Windows, Mac, and Linux systems.


Another interesting API, Processing, is actually a programming language with a host of interesting libraries. Even though the language was originally intended for those engaged in the visual arts, many of its libraries make this language useful for someone who needs to interact with sensors in non-traditional ways. For example, one library lets you analyze the input from a camera to do things like detect threats. Another library helps your application determine the direction of sounds using two sound sensors and stereoscopic detection. One library makes it easier to work with Arduino board output; another directly interfaces with the Apple light sensor. There is even a library for working with the NeuroSky Mindset brainwave sensing headset, just in case you want to think your way through life. This API also works with Windows, Mac, and Linux systems.

Some APIs are special purpose. For example, if you want to work with 3D sensors, then you need to look into OpenNI. Let’s say you want to detect where someone is grabbing within a 3D space. The OpenNI SDK provides the means to perform that sort of detection. The idea is that you can create environments where users interact with systems in non-traditional ways, or you could use the setup to monitor the movement of goods in a warehouse. The possibilities for detecting and reacting to conditions within a 3D space based on various sensor inputs are endless.

The one thing that many developers complain about when it comes to sensors is a lack of tools for a specific need in a specific environment. For example, not everyone wants to create a solution using Processing. Finding a library, SDK, or other tool to fit a specific need can be daunting. Here are a few other libraries, SDKs, and other tools to check out.

  • BITalino API: Helps your application to react to body movements or other physiological sensors.
  • Estimote Platform: Provides sensor-based engagement, interaction, and analytics for interacting with people (such as customers for a business).
  • ioBridge API: Makes it possible to connect sensors to Web services, receive alerts, and data log the results.
  • Mote Runner Development Platform: Connects sensor and actuator motes within wireless sensor networks, making it possible for any number of devices to monitor, manage, and interact with a variety of sensor types.
  • Scout API: Provides the means to access smartphone sensors, which allows you to tailor the application experience for each individual customer based on their behavior and activity.
  • Xively REST API:  Stores, shares, and discovers real-time sensor, energy and environment data from buildings or other devices. Interestingly enough, this is yet another way to interact with Arduino board output.

Bottom Line

When working with sensors, keep in mind a few basic facts to avoid potential problems. First, remember that sensors are designed to provide numeric input to the computer that an application must manipulate in some way in order to obtain platform- or human-usable output. Second, in order to gain input from the sensor, you need some means to access it, which might mean writing low-level code when an existing device driver or platform support is missing.

Finally, consider just how the sensor performs its task—what range and type of input it can provide. Many developers are thwarted in their efforts when they discover they have the wrong sensor for the job. However, even with these caveats, it’s possible to use sensors to perform an amazing array of tasks—some that you might find unimaginable.

See also:

[dfads params='groups=933&limit=1&orderby=random']