Tuesday, 25 February 2020

IoT- Part- 2- Hardware Specification & Embedded Programming

The foundation of IoT begins with the implementation of the Physical Layer.


A modern computer consists of:
  • Motherboard
  • Processor
  • RAM
  • Graphics card
  • Expansion Slots
  • Power supply
The processor is the most important part of any computer or mobile, its basic job is to receive input and provide appropriate output.

The central processor also knows as the CPU(Central Processing Unit) handles all the basic instructions such as processing of keyboard, mouse, and other external devices connected to it.

Micro-controller:

A micro-controller is a compact integrated circuit specially designed to perform a special-purpose task.

For learning embedded programming we would prefer Arduino as it is easy to learn and no circuit development effort is needed.

Arduino:

Arduino is open source hardware and software company which designs single hardware-board and software user interface for developing prototyping digital devices.

Arduino boards is made of many processor on single board which consist of GPIO  (General Purpose Input Output) as digital and analog pins which can be interface with external peripherals or can be expanded with other devices.

Arduino board contains Atmel Controller on it such as atmega328, atmega2560 varies according to its number of GPIO pins.

Programming for Arduino is done in its own IDE(Integrated Development Environment) which is developed in the java platform and supportable in Windows, Linux, and Mac.

Atmega328 Specification (Arduino UNO Board):

  • 8 bit controller (data support).
  • 32 KB - Internal Memory (Flash Memory).
  • 16 MHz - Clock speed (Internal default frequency).
  • 4 KB - RAM.
  • 8 Analog Pin (A0 - A7).
  • 3 Timer (2 of 8 bit & 1 of 16 bit).
  • Operating Voltage - 3.7-5v.
Datasheet of atmega328 - Atmega328 Datasheet
Datasheet of  arduino Uno - Arduino Uno Datasheet and Specification






To begin with Arduino you will need an Arduino board and Arduino IDE

Note: You will also need USB A to B cable to interface with your Arduino board, make sure this is available in your purchase.

Install Arduino as normally you install any software.

Once Arduino is installed, set ESP8266 link preferences, this will be required in the future.

To add preferences Go to File -> Preferences -> At the bottom 'Additional Board Manager URLs' and paste below link and click 'OK'

https://arduino.esp8266.com/stable/package_esp8266com_index.json


As we know Arduino has GPIO pins for input & output purposes, before using any of these pins you need to configure them according to requirement. These pins can behave as an INPUT or an OUTPUT.

Configuring pin as INPUT or OUTPUT:

PIN as INPUT:

Used to read an input from outer peripheral devices such as Sensors, LED as Photo-diode, when pins are declared as input they are considered to be in High-Impedance state (Output is disconnected electrically from the circuit or these pins don't drive any output). However these pins may also generate electrical noise with nothing connected or with nearby pins.

To check state if no input is present these pins are connected with Pull-up Register to +5v or Pull-down register to GROUND.

Syntax: pinMode(pinNo, INPUT);


PIN as OUTPUT:

Used to provide current to peripheral device connected to them, when pins are declared as Output they are considered to be in Low-Impedance state, it is highly suggested to connect register of 450 to 1 k ohm between output and peripheral devices. Running high current devices directly from arduino may damage these pins or atmega controller.

Syntax: pinMode(pinNo, OUTPUT);


PIN as INPUT_PULLUP:

Defining pins as INPUT_PULLUP revert the behavior of data, where HIGH means sensor if OFF and LOW means Sensor is ON. Value of Pull-up vary from controller to controller. In AVR controllers, the value is between 20 k and 50 k ohm. This can be find in datasheet of the controller.


Note: Digital pin 13 is already connected with LED and Register (in most of the arduino board), so its difficult to configure this pin as INPUT. If you attempt to do it you won't get expected (+5v) input because connected register will drop down the voltage level up to 1.7v (is considered as LOW). If using this pins is necessary, configure it as INPUT and connect external pull-down register.


Writing HIGH or LOW value to digital pins:

Note: For basics operation before writing HIGH or LOW value to any digital pin, it is necessary to configure it as OUTPUT.

Once the pins are configured as OUTPUT they can be written as HIGH or LOW value. Corresponding voltage is set (+5v for HIGH) and (0v for LOW). 

Syntax:
digitalWrite(pinNo, HIGH); //set +5v as output
digitalWrite(pinNo, LOW); //set 0v as output


Reading digital value of pins:

Has specific of reading the state of digital pins whether it's HIGH or LOW.

Syntax: digitalRead(pinNo); //Returns either 0/1


Note: There are two possible ways of defining pin as INPUT_PULLUP.

1) pinMode(pinNo, INPUT_PULLUP);
2) pinMode(pinNo, INPUT);
    digitalWrite(pinNo, HIGH); 


Now you are ready to begin with your first Arduino Program. Connect your UNO board with your Computer using USB Cable, make sure you are able to see power supply LED glowing after connecting it.

Connect your arduino board and set the tools value for 'Board' and 'PORT' as shown below.


Arduino programming structure is divided into 3 part

1) Global Declaration:
Everything that is declared outside of 'void setup()' and 'void loop()' is considered as global declaration such as variable (integer, float, char) or defining macros.

2) void setup():
Code that is meant to be run only once is declared in void setup() function such as setting pin configuration, assigning values to variable. 

3) void loop(): void loop() is the part where your whole bunch of code is going to be executed infinitely.

Task 1: Glowing arduino on board led (pin 13).


To glow a led and output voltage is required, that means we need to config pin as output.
Applying configuration is a one time process, so this must be performed in void setup().

Note: By default arduino pins are config as INPUT.


To provide an output voltage we need to set pin as HIGH(+5v).


Compile your program using shortcut Ctrl+R, after successful compilation we are ready to upload using Ctrl+U.

Once uploading is complete you will be able to see Orange led glowing continuously.


Thinking logically: Blinking requires turning led ON and OFF with specific time of interval.


delay(): delay is used to pause the execution of program for specific amount of time, delay in arduino uses millisecond as its parameter.

Syntax: delay(ms) // ms is whole number 

Lets try with interval of 500 ms.

As we need process of blinking to be executed for  infinite amount of time, this is where void loop() will have our back.


Note: Putting delay setting pin as HIGH won't effect digitalWrite function that means Pin 13 will be HIGH unless no further command is given for it, same will be applicable for pin as LOW also.

Uploading this program will result of blinking led with time interval of 500 ms. Try with some different value as delay.


Practice Task:


In the next part, we will begin with Arduino Serial Communication.

For future learning part, it is suggested to arrange some below-mentioned hardware online or from the local market.

  • NODEMCU ESP8266 -1 qty
  • Arduino Mega (Optional) - 1 qty
  • HC-05 Bluetooth - 1 qty
  • Breadboard - 1 qty
  • 5v Led - 5 qty
  • Resister - 5 qty
  • Jumper wire Male to female - 10
  • Jumper wire Male to Male - 10
  • LM35 Temperature sensor - 1 qty
  • IR sensor module - 2 qty
  • Raspberry pi 3 or 4 (Optional) - 1 qty

Please comment if you have any query or suggestions for improvement of content delivery. 

Saturday, 22 February 2020

IoT- Part- 1- Introduction to IoT (Internet of Things)

Why Internet is so important in our life?

   1) Social Networking

Keeping personal information in-front of public is very trending since the launch of facebook, this info contains details of there working profile, relationship status, location, their content interest, and activities etc.

Also it enables marketing, small business growth, communication with clients. 

2) Information Access

Information access without any outdoor efforts is the ability for an individual or group to seek, receive and impact information effectively.

Weather report, News, current affairs, trending entities, solution for any problem, audio, video, and any type of digital information is highly requested in every second.

Search engines like google, yahoo, bing, duckduckgo, etc are the broker to connect these peoples with Information.


3) Services

Internet has not only made it easier but has created new business options as well.

Drop Shipping, affiliate marketing, eBook, online booking, social media, virtual intelligence, freelancing, online education, eCommerce, and many more are highly profitable businesses idea domain, which will never get down in upcoming future.

Online shopping is one of the most fascinating service which will never get old.


Data Driven model which in simple is a technique used by organisation to provide better service's to their customer by doing analysis on customer searches, interest of content, regular behavior, search pattern and many small things, to provide better result or suggestion whenever customer visit their site again. YouTube, Instagram, Facebook are very good example of this.

Many IT industries are getting down as they don't analysis the interest or pattern of their costumer.


IoT (Internet of Things)

Their is no official definition for IoT. You can create it of your own based on how you want to express it to others, for me...

IoT is simple implementation of system which contains the method of real-time retrieval of data same as we normal human retrieve by the mean of software control and embedded objects such as sensors, actuator, software, etc. These data occupies very low memory consumption such as Boolean, Character and Integer. 

By 2025 it is predicted to become a $8 billion industries and approximately 40 to 80 billion devices to be connected at that time.

Technologies that makes IoT possible

  1. Big Data (unstructured data)
  2. Cheap sensors (50% cheaper)
  3. Cheap bandwidth
  4. Cheap processing
  5. Smart devices
  6. Ubiquitous wireless

Application area of IoT

  • Industrial - Factory, Machines, Car, etc.
  • Consumer - Home appliances, Phone, TV, etc.
  • Government - Grid system, City, Public vehicles.
  • Health Sector - Doctors can get prepared in by looking patient previous data, real time monitoring of Heartbeat, pulse, blood pressure, etc.

Predictive Management - IIoT (Industrial Internet of Things)

Highly used in Qualical-Case-Study to understand the gap between Demand vs Supply, Smart Grid, Gulf Industries, Save Energy for tomorrow world.



IoT System Architecture (Basic)



Sensors (Physical Layer):

Sensors are the smart object capable of sensing the data according to their specification such as temperature sensor sense 'temperature', pressure sensor sense 'pressure', object sensor senses 'object' and many more are available like this.

These sensors are having special and specific internal hardware structure which convert the electrical data (analog/digital) for you and can be further converted into meaningful information by applying logical calculation in program.

Don't worry we will apply this in real once we start learning the basics of controller programming and hardware interface.

Gateways/frameworks (Network and Communication Layer):

Gateways are the carrier between your hardware(sensors) to server(cloud) to software(smartphone).

WiFi, GSM, Bluetooth, LTE, Xbee, SigFox, NB IoT, NFC, Lora, etc are very cheap and efficient communication medium devices, these devices are used for implementing IoT as on localhost or online services.

Communication module:

Lora can communicate up-to 15 km without internet.
NB IoT - has deep penetration capabilities.
6 Low Pan is nothing but the modified version of IPv6.

Cloud server (Transport & Application Layer):

A cloud server is a hidden physical server running in a virtual environment that can be accessed remotely from anywhere around the world using the internet.

The transport layer is the implementation of the TCP/UDP protocol.
The application layer is an implementation of Software, and some new protocols apart from HTTP.

This protocol needs to be very low weighted, which about them we will see in future.

Mobile (Edge Devices & Computing Layer):

The computing layer contains some important points which should be kept in mind while developing of IoT network:
  • Providing security to all connected devices.
  • Assigning an IP address to these devices.
  • Providing a connection to all devices in a single network or gateway. 


The network at the end may contain 'n' number of connected devices which may be connected to a common gateway or to another network, these devices receive the data at the same time from the server. 


In advance of this network architecture, there is the execution of analysis of data mainly on the cloud, which is used as a prediction of next up-coming data, or for finding the meaningful information from the collection of these data's at the end app.



In the next part, we will start with some basics fundamentals of Hardware.

Purchase Arduino UNO board: from here

Download Arduino IDE: from here

All +ve / -ve Reviews & Suggestions are heartily welcome.

IoT- Part- 4- IoT Communication Protocol

Implementation of IoT is of no use unless or until we overcome some existing problems. As we are very much familiar with the most wide...