0% found this document useful (0 votes)
34 views46 pages

Unit 1 2

The document discusses embedded systems, including their characteristics, types, advantages, disadvantages and applications. Embedded systems are computer systems designed to perform specific tasks, have low power consumption and cost, and are used in applications such as consumer electronics, automotive, medical devices and industrial automation.

Uploaded by

Harini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views46 pages

Unit 1 2

The document discusses embedded systems, including their characteristics, types, advantages, disadvantages and applications. Embedded systems are computer systems designed to perform specific tasks, have low power consumption and cost, and are used in applications such as consumer electronics, automotive, medical devices and industrial automation.

Uploaded by

Harini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

U21ECG04 -Internet

of Things and its


Applications [UNIT I – OVERVIEW OF EMBEDDED SYSTEMS]

UNIT I: OVERVIEW OF EMBEDDED SYSTEMS


Embedded System-Features and Characteristics- Simple Embedded System model-
Microprocessor Vs Microcontroller- Microcontroller Unit-8 bit MCU- Functional Blocks of
mobile phone

EMBEDDED SYSTEM
Embedded systems are integrated system made up of computer hardware and software
that performs a specific job. These embedded systems can operate independently or as
part of a larger system and may require minimal or no human intervention to function.
The use of embedded systems has become increasingly common in a wide range of
industries due to their reliability, efficiency, and ability to perform tasks that may be
too complex or time-consuming for humans to complete.

Types of Embedded Systems

Here are some common types of embedded systems:


Microcontroller-based Embedded Systems: These are embedded systems that use a
microcontroller as the main processing unit. They are commonly used in small-scale applications
such as household appliances, toys, and automotive systems.
Real-time Embedded Systems: These are embedded systems that are designed to respond to
external events or input signals within a specified time frame. They are commonly used in critical
applications such as aerospace, defense, and medical devices.
Networked Embedded Systems: These are embedded systems that are connected to a network and
can communicate with other devices. They are commonly used in applications such as home
automation, building automation, and industrial control systems.
Mobile Embedded Systems: These are embedded systems that are designed for use in mobile
devices such as smartphones, tablets, and portable gaming devices. They are optimized for low power
consumption and high performance.
Programmable Logic Controller (PLC) Systems: These are embedded systems that are commonly
used in industrial automation applications to control machinery and processes.
Digital Signal Processing (DSP) Systems: These are embedded systems that are optimized for
processing signals such as audio and video. They are commonly used in applications such as
telecommunications, multimedia, and image processing.

Advantages of Embedded Systems

Embedded systems offer several advantages, including:


Improved System Performance: Embedded systems are designed to perform specific tasks and are
optimized for efficiency and performance. They can deliver faster response times and higher accuracy
compared to general-purpose computing systems.
Lower Power Consumption: Embedded systems are optimized for low power consumption, making
them ideal for battery-powered devices or systems that need to operate in remote or inaccessible
locations.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 1


U21ECG04 -Internet
of Things and its
Applications [UNIT I – OVERVIEW OF EMBEDDED SYSTEMS]

Increased Reliability: Embedded systems are designed to be reliable and stable, with minimal
downtime or errors. They can operate in harsh environments and withstand temperature, humidity,
and other external factors.
Cost-Effective: Embedded systems are often less expensive compared to general-purpose computing
systems. They require fewer hardware components and are optimized for specific tasks, reducing the
overall system cost.
Compact Size: Embedded systems are designed to be small and compact, making them ideal for
applications where space is limited, such as in cars, aircraft, and medical devices.
Customizable: Embedded systems can be customized to meet specific application requirements,
allowing for greater flexibility and functionality.
Improved Security: Embedded systems can be designed with built-in security features, such as
encryption and authentication, to protect against cyber attacks and unauthorized access.

Disadvantages of Embedded Systems

While embedded systems offer several advantages, there are also some potential disadvantages,
including:
Limited Functionality: Embedded systems are designed to perform specific tasks and are often
limited in their functionality. They may not be suitable for applications that require more complex or
varied tasks.
Limited Upgradability: Embedded systems are often designed with limited upgradability, which can
be a disadvantage in applications where future upgrades or modifications may be required.
Limited Connectivity: Some embedded systems may have limited connectivity options, which can
limit their ability to communicate with other devices or systems.
Difficult to Debug: Embedded systems can be difficult to debug and diagnose when issues arise,
which can be a disadvantage in applications where system downtime is critical.
Costly Development: Developing embedded systems can be complex and time-consuming, requiring
specialized skills and knowledge. This can result in higher development costs compared to other
computing systems.
Compatibility Issues: Embedded systems may have compatibility issues with other systems or
devices, which can be a disadvantage in applications where interoperability is critical.
Limited Hardware Resources: Embedded systems are often designed with limited hardware
resources, such as memory and processing power, which can limit their ability to perform complex
tasks or handle large amounts of data.

Applications of Embedded Systems

Embedded systems are used in a wide range of applications across various industries. Some common
applications of embedded systems include:
Consumer Electronics: Embedded systems are used in consumer electronics such as smartphones,
digital cameras, televisions, and home appliances.
Automotive Industry: Embedded systems are used in automotive systems such as engine
management, airbag control, and infotainment systems.
Aerospace Industry: Embedded systems are used in aerospace applications such as flight control
systems, navigation systems, and communication systems.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 2


U21ECG04 -Internet
of Things and its
Applications [UNIT I – OVERVIEW OF EMBEDDED SYSTEMS]

Medical Devices: Embedded systems are used in medical devices such as pacemakers, blood glucose
monitors, and MRI machines.
Industrial Automation: Embedded systems are used in industrial automation applications such as
process control, factory automation, and robotics.
Security and Surveillance: Embedded systems are used in security and surveillance systems such as
access control systems, CCTV systems, and biometric systems.
Defense and Military: Embedded systems are used in defense and military applications such as
weapon systems, communication systems, and surveillance systems.
Home Automation: Embedded systems are used in home automation systems such as smart
thermostats, smart lighting systems, and security systems.

CHARACTERISTICS OF EMBEDDED SYSTEM-

Performs specific tasks: Embedded systems are designed to perform specific tasks or functions.
They are optimized for the particular task they are intended to perform, which makes them more
efficient and reliable.
Low Cost: Embedded systems are typically designed to be cost-effective. This is because they are
often used in large volumes, and the cost per unit must be low to make the product economically
viable.
Time Specific: Embedded systems must operate within a specific time frame. This is important in
applications such as industrial control systems, where timing is critical for safety and efficiency.
Low Power: Embedded systems are designed to operate with minimal power consumption. This is
important for applications where the system needs to operate for extended periods on battery power
or where power consumption needs to be minimized to reduce operating costs.
High Efficiency: Embedded systems are designed to be highly efficient in terms of processing
power, memory usage, and energy consumption. This ensures that they can perform their specific task
with maximum efficiency and reliability.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 3


U21ECG04 -Internet
of Things and its
Applications [UNIT I – OVERVIEW OF EMBEDDED SYSTEMS]

Minimal User Interface: Many embedded systems do not require a complex user interface. They are
often designed to operate autonomously or with minimal user intervention.
Highly Stable: Embedded systems are typically designed to be stable and reliable. They are often
used in applications where failure is not an option, such as in medical devices or aviation.
High Reliability: Embedded systems are designed to operate reliably and consistently over long
periods. This is important in applications where downtime can be costly or dangerous.

FEATURES OF EMBEDDED SYSTEMS


1. Performance
The performance and accuracy of an embedded system is the main feature.It is measured
considering all the conditions and constraints on the system
2. Cost
The cost factor is another important feature. Such systems are built for performing specific
functions and in large quantities. The design process is costly but once a system is designed,
customized and produced in bulk, overall cost becomes minimum.
3. Size
One of the features of an embedded system is its size. The size should be small and it is done
by adding more functionality in a single chip so that the need for external parts is reduced.
4. Power consumption
The power consumption is also low. This feature is becoming more and more important in
new systems. Sometimes it happens that your embedded system has to be isolated and needs
to run for a very long time so in such cases the power consumption is a critical factor and it
has to be really low.
5. Reliability
Embedded systems are reliable if they are operated under normal conditions.

A SIMPLE EMBEDDED SYSTEM MODEL

Sensor − It measures the physical quantity and converts it to an electrical signal which can be read by
an observer or by any electronic instrument like an A2D converter. A sensor stores the measured
quantity in the memory.
A-D Converter − An analog-to-digital converter converts the analog signal sent by the sensor into a
digital signal.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 4


U21ECG04 -Internet
of Things and its
Applications [UNIT I – OVERVIEW OF EMBEDDED SYSTEMS]

Processor & ASICs − Processors process the data to measure the output and store it in the memory.
D-A Converter − A digital-to-analog converter converts the digital data fed by the processor to
analog data
Actuator − An actuator compares the output given by the D-A Converter to the actual (expected)
output stored in it and stores the approved output.

Embedded Systems Model have at least one layer (hardware) or all layers (hardware, system
software, and application software) into which all components fall. The hardware layer contains all
the major physical components located on an embedded board, whereas the system and application
software layers contain all of the software located on and being processed by the embedded system.
This reference model is essentially a layered (modular) representation of an embedded systems
architecture from which a modular architectural structure can be derived.
While the concept of layering isn’t unique to embedded system design (architectures are relevant to
all computer systems, and an embedded system is a type A Systems Engineering Approach to
Embedded Systems Design of computer system, it is a useful tool in visualizing the possible
combinations of hundreds, if not thousands, of hardware and software components that can be used in
designing an embedded system. In general, modular representation of embedded systems architecture
as the primary structure for two main reasons:
1. The visual representation of the main elements and their associated functions. The layered
approach allows readers to visualize the various components of an embedded system and their
interrelationships.
2. Modular architectural representations are typically the structures leveraged to structure the entire
embedded project.
This is mainly because the various modules (elements) within this type of structure are usually
functionally independent. These elements also have a higher degree of interaction, thus separating
these types of elements into layers improves the structural organization of the system without the risk
of oversimplifying complex interactions or overlooking required functionality.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 5


U21ECG04 -Internet
of Things and its
Applications [UNIT I – OVERVIEW OF EMBEDDED SYSTEMS]

MICROPROCESSOR VS MICROCONTROLLER

Microprocessor-

As its name implies, it is a processing device that converts data into information based on some sets
of instructions. It is a very compact electronic chip due to which it is referred to as
the microprocessor. In other words, a processing device implemented on a single chip is called a
microprocessor. A microprocessor is the most crucial component of a computer or any other
computing device. Because, it is entirely responsible for processing data based on instructions to
produce information.

Microcontroller

A microcontroller is an electronic system which consists of a processing element, a small memory


(RAM, ROM, EPROM), I/O ports, etc. on a single chip. Therefore, a microcontroller is a tiny
resemblance of a microcomputer. It is a quite small and low−cost electronic device which is used in
several electronic appliances as the main functioning device.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 6


U21ECG04 -Internet
of Things and its
Applications [UNIT I – OVERVIEW OF EMBEDDED SYSTEMS]

Parameter Microprocessor Microcontroller

Microprocessors can be Microcontrollers can be understood


Definition understood as the heart of a as the heart of an embedded system.
computer system.

A microprocessor is a processor A microcontroller is a controlling


where the memory and I/O device wherein the memory and I/O
What is it?
component are connected output component are present
externally. internally.

Circuit The circuit is complex due to Microcontrollers are present on chip


complexity external connection. memory. The circuit is less complex.

Memory and I/O The memory and I/O components The memory and I/O components are
components are to be connected externally. available.

Compact system Microprocessors can’t be used in Microcontrollers can be used with a


compatibility compact system. compact system.

Efficiency Microprocessors are not efficient. Microcontrollers are efficient.

Microprocessors have a zero Microcontroller doesn’t have a zero


Zero status flag
status flag. status flag.

Number of Microprocessors have less number Microcontrollers have more number


registers of registers. of registers.

Microprocessors are generally Microcontrollers are generally used in


Applications used in personal computers. washing machines, and air
conditioners.

A MICROCONTROLLER UNIT

A microcontroller (MC, UC, or μC) or microcontroller unit (MCU) is a small computer on a


single integrated circuit. A microcontroller contains one or more CPUs (processor cores) along
with memory and programmable input/output peripherals. Program memory in the form
of ferroelectric RAM, NOR flash or OTP ROM is also often included on chip, as well as a small
amount of RAM. Microcontrollers are designed for embedded applications, in contrast to
the microprocessors used in personal computers or other general purpose applications consisting of
various discrete chips.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 7


U21ECG04 -Internet
of Things and its
Applications [UNIT I – OVERVIEW OF EMBEDDED SYSTEMS]

The MCU receives inputs from buttons, switches, sensors, and similar components; and controls the
peripheral circuitry—such as motors and displays—in accordance with a preset program that tells it
what to do and how to respond.

Figure shows the structure of a typical MCU. The MCU incorporates a CPU (central processing unit),
some memory, and some circuitry that implements peripheral functionalities. If we wish to
anthropomorphize, we can say that the CPU does the "thinking," the memory stores the relevant
information, and the peripheral functions implement the nervous system―the inputs (seeing, hearing,
feeling) and the responses (hand and foot movements, etc.).

Processor Core:
The CPU is the main component of the controller. It contains the arithmetic logic unit and the
registers, stack pointer, program counter, accumulator register, register file, etc.
Memory:
A microcontroller has two types of memory: program memory and data memory. The program
memory, also known as flash memory, holds the code that the microcontroller executes. Data
memory, also known as RAM, holds variables and data that the microcontroller uses during
operation.
Microcontrollers/Microprocessors are manufactured with three types of memories:
 Flash memory
 RAM Memory
 EEPROM memory

Prepared By: CSE Department, KPRIET, Coimbatore. Page 8


U21ECG04 -Internet
of Things and its
Applications [UNIT I – OVERVIEW OF EMBEDDED SYSTEMS]

The memory is divided into program memory and data memory. DMA controller handles data
transfers between peripherals components and the memory.
Interrupt Controller:
By setting the relevant bits in the interrupt controller registers, an interrupt controller offers a
programmable governing policy that enables software to choose which peripheral or device can
interrupt the processor at any given time.
Timer / Counter:
Most controllers have at least one and more Timers / Counters. A timer is a type of clock that is
used to measure time intervals. A counter is a device that records the number of times a specific
event or process occurred about a clock signal.
Digital I/O:
This is one of the main features of the microcontroller. A digital I/O board is an interface board
that allows a computer to input and output digital signals in parallel. I/O pins vary from 3-4 to
over 90.
Analog I/O:
Most Of Microcontrollers Have Integrated Analog / Digital Converters.
Interfaces:
The serial interface can be used to download the program and for general communication with the
development PC. Serial interfaces can also communicate with external peripheral devices. Most
controllers include a variety of interfaces such as SPI, SCI, PCI, USB, and Ethernet.
Debugging Unit:
The process of debugging involves finding and fixing current and potential flaws commonly
known as “bugs” in software code that may cause it to act erratically or crash. Some controllers
include additional hardware that enables remote debugging of the chip from a PC.
Central Processing Unit (CPU):
The CPU is the core of the microcontroller and is responsible for executing instructions and
performing calculations. It is typically a low-power, low-speed processor optimized for embedded
systems.
Input/Output (I/O) Peripherals:
Microcontrollers have various input/output peripherals that allow them to interface with the
external world. These include digital and analog input/output pins, timers, counters,
communication interfaces (such as UART, SPI, I2C, and USB), and pulse width modulation
(PWM) outputs.
Power Management:
Microcontrollers require a stable and consistent power supply to operate correctly. Power
management components, such as voltage regulators, are included on the chip to ensure that the
microcontroller receives the correct voltage and current.

Uses of Microcontroller Components:

Prepared By: CSE Department, KPRIET, Coimbatore. Page 9


U21ECG04 -Internet
of Things and its
Applications [UNIT I – OVERVIEW OF EMBEDDED SYSTEMS]

Here are some uses of the components of a microcontroller:


1. Central Processing Unit (CPU): The CPU is responsible for executing instruct ions and
performing calculations. It is used to run the program code that controls the behavior of the
microcontroller in various applications.
2. Memory: The memory of a microcontroller is used to store program code and data. Program
memory, also known as flash memory, is used to store the program code that controls the
behavior of the microcontroller. Data memory, also known as RAM, is used to store variables
and data that the microcontroller uses during operation.
3. Input/Output (I/O) Peripherals: The input/output peripherals of a microcontroller are used to
interface with the external world. Digital and analog input/output pins are used to interface
with sensors and actuators. Timers and counters are used to measure time and count events.
Communication interfaces, such as UART, SPI, I2C, and USB, are used to communicate with
other devices. PWM outputs are used to generate analog signals.
4. Power Management: The power management components of a microcontroller are used to
ensure that the device receives a stable and consistent power supply. Voltage regulators are
used to regulate the voltage, and other components are used to protect the device from voltage
spikes, current surges, and other power-related issues.
5. Clock: The clock of a microcontroller is used to provide a timing signal to synchronize the
operations of the device. The clock frequency determines the speed at which the
microcontroller executes instructions and performs calculations.

Types of Microcontrollers

Microcontrollers are divided into various categories based on memory, architecture, bits and
instruction sets. Following is the list of their types
Bit
Based on bit configuration, the microcontroller is further divided into three categories.
 8-bit microcontroller − This type of microcontroller is used to execute arithmetic and logical
operations like addition, subtraction, multiplication division, etc. For example, Intel 8031 and
8051 are 8 bits microcontroller.
 16-bit microcontroller − This type of microcontroller is used to perform arithmetic and
logical operations where higher accuracy and performance is required. For example, Intel
8096 is a 16-bit microcontroller.
 32-bit microcontroller − This type of microcontroller is generally used in automatically
controlled appliances like automatic operational machines, medical appliances, etc.
Memory
Based on the memory configuration, the microcontroller is further divided into two categories.
 External memory microcontroller − This type of microcontroller is designed in such a way
that they do not have a program memory on the chip. Hence, it is named as external memory
microcontroller. For example: Intel 8031 microcontroller.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 10


U21ECG04 -Internet
of Things and its
Applications [UNIT I – OVERVIEW OF EMBEDDED SYSTEMS]

 Embedded memory microcontroller − This type of microcontroller is designed in such a


way that the microcontroller has all programs and data memory, counters and timers,
interrupts, I/O ports are embedded on the chip. For example: Intel 8051 microcontroller.
Instruction Set
Based on the instruction set configuration, the microcontroller is further divided into two categories.
 CISC − CISC stands for complex instruction set computer. It allows the user to insert a single
instruction as an alternative to many simple instructions.
 RISC − RISC stands for Reduced Instruction Set Computers. It reduces the operational time
by shortening the clock cycle per instruction.

8 BIT MICROCONTROLLER UNIT(8-MCU)

ARCHITECTURE & BLOCK DIAGRAM OF 8051 MICROCONTROLLER

The 8051 microcontroller is a very popular 8-bit microcontroller introduced by Intel in the year 1981
and it has become almost the academic standard now a days. The 8051 is based on an 8-bit CISC
core with Harvard architecture. Its 8-bit architecture is optimized for control applications with
extensive Boolean processing. It is available as a 40-pin DIP chip and works at +5 Volts DC. The
salient features of 8051 controller are given below.

The architecture of the 8051 microcontroller can be understood from the block diagram. It has
Harward architecture with RISC (Reduced Instruction Set Computer) concept. The block diagram of
8051 microcontroller is shown in Fig .It consists of an 8-bit ALU, one 8-bit PSW(Program Status
Register), A and B registers, one 16-bit Program counter , one 16-bit Data pointer
register(DPTR),128 bytes of RAM and 4kB of ROM and four parallel I/O ports each of 8-bit width.

SALIENT FEATURES :

Prepared By: CSE Department, KPRIET, Coimbatore. Page 11


U21ECG04 -Internet
of Things and its
Applications [UNIT I – OVERVIEW OF EMBEDDED SYSTEMS]

The salient features of 8051 Microcontroller are

i. Two 8-bit registers, A (accumulator) and B register.


ii. Two 16-bit registers, program counter and (data pointer) DPTR
iii. 8-bit flag register or Program Status Word (PSW)
iv. One 8-bit stack pointer
v. Inter ROM of 4 KB
vi. 128 bytes on chip data memory (RAM). Internal RAM consists of
Four register banks, each containing eight registers
16-bytes of Bit Address
80 bytes of general purpose data memory.
vii. 8-bit data bus
viii. 16-bit address bus
ix. Four Parallel ports each of 8-bits (PORT0, PORT1,PORT2,PORT3) with a total of 32 I/O
lines
x. Two -16 bit timers: T0 and T1
xi. Serial Data Reciever and Serial Data Transmitter.
xii. Control registers TCON, TMOD, SCON, PCON, IP and IE.
xiii. Five Interrupts (3 internal and 2 external).
xiv. Oscillator and Clock circuits.
Register A: The register A is an 8-bit register that is part of the ALU. This register is used to
store 8-bit data and to perform arithmetic and logical operations. The result of an operation is
strored in the register A. Register A is also identified as Accumulator. Its address is 0E0H.

Register B: The register B is an 8-bit register. It is used with the register A for multiplication and
division operations. In other words it holds the 1-byte of data during multiplication and division.
Register B holds high order byte of the result in the multiplication and remainder in the division
operation.

Program Counter (PC) : 8051 has a 16-bit program counter .The program counter always points
to the address of the next instruction to be executed. After execution of one instruction the
program counter is incremented to point to the address of the next instruction to be executed.
Since the PC is 16-bit width,8051 can access program addresses from 0000H to FFFFH, a total of
64 kB of code.

Stack Pointer Register (SP): It is an 8-bit register which stores the address of the stack top. i.e
the Stack Pointer is used to indicate where the next value to be removed from the stack should
be taken from. When a value is pushed onto the stack, the 8051 first increments the value of SP
and then stores the value. Similarly when a value is popped off the stack, the 8051 returns the
value from the memory location indicated by SP, and then decrements the value of SP. Since the

Prepared By: CSE Department, KPRIET, Coimbatore. Page 12


U21ECG04 -Internet
of Things and its
Applications [UNIT I – OVERVIEW OF EMBEDDED SYSTEMS]

SP is only 8-bit wide it is incremented or decremented by two. SP is modified directly by the


8051 by six instructions: PUSH, POP, ACALL, LCALL, RET, and RETI. It is also used
intrinsically whenever an interrupt is triggered.

Data Pointer (DPTR): As the name indicates, the Data Pointer register points to the data in the
memory. It is 16-bit register. It can be used as two 8-bit registers DPH and DPL. DPH holds the
high order address and DPL holds the low order address.

Program Status Word (PSW): The 8051 has a 8-bit PSW register which is alsoknown as Flag
register. In the 8-bit register only 6-bits are used by 8051.The two unused bits are user definable
bits. In the 6-bits four of them are conditional flags .

They are Carry –CY, Auxiliary Carry-AC, Parity-P, and Overflow-OV. These flag SET or
RESET after an operation according to data conditions of the result in the register A and other
registers. As shown below figure PSW.3 and PSW.4 are designed as RS0 and RS1 and are used to
select the register banks.

Carry Flag (CY): If an operation results in a carry at D7(MSB) position, then the carry flag is
SET or else it is RESET. It can also be set or reset directly by instruction such as “SETB C” and
“CLR C”, where “SETB C” stands for “Set Bit Carry” and “CLR C” for “Clear Carry”.

Auxiliary Flag (AC): If there is a carry form D3 to D4 during addition operation, this bit is set
other wise it is reset.

Parity Flag (P): The parity flag reflects the number of 1’s in the accumulator. If the register A
contains an odd number of 1’s the parity flag is set. If A has an even number of 1’s, the parity flag
is reset.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 13


U21ECG04 -Internet
of Things and its
Applications [UNIT I – OVERVIEW OF EMBEDDED SYSTEMS]

Overflow Flag (OV): This flag is set whenever the result of a signed number operation is too
large, causing the high order bit to overflow in to the sign bit. The overflow flag is only used to
detect errors in signed aithemetic operations. If OV=1, the result is erraneous, If=0, the result is
valid.

The Register Bank Selection: The following table shows register bank selection.

PIN DIAGRAM-

Pins 1 to 8 − these pins are known as Port 1. This port doesn’t serve any other functions. It is
internally pulled up, bi-directional I/O port.
Pin 9 − It is a RESET pin, which is used to reset the microcontroller to its initial values.
Pins 10 to 17 − these pins are known as Port 3. This port serves some functions like interrupts,
timer input, control signals, serial communication signals RxD and TxD, etc.
Pins 18 & 19 − these pins are used for interfacing an external crystal to get the system clock.
Pin 20 − this pin provides the power supply to the circuit.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 14


U21ECG04 -Internet
of Things and its
Applications [UNIT I – OVERVIEW OF EMBEDDED SYSTEMS]

Pins 21 to 28 − these pins are known as Port 2. It serves as I/O port. Higher order address bus
signals are also multiplexed using this port.
Pin 29 − this is PSEN pin which stands for Program Store Enable. It is used to read a signal from
the external program memory.
Pin 30 − this is EA pin which stands for External Access input. It is used to enable/disable the
external memory interfacing.
Pin 31 − this is ALE pin which stands for Address Latch Enable. It is used to demultiplex the
address-data signal of port.
Pins 32 to 39 − these pins are known as Port 0. It serves as I/O port. Lower order address and data
bus signals are multiplexed using this port.
Pin 40 − this pin is used to provide power supply to the circuit.

FUNCTIONAL BLOCKS OF MOBILE PHONE-

Microphone: Captures voice for conversion from analog to digital mode.


Speaker: Allows monitoring of remote phone.
LCD Display: Shows Call, Phone, Signal & Network Information.
Keypad: Allows access to specific remote locations of the phone.
Battery and Meter: While battery housings on cell phones are standard input designs. Some cell
phones also have some “battery processing” intelligence built in. For example, they will check the
charge level to start or stop the charge when the phone is connected to a desktop, car or quick charger

Prepared By: CSE Department, KPRIET, Coimbatore. Page 15


U21ECG04 -Internet
of Things and its
Applications [UNIT I – OVERVIEW OF EMBEDDED SYSTEMS]

and even automatically discharge the battery for you when necessary. This is usually linked to the
LCD display and to an audible beep to warn you of the battery charge status.
LED Lights: Status information, Usually Green, white & Red.
Digital Signal Processor: The DSP chipset is a critical component which is used to co-ordinates the
voice, SMS and data/fax features of a cell phone. It processes speech, handles voice activity
detection, as well as discontinuous GSM transmission and reception. One section amplifies the input
signal received from the microphone, while another converts this.
CODEC: Microphone voice signal from “analogue” to “digital”. The digital conversion is
necessary because the GSM cellular standard is a completely digital system. This DSP’s voice
processing is done with highly sophisticated compression technique mediated by the “CODEC”
portion of the cell phone.
RF Unit: The CODEC chipset instantly transfers this “compressed” information to the cell phone’s
Radio Frequency (RF) unit. RF Unit is essentially to perform the transmitter and receiver section of
the cell phone. It sends out the voice or data information via the cell phone antenna, over the air and
on to the nearestcellular base station and ultimately to your call destination. The incoming voice also
travels much the same route, although it is first uncompressed from incoming digital from into an
audible analogue form, which is then piped out as sound through the cell phone’s speaker. This
analogue-to-digital and digital-to-analogue voice conversion via the CODEC is done at very high
speeds, so that you never really experience any delay between talking and the other person hearing
you and vice versa.
SIM Card Reader: When you switch on your phone with a “live” SIM card inside, the subscriber
information on the chip inside the SIM card is read by the SIM card reader and then transmitted
digitally to the network via the RF unit. The same route is followed when it hit the call button on the
cell phone. The number you have inputted is instantly and digitally transferred to the network for
processing.
External Connectors: At the bottom of most cell phones there is an external connector system. You
can usually plug in a data/fax adapter or a battery charger, or a personal hands free device, or car-kit
with external antenna connections. You will also find many with separate “speaker” and LED lights
that are activated when the phone rings and/or when the battery is low. Many phones also have tiny
LED lights under the keypad that light up when u presses a key and/or when the phone rings.
On-Board Memory: Many cell phones also have a certain amount of on-board memory chip
capacity available for storing outgoing telephone numbers, your own telephone number, as well as
incoming and outgoing SMS messages. Some allow copying between the (limited) memory on the
SIM card and the phones own internal memory.
Antenna System: Cell phone manufactures are implementing many wonderful permutations of
antenna system designs. While some are stubby, fixed types. The most predominant designs though
are those with thin, pullout steel rods all of whom usually fit snugly into a special antenna shaft.
These antenna designs, be they the stubby or pull-out types, all conform to the same circa 900 MHz
frequency transmit and receive range required by the GSM specification.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 16


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

UNIT II: ARDUINO BOARDS AND PROGRAMMING CONCEPT


Arduino Family-Uno, Nano, Leonardo, Ethernet, Mega2560- IDE-Tool- Variable and Datatypes-
Control structure- I/O functions

ARDUINO FAMILY

Arduino board was designed in the Ivrea Interaction Design Institute intended for students without a
background in electronics and programming concepts. This board started altering to adapt to new
requirements and challenges, separating its presence from simple 8-bit boards to products for IoT
(Internet of Things) applications, 3D printing, wearable, and embedded surroundings. All boards are
entirely open-source, allowing users to build them separately and finally adapt them to their exact
needs. Over the years the different types of Arduino boards have been used to build thousands of
projects, from daily objects to compound scientific instruments. An international community of
designers, artists, students, programmers, hobbyists, and experts has gotten together around this open-
source stage, their donations have added up to an unbelievable amount of available knowledge that
can be of immense help to beginners and specialists alike.

Arduino board is an open-source platform used to make electronics projects. It consists of both a
microcontroller and a part of the software or Integrated Development Environment (IDE) that runs on
your PC, used to write & upload computer code to the physical board. The platform of an Arduino
has become very famous with designers or students just starting out with electronics, and for an
excellent cause.

Features of different types of Arduino boards

The features of different types of Arduino boards are listed in the tabular form.

Arduino Board Processor Memory Digital I/O Analogue I/O

16Mhz 2KB SRAM,


Arduino Uno ATmega328 32KB flash 14 6 input, 0 output

84MHz 96KB SRAM,


Arduino Due AT91SAM3X8E 512KB flash 54 12 input, 2 output

16MHz 8KB SRAM,


Arduino Mega ATmega2560 256KB flash 54 16 input, 0 output

Prepared By: CSE Department, KPRIET, Coimbatore. Page 1


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

16MHz 2.5KB SRAM,


Arduino Leonardo ATmega32u4 32KB flash 20 12 input, 0 output

Arduino Uno (R3)

The Uno is a huge option for your initial Arduino. This Arduino board depends on an ATmega328P
based microcontroller. As compared with other types of arduino boards, it is very simple to use like
the Arduino Mega type board. .It consists of 14-digital I/O pins, where 6-pins can be used as
PWM(pulse width modulation outputs), 6-analog inputs, a reset button, a power jack, a USB
connection, an In-Circuit Serial Programming header (ICSP), etc. It includes everything required to
hold up the microcontroller; simply attach it to a PC with the help of a USB cable and give the supply
to get started with an AC-to-DC adapter or battery.

Arduino Uno R3 Specifications

The Arduino Uno R3 board includes the following specifications.


 It is an ATmega328P based Microcontroller
 The Operating Voltage of the Arduino is 5V
 The recommended input voltage ranges from 7V to 12V

Prepared By: CSE Department, KPRIET, Coimbatore. Page 2


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

 The i/p voltage (limit) is 6V to 20V


 Digital input and output pins-14
 Digital input & output pins (PWM)-6
 Analog i/p pins are 6
 DC Current for each I/O Pin is 20 mA
 DC Current used for 3.3V Pin is 50 mA
 Flash Memory -32 KB, and 0.5 KB memory is used by the boot loader
 SRAM is 2 KB
 EEPROM is 1 KB
 The speed of the CLK is 16 MHz
 In Built LED
 Length and width of the Arduino are 68.6 mm X 53.4 mm
 The weight of the Arduino board is 25 g

Power Supply
The power supply of the Arduino can be done with the help of an exterior power supply otherwise
USB connection. The exterior power supply (6 to 20 volts) mainly includes a battery or an AC to DC
adapter. The connection of an adapter can be done by plugging a center-positive plug (2.1mm) into
the power jack on the board. The battery terminals can be placed in the pins of Vin as well as GND.
The power pins of an Arduino board include the following.
Vin: The input voltage or Vin to the Arduino while it is using an exterior power supply opposite to
volts from the connection of USB or else RPS (regulated power supply). By using this pin, one can
supply the voltage.
5Volts: The RPS can be used to give the power supply to the microcontroller as well as components
which are used on the Arduino board. This can approach from the input voltage through a regulator.
3V3: A 3.3 supply voltage can be generated with the onboard regulator, and the highest draw current
will be 50 mA.
GND: GND (ground) pins
Memory
The memory of an ATmega328 microcontroller includes 32 KB and 0.5 KB memory is utilized for
the Boot loader), and also it includes SRAM-2 KB as well as EEPROM-1KB.
Input and Output
We know that an arguing Uno R3 includes 14-digital pins which can be used as an input otherwise
output by using the functions like pin Mode (), digital Read(), and digital Write(). These pins can
operate with 5V, and every digital pin can give or receive 20mA, & includes a 20k to 50k ohm pull
up resistor. The maximum current on any pin is 40mA which cannot surpass for avoiding the
microcontroller from the damage. Additionally, some of the pins of an Arduino include specific
functions.
Serial Pins
The serial pins of an Arduino board are TX (1) and RX (0) pins and these pins can be used to transfer
the TTL serial data. The connection of these pins can be done with the equivalent pins of the
ATmega8 U2 USB to TTL chip.

External Interrupt Pins

Prepared By: CSE Department, KPRIET, Coimbatore. Page 3


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

The external interrupt pins of the board are 2 & 3, and these pins can be arranged to activate an
interrupt on a rising otherwise falling edge, a low-value otherwise a modify in value
PWM Pins
The PWM pins of an Arduino are 3, 5, 6, 9, 10, & 11, and gives an output of an 8-bit PWM with the
function analogWrite ().
SPI (Serial Peripheral Interface) Pins
The SPI pins are 10, 11, 12, 13 namely SS, MOSI, MISO, SCK, and these will maintain the SPI
communication with the help of the SPI library.
LED Pin
An arguing board is inbuilt with a LED using digital pin-13. Whenever the digital pin is high, the
LED will glow otherwise it will not glow.
TWI (2-Wire Interface) Pins
The TWI pins are SDA or A4, & SCL or A5, which can support the communication of TWI with the
help of Wire library.
AREF (Analog Reference) Pin
An analog reference pin is the reference voltage to the inputs of an analog i/ps using the function like
analogReference().
Reset (RST) Pin
This pin brings a low line for resetting the microcontroller, and it is very useful for using an RST
button toward shields which can block the one over the Arduino R3 board.
Communication
The communication protocols of an Arduino Uno include SPI, I2C, and UART serial
communication.
UART
An Arduino Uno uses the two functions like the transmitter digital pin1 and the receiver digital pin0.
These pins are mainly used in UART TTL serial communication.
I2C
An Arduino UNO board employs SDA pin otherwise A4 pin & A5 pin otherwise SCL pin is used
for I2C communication with wire library. In this, both the SCL and SDA are CLK signal and data
signal.
SPI Pins
The SPI communication includes MOSI, MISO, and SCK.
MOSI (Pin11)
This is the master out slave in the pin, used to transmit the data to the devices
MISO (Pin12)
This pin is a serial CLK, and the CLK pulse will synchronize the transmission of which is produced
by the master.
SCK (Pin13)
The CLK pulse synchronizes data transmission that is generated by the master. Equivalent pins with
the SPI library is employed for the communication of SPI. ICSP (in-circuit serial programming)
headers can be utilized for programming ATmega microcontroller directly with the boot loader.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 4


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

Arduino Nano

This is a small board based on the microcontrollers like ATmega328P otherwise ATmega628 but the
connection of this board is the same as to the Arduino UNO board. This kind of microcontroller
board is very small in size, sustainable, flexible, and reliable.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 5


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

Arduino Nano Specifications

 ATmega328P Microcontroller is from 8-bit AVR family


 Operating voltage is 5V
 Input voltage (Vin) is 7V to 12V
 Input/Output Pins are 22
 Analog i/p pins are 6 from A0 to A5
 Digital pins are 14
 Power consumption is 19 mA
 I/O pins DC Current is 40 mA
 Flash memory is 32 KB

Prepared By: CSE Department, KPRIET, Coimbatore. Page 6


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

 SRAM is 2 KB
 EEPROM is 1 KB
 CLK speed is 16 MHz
 Weight-7g
 Size of the printed circuit board is 18 X 45mm
 Supports three communications like SPI, IIC, & USART

Power Pin (Vin, 3.3V, 5V, GND): These pins are power pins
 Vin is the input voltage of the board, and it is used when an external power source is
used from 7V to 12V.
 5V is the regulated power supply voltage of the nano board and it is used to give the
supply to the board as well as components.
 3.3V is the minimum voltage which is generated from the voltage regulator on the
board.
GND is the ground pin of the board
RST Pin( Reset): This pin is used to reset the microcontroller
Analog Pins (A0-A7): These pins are used to calculate the analog voltage of the board within the
range of 0V to 5V
I/O Pins (Digital Pins from D0 – D13): These pins are used as an i/p otherwise o/p pins. 0V & 5V
Serial Pins (Tx, Rx): These pins are used to transmit & receive TTL serial data.
External Interrupts (2, 3): These pins are used to activate an interrupt.
PWM (3, 5, 6, 9, 11): These pins are used to provide 8-bit of PWM output.
SPI (10, 11, 12, & 13): These pins are used for supporting SPI communication.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 7


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

Inbuilt LED (13): This pin is used to activate the LED.


IIC (A4, A5): These pins are used for supporting TWI communication.
AREF: This pin is used to give reference voltage to the input voltage

Arduino Leonardo Board

The first development board of an Arduino is the Leonardo board. This board uses one
microcontroller along with the USB. That means, it can be very simple and cheap also. Because this
board handles USB directly, program libraries are obtainable which let the Arduino board to follow a
keyboard of the computer, mouse, etc.

Arduino Leonardo specifications

Microcontroller ATmega32u4
Operating Voltage 5V
Input Voltage (Recommended) 7-12V
Input Voltage (limits) 6-20V
Digital I/O Pins 20
PWM Channels 7
Analog Input Channels 12
DC Current per I/O Pin 40 mA
DC Current for 3.3V Pin 50 mA
Flash Memory 32 KB (ATmega32u4) of which 4 KB used by bootloader
SRAM 2.5 KB (ATmega32u4)

Prepared By: CSE Department, KPRIET, Coimbatore. Page 8


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

EEPROM 1 KB (ATmega32u4)
Clock Speed 16 MHz
Lengh 68.6 mm
Width 53.3 mm
Weight 20 g

Arduino Ethernet board

The Arduino Ethernet board depends on the microcontroller like ATmega328. This kind of
microcontroller board includes analog pins-5, digital I/O pins-14, RST button, an RJ45 connection,
crystal oscillator, a power jack, ICSP header, etc. The connection of the Arduino board can be done
through the Ethernet shield to the internet.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 9


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

The Arduino Ethernet Shield 2 allows an Arduino Board to connect to the internet. It is based on the
Wiznet W5500 Ethernet chip .The Wiznet W5500 provides a network (IP) stack capable of both TCP
and UDP. It supports up to eight simultaneous socket connections. Use the Ethernet library to write
sketches that connect to the Internet using the Shield. The Ethernet Shield 2 connects to an Arduino
Board using long wire-wrap headers extending through the Shield. This keeps the pin layout intact
and allows another Shield to be stacked on top of it.

The most recent revision of the board exposes the 1.0 pinout on rev 3 of the Arduino UNO Board.

The Ethernet Shield 2 has a standard RJ-45 connection, with an integrated line transformer and Power
over Ethernet enabled.

There is an onboard micro-SD card slot, which can be used to store files for serving over the network.
It is compatible with the Arduino Uno and Mega (using the Ethernet library). The onboard micro-SD
card reader is accessible through the SD Library. When working with this library, SS is on Pin 4. The
original revision of the Shield contained a full-size SD card slot; this is not supported.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 10


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

The Shield also includes a reset controller, to ensure that the W5500 Ethernet module is properly
reset on power-up. Previous revisions of the Shield were not compatible with the Mega and needed to
be manually reset after power-up. The current Shield supports a Power over Ethernet (PoE) module
designed to extract power from a conventional twisted pair Category 5 Ethernet cable.
PoE module features as follows:

 IEEE802.3af compliant
 Input voltage range 36V to 57V
 Overload and short-circuit protection
 12V Output
 High efficiency DC/DC converter: typ 85% @ 80% load
 1500V isolation (input to output)

The Shield does not come with a built in PoE module, it is a separate component that must be added
on. Arduino communicates with both the W5500 and SD card using the SPI bus (through the ICSP
header). This is on digital pins 10, 11, 12, and 13 on the Uno and pins 50, 51, and 52 on the Mega. On
both boards, pin 10 is used to select the W5500 and pin 4 for the SD card. These pins cannot be used
for general I/O. On the Mega, the hardware SS pin, 53, is not used to select either the W5500 or the
SD card, but it must be kept as an output or the SPI interface won't work.

Note that because the W5500 and SD card share the SPI bus, only one at a time can be active. If you
are using both peripherals in your program, this should be taken care of by the corresponding
libraries. If you're not using one of the peripherals in your program, however, you'll need to explicitly
deselect it. To do this with the SD card, set pin 4 as an output and write a high to it. For the W5500,
set digital pin 10 as a high output.

 The Shield provides a standard RJ45 Ethernet jack.


 The reset button on the Shield resets both the W5500 and the Arduino Board.
 The Shield contains a number of information LEDs:
 ON: indicates that the Board and Shield are powered
 13 is the Arduino standard built in LED
 ACT: flashes when RX or TX activity is present
 LINK: indicates the presence of a network link and flashes when the Shield transmits or
receives data

Arduino Mega2560

The Arduino Mega is similar to the UNO’s big brother. It includes lots of digital I/O pins
(from that, 14-pins can be used as PWM o/ps), 6-analog inputs, a reset button, a power jack, a
USB connection, and a reset button. It includes everything required to hold up the
microcontroller; simply attach it to a PC with the help of a USB cable and give the supply to
get started with an AC-to-DC adapter or battery. The huge number of pins make this Arduino

Prepared By: CSE Department, KPRIET, Coimbatore. Page 11


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

board very helpful for designing projects that need a bunch of digital i/ps or o/ps like lots of
buttons.

The microcontroller board like “Arduino Mega” depends on the ATmega2560


microcontroller. It includes digital input/output pins-54, where 16 pins are analog inputs, 14
are used like PWM outputs hardware serial ports (UARTs) – 4, a crystal oscillator-16 MHz,
an ICSP header, a power jack, a USB connection, as well as an RST button. This board
mainly includes everything which is essential for supporting the microcontroller. So, the
power supply of this board can be done by connecting it to a PC using a USB cable, or battery
or an AC-DC adapter. This board can be protected from the unexpected electrical discharge
by placing a base plate.

Arduino Mega 2560 Specifications

The specifications of Arduino Mega include the following.

 The ATmega2560 is a Microcontroller


 The operating voltage of this microcontroller is 5volts
 The recommended Input Voltage will range from 7volts to 12volts
 The input voltage will range from 6volts to 20volts
 The digital input/output pins are 54 where 15 of these pins will supply PWM o/p.
 Analog Input Pins are 16
 DC Current for each input/output pin is 40 mA
 DC Current used for 3.3V Pin is 50 mA
 Flash Memory like 256 KB where 8 KB of flash memory is used with the help of bootloader
 The static random access memory (SRAM) is 8 KB

Prepared By: CSE Department, KPRIET, Coimbatore. Page 12


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

 The electrically erasable programmable read-only memory (EEPROM) is 4 KB


 The clock (CLK) speed is 16 MHz
 The USB host chip used in this is MAX3421E
 The length of this board is 101.52 mm
 The width of this board is 53.3 mm
 The weight of this board is 36 g

Pin 3.3V & 5V


These pins are used for providing o/p regulated voltage approximately 5V. This RPS (regulated
power supply) provides the power to the microcontroller as well as other components which are used
over the Arduino mega board. It can be attained from Vin-pin of the board or one more regulated
voltage supply-5V otherwise USB cable, whereas another voltage regulation can be offered by
3.3V0-pin. The max power can be drawn by this is 50mA.
GND Pin

Prepared By: CSE Department, KPRIET, Coimbatore. Page 13


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

The Arduino mega board includes 5-GND pins where one of these pins can be used whenever the
project requires.

Reset (RST) Pin


The RST pin of this board can be used for rearranging the board. The board can be rearranged by
setting this pin to low.
Vin Pin
The range of supplied input voltage to the board ranges from 7volts to 20volts. The voltage provided
by the power jack can be accessed through this pin. However, the output voltage through this pin to
the board will be automatically set up to 5V.
Serial Communication
The serial pins of this board like TXD and RXD are used to transmit & receive the serial data. Tx
indicates the transmission of information whereas the RX indicates receive data. The serial pins of
this board have four combinations. For serial 0, it includes Tx (1) and Rx (0), for serial 1, it includes
Tx(18) & Rx(19), for serial 2 it includes Tx(16) & Rx(17), and finally for serial 3, it includes Tx(14)
& Rx(15).
External Interrupts
The external interrupts can be formed by using 6-pins like interrupt 0(0), interrupt 1(3), interrupt
2(21), interrupt 3(20), interrupt 4(19), interrupt 5(18). These pins produce interrupts by a number of
ways i.e. Providing LOW value, rising or falling edge or changing the value to the interrupt pins.
LED
This Arduino board includes a LED and that is allied to pin-13 which is named as digital pin 13. This
LED can be operated based on the high and low values of the pin. This will give you to modify the
programming skills in real time.
AREF
The term AREF stands for Analog Reference Voltage which is a reference voltage for analog inputs
Analog Pins
There are 16-analog pins included on the board which is marked as A0-A15. It is very important to
know that all the analog pins on this board can be utilized like digital I/O pins. Every analog pin is
accessible with the 10-bit resolution which can gauge from GND to 5 volts. But, the higher value can
be altered using AREF pin as well as the function of analog Reference ().
I2C
The I2C communication can be supported by two pins namely 20 & 21 where 20-pin signifies Serial
Data Line (SDA) which is used for holding the data & 21-pin signifies Serial Clock Line (SCL )
mostly utilized for offering data synchronization among the devices
SPI Communication
The term SPI is a serial peripheral interface which is used to transmit the data among the controller &
other components. Four pins like MISO (50), MOSI (51), SCK (52), and SS (53) are utilized for the
communication of SPI.
Dimensions
The dimension of Arduino Mega 2560 board mainly includes the length as well as widths like
101.6mm or 4 inch X 53.34 mm or 2.1 inches. It is comparatively superior to other types of boards
which are accessible in the marketplace. But, the power jack and USB port are somewhat expanded
from the specified measurements.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 14


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

Shield Compatibility
Arduino Mega is well-suited for most of the guards used in other Arduino boards. Before you propose
to utilize a guard, confirm the operating voltage of the guard is well-suited with the voltage of the
board. The operating voltage of most of the guards will be 3.3V otherwise 5V. But, guards with high
operating voltage can injure the board.
In addition, the distribution header of the shield should vibrate with the distribution pin of the
Arduino board. For that, one can connect the shield simply with the Arduino board & make it within
a running state.
Programming
The programming of an Arduino Mega 2560 can be done with the help of an IDE (Arduino
Software), and it supports C-programming language. Here the sketch is the code in the software
which is burned within the software and then moved to the Arduino board using a USB cable.
An Arduino mega board includes a boot loader which eliminates an external burner utilization to burn
the program code into the Arduino board. Here, the communication of the boot loader can be done
using an STK500 protocol.
When we compile as well as burn the Arduino program, then we can detach the USB cable to remove
the power supply from the Arduino board. Whenever you propose to use the Arduino board for your
project, the power supply can be provided by a power jack otherwise Vin pin of the board.
Another feature of this is multitasking wherever Arduino mega board comes handy. But, Arduino
IDE Software doesn’t support multi-tasking however one can utilize additional operating systems
namely RTX & Free RTOS to write C-program for this reason. This is flexible to use in your personal
custom build program with the help of an ISP connector.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 15


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

Data types in Arduino Programming.

Below is a list of the data types commonly seen in Arduino, with the memory size of each in
parentheses after the type name. Note: signed variables allow both positive and negative numbers,
while unsigned variables allow only positive values.
 boolean (8 bit) - simple logical true/false

boolean val = false ; // declaration of variable with type boolean and initialize it with false
boolean state = true ; // declaration of variable with type boolean and initialize it with true

Prepared By: CSE Department, KPRIET, Coimbatore. Page 16


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

 byte (8 bit) - unsigned number from 0-255.


byte m = 25 ;//declaration of variable with type byte and initialize it with 25

 char (8 bit) - signed number from -128 to 127. The compiler will attempt to interpret this data
type as a character in some circumstances, which may yield unexpected results.
Char chr_a = ‘a’ ;//declaration of variable with type char and initialize it with character a
Char chr_c = 97 ;//declaration of variable with type char and initialize it with character 97

 unsigned char (8 bit) - same as 'byte'; if this is what you're after, you should use 'byte'
instead, for reasons of clarity
Unsigned Char chr_y = 121 ; // declaration of variable with type Unsigned char and initialize it with
character y

 word (16 bit) - unsigned number from 0-65535


word w = 1000 ;//declaration of variable with type word and initialize it with 1000

 unsigned int (16 bit)- the same as 'word'. Use 'word' instead for clarity and brevity.
Unsigned int counter = 60 ; // declaration of variable with type unsigned int and initialize it with 60

 int (16 bit) - signed number from -32768 to 32767. This is most commonly what you see used
for general purpose variables in Arduino example code provided with the IDE.
int counter = 32 ;// declaration of variable with type int and initialize it with 32

 unsigned long (32 bit) - unsigned number from 0-4,294,967,295. The most common usage of
this is to store the result of the millis() function, which returns the number of milliseconds the
current code has been running.

Unsigned Long velocity = 101006 ;// declaration of variable with type Unsigned Long and initialize it with
101006

 long (32 bit) - signed number from -2,147,483,648 to 2,147,483,647


Long velocity = 102346 ;//declaration of variable with type Long and initialize it with 102346

 float (32 bit) - signed number from -3.4028235E38 to 3.4028235E38. Floating point on the
Arduino is not native; the compiler has to jump through hoops to make it work.

float num = 1.352;//declaration of variable with type float and initialize it with 1.352

Prepared By: CSE Department, KPRIET, Coimbatore. Page 17


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

 short- A short is a 16-bit data-type. On all Arduinos (ATMega and ARM based), a short
stores a 16-bit (2-byte) value.

short val = 13 ;//declaration of variable with type short and initialize it with 13
 double- On the Uno and other ATMEGA based boards, Double precision floating-point number occupies
four bytes.
double num = 45.352 ;// declaration of variable with type double and initialize it with 45.352

Datatypes in Arduino Programming- Arduino Arrays

void setup()
{
char my_str[6]; // an array big enough for a 5 character string
Serial.begin(9600);
my_str[0] = 'H'; // the string consists of 5 characters
my_str[1] = 'e';
my_str[2] = 'l';
my_str[3] = 'l';
my_str[4] = 'o';
my_str[5] = 0; // 6th array element is a null terminator
Serial.println(my_str);
}
void loop()
{}
OR
void setup()
{
char my_str[] = "Hello";
Serial.begin(9600);
Serial.println(my_str);
}
void loop()
{}

Example output?????

void setup()
{
char like[] = "I like coffee and cake"; // create a string

Prepared By: CSE Department, KPRIET, Coimbatore. Page 18


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

Serial.begin(9600);
// (1) print the string
Serial.println(like);
// (2) delete part of the string
like[13] = 0;
Serial.println(like);
// (3) substitute a word into the string
like[13] = ' '; // replace the null terminator with a space
like[18] = 't'; // insert the new word
like[19] = 'e';
like[20] = 'a';
like[21] = 0; // terminate the string
Serial.println(like);
}
void loop()
{
}

Variable Scope

Local Variables

Variables that are declared inside a function or block are local variables. They can be used only by
the statements that are inside that function or block of code. Local variables are not known to
function outside their own. Following is the example using local variables –

Void setup () {
}

Void loop () {
int x , y ;
int z ; Local variable declaration
x = 0;
y = 0; actual initialization
z = 10;
}

Prepared By: CSE Department, KPRIET, Coimbatore. Page 19


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

Global Variables

Global variables are defined outside of all the functions, usually at the top of the program. The global
variables will hold their value throughout the life-time of your program.

A global variable can be accessed by any function. That is, a global variable is available for use
throughout your entire program after its declaration.

The following example uses global and local variables –

int T , S ;
float c = 0 ; Global variable declaration

Void setup () {

Void loop () {
int x , y ;
int z ; Local variable declaration
x = 0;
y = 0; actual initialization
z = 10;
}

Control Statements in Arduino Programmming-

S.NO. Control Statement & Description

If statement
1 It takes an expression in parenthesis and a statement or block of statements. If
the expression is true then the statement or block of statements gets executed
otherwise these statements are skipped.

If …else statement
2 An if statement can be followed by an optional else statement, which executes
when the expression is false.

If…else if …else statement


3
The if statement can be followed by an optional else if...else statement, which is
very useful to test various conditions using single if...else if statement.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 20


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

switch case statement


4 Similar to the if statements, switch...case controls the flow of programs by
allowing the programmers to specify different codes that should be executed in
various conditions.

5 Conditional Operator ? :
The conditional operator ? : is the only ternary operator .

Example 1:

int a=4;
void setup(){
Serial.begin(9600);
if (a==4){
Serial.println(“Welcome to KPRIET”);}
}
void loop(){
}

Example 2:

int a=3;
void setup(){
Serial.begin(9600);
if (a==4)
Serial.println("The if statement executed");
else
Serial.println("The else statement executed");
}
void loop(){
}

Example 3:

int a=1;
void setup(){
Serial.begin(9600);
switch (a) {
case 1:
Serial.println("Case 1 executed");
break;
case 2:
Serial.println("Case 2 executed");

Prepared By: CSE Department, KPRIET, Coimbatore. Page 21


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

break;
default:

Serial.println("Default is executed");
}}
void loop(){
}

Example 4:

void setup(){
Serial.begin(9600);
int a=100, b=60, max;
max=(a>b)? a : b;
Serial.print(“The maximum number is: ”);
Serial.print(result);
}
void loop(){
}

Example Output????
1. void setup() {
2. Serial.begin(9600);
3. }
4. void loop() {
5. int a=10;
6. int b=12;
7. int c=13;
8. if(a>b && a>c) {
9. Serial.println(a);
10. }
11. else if(b>a && b>c) {
12. Serial.println(b);
13. }
14. else if(c>a && c>b) {
15. Serial.println(c);
16. }
17. }

Prepared By: CSE Department, KPRIET, Coimbatore. Page 22


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

Digital I/O

Digital I/O is defined as using a digital signal to communicate; a logical 1 or logical 0. In Arduino, 1
is defined as having a “high” voltage; normally at or close to the system voltage. 0 is defi ned as
having a “low” voltage, typically 0. A system powered by 5 volts will usually have 5 volts for a
logical 1 and 0 volt for a logical 0. A system powered by 3.3 V will usually have 3.3 V and 0.

pinMode()
Before using a pin as a digital input or output, you must fi rst confi gure the pin, which is done with
pinMode(). pinMode() uses two parameters: pin and mode.

pinMode(pin, mode)
The pin parameter is simply the digital pin number you want to set. The mode parameter is one of
three constants: INPUT, OUTPUT, or INPUT_PULLUP. The INPUT and OUTPUT constants set the
pin to be a digital input or output, respectively. The INPUT_PULLUP constant sets the selected pin
to become a digital input but also connects an internal resistor to keep the input level at a logical one
if there is no input value.

INPUT
Pins configured as INPUT can read voltage applied to them. It takes only a small amount of current to
change an INPUT pin’s state. INPUT pins are good at reading logical inputs but cannot be used to
input, or sink, any current. For example, you cannot use an INPUT pin to sink current from an LED.

OUPUT
Pins configured as OUTPUT are capable of delivering power to circuits, up to 40 mA. This is more
than enough to power an LED but is not enough to power motors. Output pins cannot read sensors.
Connecting output pins directly to 5 volts or 0 volts can damage the pin.

INPUT_PULLUP
Pins configured as INPUT_PULLUP are configured as output, but with an internal pull-up resistor
connected. On most Arduino boards this internal resistor is at least 20 kilohms. This has the effect of
setting the input value to HIGH if it is pulled to ground, and LOW if voltage is applied.

digitalRead()
In order to read the state of a digital pin, you must use digitalRead():
result = digitalRead(pin);
The pin parameter is the pin number you want to read from. This function returns either HIGH or
LOW, depending on the input.

digitalWrite()

To write the state of a pin that was declared as an OUTPUT, use the digitalWrite()
function:

Prepared By: CSE Department, KPRIET, Coimbatore. Page 23


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

digitalWrite(pin, value);

The pin parameter is the pin number you want to write to, and the value is the logical level you want
to write; HIGH or LOW.

Analog I/O

Analog is different than digital. Digital signals are one of two states; either true (a logical one), or
false (a logical zero). Digital states are not designed to have any other value. Analog is different in
that it has a potentially infinite amount of values between two points. Analog is all around us. A light
bulb is normally either on or off, but consider the sun. At nighttime, there is no light, and in daytime,
midday, on a sunny day with no clouds, you would think that you have the maximum
amount of sunlight.

analogRead()

To read a value from an analog pin, you call analogRead().

int analogRead(pin)

analogRead() reads the voltage value on a pin and returns the value as an int. The pin argument
denotes the analog pin you want to read from. When referring to an analog pin, call them as A0, A1,
A2,…A6. This function takes approximately 100 microseconds to perform. In theory, you could
sample a pin up to 10,000 times a second.

analogWrite()

analogWrite() is used to write an analog output on a digital pin. Wait, analog? On a digital pin? Well,
yes, sort of. It’s not a true analog value that’s being written. Arduinos use something called Pulse-
width modulation, PWM for short. PWM is digital but can be used for some analog devices. It uses a
simple technique to “emulate” an analog output. It relies on two things: a pulse width and a duty
cycle. It is a way of simulating any value within a range by rapidly switching between 0 volts and 5
volts. The pulse width (also called a period) is a short duration of time in which the duty cycle will
operate. The duty cycle describes the amount of time that the output will be at a logical one in the
given period. Depending on the Arduino you’re using, the period can range from 490 Hz to 980 Hz.
A duty cycle of 50 percent means that during 50 percent of the pulse width, the output will be at a
logical one, and the remaining 50 percent of the pulse width, the duty cycle will be at a logical 0. A
duty cycle of 0 percent means that the output will always be p, and a duty cycle of 100 percent means
that the output will always be 1. PWM is an excellent method for controlling motors and dimming
LEDs; it worked well in the previous chapter. However, some components do not like receiving
pulses and want a stable output. For example, another Arduino reading an analog input would read in
alternating values of 5 V and 0 V instead of a true analog signal. In this case, adding a capacitor to the
circuit will “fi lter” the output.

tone()

Prepared By: CSE Department, KPRIET, Coimbatore. Page 24


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

tone() is used mainly to generate audio tones on devices like buzzers. Although designed to generate
audible tones, it is not limited to audio. This function generates a square wave, a signal that alternates
instantly between two values, typically the maximum voltage and zero. It generates signals with a fi
xed 50 percent duty cycle, from frequencies as low as 31 Hz to 80 kHz (humans can typically hear up
to 20 kHz). tone() accepts unsigned integers as a parameter. This function requires either two or three
parameters, depending on your use. tone(pin, frequency) tone(pin, frequency, duration) The pin
arameter is the pin number on which to produce a tone. The frequency parameter is the frequency to
generate in hertz, passed as an unsigned int.
noTone()
noTone() stops the square wave generation of tone() on the specifi ed pin. If no tone is generated,
this function has no effect. This function must be called before generating another tone on the same
pin.

Reading Pulses
Arduinos can be told to react to pulses received on digital pins, reading serial data when data
becomes available, or to call specifi c functions when a signal is received.

pulseIn()
pulseIn() will tell you the length of a pulse. It requires a pin as a parameter and the type of pulse to
read. When programmed, the Arduino waits for a signal on the selected pin. For example, you can tell
the Arduino to wait for a pin to go HIGH. When it does, it starts a counter. When the signal returns to
LOW, it stops the counter, and returns the number of microseconds.

unsigned long length pulseIn(pin, value)


unsigned long length pulseIn(pin, value, time-out)

The pin parameter is the pin number to listen on, as an int value. The value parameter is the type of
signal to wait for: either HIGH or LOW.

Timing Function

Timing is important in electronics projects. Electronics are not instantaneous, and most sensor
components require some time before they can be accessed. A typical one-wire humidity sensor
requires 100 ms of time between the command to acquire a reading and returning the result.

delay()

delay() tells the microcontroller to wait for a specified number of milliseconds before resuming the
sketch. This can be used to tell the microcontroller to wait for a specified period of time before
reading a sensor, or slowing down a loop that is running too fast.

delayMicroseconds()
delayMicrosecond() is similar to delay(), but instead of waiting for a specified number of
milliseconds, it waits for a specifi c number of microseconds. This function is accurate to a certain
point; values above 16,383 produce inaccurate results. If you need an accurate delay above 16,000

Prepared By: CSE Department, KPRIET, Coimbatore. Page 25


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

microseconds (or 16 milliseconds), use a mix of delay() and delayMicroseconds(), like in the
following snippet of code, where the Arduino is asked to wait for 22.5 milliseconds, or a total of
25,500 microseconds.

delay(25); // waits for 25 milliseconds


delayMicroseconds(500) waits for 500 microseconds

millis()
millis() returns the number of milliseconds that the sketch has been running, returning the number as
an unsigned long. This can be used to check how long the current sketch has been running, but it can
also be used to calculate how long a function takes to run, by comparing the number of milliseconds
before and afterward.
unsigned long timeBefore;
unsigned long timeAfter;
timeBefore = millis(); //Get the time before running a function
aLongFunction(); //Run a function that could take some time
timeAfter = millis(); //And now get the time after running the function

micros()
micros() is almost identical to the millis() function, except it returns the number of microseconds in
an unsigned long. The counter overflows far more quickly than millis(); roughly every 70 minutes.

Mathematical Functions

min()

min() returns the smaller of two numbers.

result = min(x, y)

The two values can be of any numerical data type, returning the same data type as the parameter.

int sensorData = 100;


min(sensorData, 255); // Returns 100 (sensorData is smaller)
min(sensorData, 100); // Returns 100
min(sensorData, 64); //Returns 64

max()

max() is similar to min(), except it returns the higher of two values.

result = max(x, y)

max() can take any numerical data type and can be used to obtain a minimum value for sensor data.

Prepared By: CSE Department, KPRIET, Coimbatore. Page 26


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

int sensorData = 100;


max(sensorData, 255); // Returns 255
max(sensorData, 100); // Returns 100 (both values are the same)
max(sensorData, 64); //Returns 100 (sensorData is larger)

constrain ()
constrain() is like combining parts of max() and min() at the same time; it constrains data values to a
set range.

value = constrain(data, min, max)

Imagine a light sensor, reading the ambient light inside your living room, letting you turn the lights
on or off. Values may vary between dark (you can still vaguely see your way around), and bright
(comfortable to see, but not blinding). For a light sensor that gives values between 0 and 1,023, you
could set the constrain levels to values between 40 and 127.

abs()
abs() returns the absolute value of a number, for example, the non-negative value the number, without
regard to its sign. The absolute value of 2 and –2 is 2.

value = abs(x);

This function is implemented in such a way that only values should be calculated, not the results from
mathematical operations or functions.

map()
map() remaps a number in one range set to another. It takes a number, a theoretical boundary, and
remaps that number as if it were in another boundary.

map(value, fromLow, fromHigh, toLow, toHigh);

pow()
pow() raises a number to the power of x.

double result = pow(float base, float exponent);

The base number and exponent are calculated as float, allowing for fractional exponents. The result of
this calculation is returned as a double.

random()
Arduinos are capable of generating pseudo-random numbers using the random() function:
result = random(max);
result = random(min, max);

Prepared By: CSE Department, KPRIET, Coimbatore. Page 27


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

This function takes one or two parameters specifying the range for the random number to be chosen.
If the min parameter is omitted, the result will be a number between zero and max, otherwise the
number will be between min and max.

Example 1:

/*
The circuit:
 photoresistor from analog in 0 to +5V
 10K resistor from analog in 0 to ground
*/
// these constants won't change. They are the lowest and highest readings you
// get from your sensor:

const int sensorMin = 0; // sensor minimum, discovered through experiment


const int sensorMax = 600; // sensor maximum, discovered through experiment

void setup() {
// initialize serial communication:
Serial.begin(9600);
}
void loop() {
// read the sensor:
int sensorReading = analogRead(A0);
// map the sensor range to a range of four options:
int range = map(sensorReading, sensorMin, sensorMax, 0, 3);

// do something different depending on the range value:


switch (range) {
case 0: // your hand is on the sensor

Prepared By: CSE Department, KPRIET, Coimbatore. Page 28


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

Serial.println("dark");
break;
case 1: // your hand is close to the sensor
Serial.println("dim");
break;
case 2: // your hand is a few inches from the sensor
Serial.println("medium");
break;
case 3: // your hand is nowhere near the sensor
Serial.println("bright");
break;
}
delay(1); // delay in between reads for stability
}

Example 2:

int led = 13; // connect LED to pin 13


int pin = 7; // connect pushbutton to pin 7
int value = 0; // variable to store the read value
void setup()
{
pinMode(led, OUTPUT); // sets pin 13 as output
pinMode(pin, INPUT); // sets pin 7 as input
}
void loop()
{
value = digitalRead(pin); // sets 'value' equal to the input pin
digitalWrite(led, value); // sets 'led' to the button's value
}

Example 3:

int ledPin = 9; // PWM pin for the LED


void setup(){} // no setup needed
void loop()
{
for (int i=0; i<=255; i++) // ascending value for i
{
analogWrite(ledPin, i); // sets brightess level to i
delay(100); // pauses for 100ms
}
for (int i=255; i>=0; i--) // descending value for i
{
analogWrite(ledPin, i); // sets brightess level to i

Prepared By: CSE Department, KPRIET, Coimbatore. Page 29


U21ECG04 -Internet [UNIT II – ARDUINO BOARDS AND PROGRAMMING
of Things and its
Applications CONCEPT]

delay(100); // pauses for 100ms


}
}

Prepared By: CSE Department, KPRIET, Coimbatore. Page 30

You might also like