Unit 1 2
Unit 1 2
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.
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.
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.
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.
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.
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.
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.
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.
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.
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
Memory and I/O The memory and I/O components The memory and I/O components are
components are to be connected externally. available.
A MICROCONTROLLER UNIT
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
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.
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.
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 :
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
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.
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.
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.
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.
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.
The features of different types of Arduino boards are listed in the tabular form.
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.
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.
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.
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.
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.
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.
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)
EEPROM 1 KB (ATmega32u4)
Clock Speed 16 MHz
Lengh 68.6 mm
Width 53.3 mm
Weight 20 g
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.
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.
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.
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
board very helpful for designing projects that need a bunch of digital i/ps or o/ps like lots of
buttons.
The Arduino mega board includes 5-GND pins where one of these pins can be used whenever the
project requires.
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.
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
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
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
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
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
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
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;
}
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.
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;
}
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.
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");
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. }
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:
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()
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()
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.
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
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.
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()
result = min(x, y)
The two values can be of any numerical data type, returning the same data type as the parameter.
max()
result = max(x, y)
max() can take any numerical data type and can be used to obtain a minimum value for sensor data.
constrain ()
constrain() is like combining parts of max() and min() at the same time; it constrains data values to a
set range.
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.
pow()
pow() raises a number to the power of x.
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);
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:
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);
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:
Example 3: