Internet of Things (IoT) is one of the hottest technologies across the globe nowadays. There are a number of IoT products and devices that are available in the market.
At the end of this blog, you will have a high-level idea of how IoT systems work. To understand, we will create an iOS demo app which will send/receive data from an IoT compatible device with the help of Arduino.
We will cover the following points:
- Introduction to IoT
- Arduino Overview
- iOS demo App to understand the end-to-end flow
Introduction to IoT
- The connected world of devices, people and data helps to create numerous business opportunities for many sectors. For example, if I own a car parts manufacturing business, I might want to know which parts are the most popular. With IoT, I can use a sensor in a showroom to detect which areas are more popular or in which area a customer spends more time. I can then use this data to identify parts and increase the production of these parts.
- Real-time updates offer resources to improve accuracy in decision making.
- Costs of IoT components have significantly gone down which effectively means that the cost of IoT-linked devices is getting more affordable day by day.
Along with the above, there are many other opportunities which have accelerated the market for Internet of Things. It is predicted that by 2020, 25 billion IoT devices will be available in the market. The network in IoT will be decided on factors such as range, data, security, and power. These factors will decide the choice of network: whether it is the internet, Bluetooth, WiFi or something else.
IoT is also used for devices that with no internet connection. It is used for devices that can communicate with a network which such as internet, Bluetooth, NFC etc. For short-range communications, Bluetooth is the preferred technology. It is expected to be the key for wearable products. For example, Smartwatch, Fitness band.
Arduino Overview
We know how to send or receive data over the internet from an iOS app. But many of us don’t know how this data operates the IoT devices. There are open source hardware and software available in the market which is used to control the IoT devices. One of these is Arduino.

Arduino is an open-source hardware and software. Arduino boards are able to read inputs from different sensors and turn it into an output like turning on an LED, activating a motor or publishing it over the internet. These boards can take the following input and output:
- Temperature, Humidity, Pressure etc
- Light, Infrared signals
- Sounds
- Motion captures
- Heart rate, muscle movement
- Electrical current
- Touch, Fingerprints
- LEDs
- LCDs
- Speakers
- Motors
- The internet
- ATmega 328 8bit chip
- 5-20V power supply
- 32 KB flash memory
- 20 I/O pins
You can tell Arduino boards what to do by sending a set of instructions to the micro-controller on the board. For this, we have to use Arduino Software (IDE) and Arduino programming language.
Arduino IDE
To write code and upload it to the board, Arduino IDE is used. It is available for Mac, Windows, and Linux platform. You can download it from https://www.arduino.cc/en/Main/Software.
Arduino programming language
- setup( ) – Every program should have this function. This runs once at the start of the program like main () function. You can do the initialization in this function.
- loop( ) – Every program should have this function. This gets called repeatedly. You can use it to actively control the Arduino board.
- pinMode() – Set a pin as input or output
- digitalWrite() – Set a digital pin high/low
- digitalRead() – Read a digital pin’s state
- analogRead() – Read an analog pin
- analogWrite() – Write an analog value
- delay() – Wait an amount of time
int ledPin = 3;
// setup initializes serial and the LED pin
void setup(){
Serial.begin(9600);
pinMode(ledPin, INPUT);
}
// loop checks the LED pin state each time and broadcast it whether it is high or
// low
void loop(){
if (digitalRead(ledPin) == HIGH)
Serial.write('H');
else
Serial.write('L');
delay(1000);
}
iOS Demo App
I have created a sample iOS demo app which will send/receive data over Bluetooth. For that, I have used Core-Bluetooth framework. You can download it here.
Lets see the Bluetooth connectivity coding part now.
CBCentralManager

Scan for peripherals

Discovering Peripherals
When the central manager discovers a peripheral while scanning, it invokes didDiscover delegate method. You can use the peripheral information received in this method parameters.

Connecting to a Peripheral
To send a connect request to the discovered peripheral, we have to call connect method of central manager class along with the peripheral information.

We will get a notification after the creation of a successful connection with the peripheral. didConnect delegate method gets invoked to notify this.
Discovering Services
Now, we can discover peripheral’s services by using the central manager. To notify discovered services, it will call the didDiscoverServices delegate method.
Discovering Characteristics
Similar to services, the central manager has didDiscoverCharactaristics delegate method to notify about characteristics of the specified service.

In this method, we can register for characteristics in which we are interested in.
Read/Write Data
After registration, whenever there is a change in registered characteristics, central manager will invoke didUpdateValueFor delegate method. In this method, we can read and handle the new incoming data.

To write data to external peripheral, we need to call writeValue method.
Steps To Run
- Upload LED demo program on Arduino board by using Arduino IDE. You will find more details for uploading it in the referenced link above.
- On successful upload, keep power up Arduino board.
- Launch iOS demo app. It will automatically connect to the board on which the program is uploaded.
- Once it is connected, the red line in the app turns green. Now you can send instructions to turn the LED on-off on the board by using this app.
You can modify this demo program for the internet instead of Bluetooth. For internet network, Arduino board has the capability of broadcasting data over the internet.
Conclusion
This article is a good starting point for anyone interested in connecting an iOS app to an IoT device using Bluetooth Low Energy (BLE). We saw how to hook up an Arduino board with an iOS app. We have an LED on Arduino board, but we can easily connect any other sensor to it. You can find the sample projects on github. I hope you’ll find these projects useful. Good luck and have fun!