Remote Thermo Couple Sending Temp to iPhone

Intro

After my first experiment of using a simple build iPhone app to send info to control an external lamp I wanted to try something with data flowing in the other direction. So I chose to set up a simple circuit with a temperature sensor, and then send this data to a simple iPhone app to display the temperature.

Ingredients

  • Arduino (Genuino) Uno, Microcontroller
  • Red Bear Labs BLE Shield 2.1
  • Breadboard
  • Temperature Sensor (TMP36)
  • Power Source (computer via USB or 9V battery)
  • Jumper Wires
  • iPhone

Set Up The Circuit

Nothing complicated here. The temp sensor has 3 pins: run one to power, one to ground, and one to an analog input port on our Arduino. I used my laptop to power the board for this quick hack, but of course a battery to power the board is also an option.

Program The MicroController

Here is where the learning really started for me on this project. How would I send the data package? How would it be received by the phone and will I need to process it at all? My first thought was ‘I want to read the temperate as a float value (like 24.12 C), so I would capture and pass a float’. Makes sense and is certainly possible but I quickly realized the float was wanting to send a large data packet for this one simple number ,as the float is stored down to many many decimal places.

So I changed my approach for a simpler one. I would capture the temperature value as a float on the Arduino, then convert it to a string with only 2 decimal places and then send this simple 5 character string via bluetooth to the app. (I hard coded ‘5 characters assuming a temp range of 10 C and 99C for this quick experiment project). Code below:

Program The App

Once again, my life is made easy thanks to the Read Bear Labs framework. I initiate a global instance of the framework class (not good coding, but quick and easy for my test here) and fire up the read method on the view load of my main view controller. I also add a variable property to the BLE class called tempValue and initiated it with a value of 0. Within the BLE method

I capture the updated value received and send a notification to the notification center.

In the main view controller I watch for updates for this notification, and when there is one I pull the BLE class property value of tempValue variable, set that value to the label text and update the view.

Result

Power the circuit and fire up the app and voila — room temperature updated every second. Or squeeze the thermocouple in my fingers and watch the temperature rise. :)

Father, Husband, Tinkerer, Learner, Project Manager, Programmer, Engineer, Expat

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store