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.