Build An Ios Application That Interfaces To IoT Device Using Bluetooth
Manufacturers and industrialists in every sector have a significant opportunity at hand where they can not only monitor but also automate many of the complex processes involved in manufacturing. While there have been systems that can track progress in the plant but the industrial IoT (IIoT) technology provides far more intricate details to the managers.
IoT
The internet of things, or IoT, is a system of interrelated computing devices, mechanical and digital machines, objects, animals or people that are provided with unique identifiers (UIDs) and the ability to transfer data over a network without requiring human-to-human or human-to-computer interaction.
Why IoT is important
The internet of things helps people live and work smarter as well as gain complete control over their lives. In addition to offering smart devices to automate homes, IoT is essential to business. IoT provides businesses with a real-time look into how their companies’ systems really work, delivering insights into everything from the performance of machines to supply chain and logistics operations.
IoT enables companies to automate processes and reduce labor costs. It also cuts down on waste and improves service delivery, making it less expensive to manufacture and deliver goods as well as offering transparency into customer transactions.
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 operate 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 the 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 inputs and outputs:
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
There are different types of Arduino boards available depending on features like an ethernet port, wireless or USB device support. Common specification of these hardware boards are:
- 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 the 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 platforms. You can download it Here.
Arduino programming language:
The coding language that Arduino uses is very much like C++, which is a common language in the world of computing.
Two important functions in Arduino language are:
- setup( ) – Every program should have this function. This runs once at the start of the program like the main () function. You can do initialization 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 the language at https://www.arduino.cc/reference/en/.
Once you write the code, you can upload it to the Arduino board by using Arduino IDE. You can download a demo Arduino program to turn LED on-off. This program sends/receives data over the Bluetooth and turns on-board LED on-off depending on the data received. Also, this will broadcast the state of the LED pin. You can use the Arduino Leonardo board for this demo.
You can modify this demo program for the internet instead of Bluetooth. For an internet network, an Arduino board which has the capability of broadcasting data over the internet is required.