You must be aware of term “IoT” Internet of Things, this is one of the hot technology worldwide nowadays, as many products, devices are available in the market.
I won’t say detailed knowledge of IoT, but at the end of this article, you will have a high-level idea of how IoT system works. To understand it, we will create an iOS demo app which will send/receive data from IoT compatible device with the help of Arduino.
In this article, we will cover following points:
– Introduction to IoT
– Arduino Overview
– iOS Demo App to understand 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 car parts manufacturing business then I might want to know which parts are most popular. Using IoT, I can use a sensor in a showroom, to detect which areas are more popular or in which area customer spends more time. I will use this data to identify parts and increase production of these parts.
- Real-time updates offer resources to improve decision making more accurate.
- 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.
There are many other opportunities which accelerated the market for Internet of Things. It is predicted that by 2020, 25 billion devices will be available in the market.
The network in IoT will be decided on the factors such as range, data, security, and power. These factors will decide the choice of network whether it is the internet, Bluetooth, WiFi or any other. IoT is used for the devices that would not necessary to have an internet connection. It is used for a device that can communicate with the network which can be the internet, Bluetooth, NFC or anything else. For short-range communications technology is of course Bluetooth. It is expected to be key for wearable products. For example, Smartwatch, Fitness band. There are many sources available for IoT, so we will not dig into this.
Arduino Overview
Arduino is an open-source hardware and software. Arduino boards are able to read inputs from the different sensors and turn it into an output like turning on an LED, activating a motor or publishing it over the internet.
Inputs:
- Temperature, Humidity, Pressure etc
- Light, Infrared signals
- Sounds
- Motion captures
- Heart rate, muscle movement
- Electrical current
- Touch, Fingerprints
Outputs:
- 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 microcontroller 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 at https://www.arduino.cc/en/Main/Software.
Arduino programming language:
Two important functions in Arduino language are:
- setup( ) – Every program should have this function. This runs once at the start of the program like main () function. You can do initialisation stuff in this function.
- loop( ) – Every program should have this function. This gets called repeatedly. You can use it to actively control the Arduino board.
Other Useful Function:
- 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
Example Code:
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);
}
You will find more details about language at https://www.arduino.cc/reference/en/.
Once you write the code, you can upload it on Arduino board by using Arduino IDE. You can download demo Arduino program to turn LED on-off. This program send/receives data over the Bluetooth and turns on-board LED on-off depending on data received. Also, this will broadcast state of the LED pin. You can use Arduino Leonardo board for this demo.
iOS Demo App
Steps To Run:
- Upload LED demo program on Arduino board. You have to upload it 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 connect automatically to the board on which program is uploaded.
- Once it is connected, red line in the app turns green. Now you can send instructions to turn LED on-off on the board by using this app.
- Once it is connected, red line in the app turns green. Now you can send instructions to turn 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 which has a capability of broadcasting data over the internet is required.
Conclusion
This article is a good starting point for anyone who is interested in connecting an iOS app to IoT device using Bluetooth Low Energy. We saw how to hook up an Arduino board with an iOS app. We have a 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!