0% found this document useful (0 votes)
4 views94 pages

AMC Notes

detailed notes of advanced microcontrollers and applications

Uploaded by

yashiiivashisht
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)
4 views94 pages

AMC Notes

detailed notes of advanced microcontrollers and applications

Uploaded by

yashiiivashisht
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/ 94

UNIT 1: Introduction to Embedded System:

Part1: Basic concept of embedded system


An embedded system is a microprocessor-based computer hardware system with software that is
designed to perform a dedicated function, either as an independent system or as a part of a
large system. At the core is an integrated circuit designed to carry out computation for real-time
operations.

A system is a way of working, organizing or doing one or many tasks according to a fixed plan,
program or set of rules.

A system is also an arrangement in which all its units assemble and work together according to the
plan or program.

• Embedded means something that is attached to another thing. An embedded system can be
thought of as a computer hardware system having software embedded in it.

• It may or not be programmable, depending on application. Examples of embedded systems


include washing machines, printers, automobiles, cameras, industrial machines.

An Embedded System is one that has computer hardware with software embedded in it as one of its
important components.

Its software embeds in ROM (Read Only Memory). It does not need secondary memories as in a
computer.

COMPUTER HARDWARE

• Microprocessor (RAM, ROM and caches)

• A Large Memory (RAM, ROM and caches)

• Input Units (Keyboard, Mouse, Scanner, etc.)

• Output Units (Monitor, printer, etc.)

• Networking Units (Ethernet Card, Drivers, etc.)

• I/O Units (Modem, Fax cum Modem, etc.)

COMPONENTS OF EMBEDDED SYSTEM

It has Hardware

Processor, Timers, Interrupt controller, I/O Devices, Memories, Ports, etc.

• It has main Application Software

Which may perform concurrently the series of tasks or multiple tasks.

• It has Real Time Operating System (RTOS)


RTOS defines the way the system work. Which supervise the application software. It sets the rules
during the execution of the application program. A small scale embedded system may not need an
RTOS.

Typical Embedded System Hardware


EMBEDDED SYSTEM CONSTRAINTS

An embedded system's software designed to keep

in view three constraints:

• Available system memory

• Available processor speed

• The need to limit the power dissipation

• Production cost per unit

General Purpose Systems vs. Embedded Systems


In order to better realize the characteristics of an embedded system, let’s compare it with a general
computing system.

General Purpose Computer Embedded System

Purpose Multipurpose Single function

Low or no resource
Constraint constraint Size, power, cost, memory, real time

Performance Faster and better Fixed runtime requirement

Integrated into the real world with


User Can have keyboard, display, buttons, sensors, Leads, LCDs, Bluetooth
Interface mouse, touch screen system

Part 2: Characteristics of Embedded system


ES posses certain specific characteristics and are unique to each embedded systems

Important characteristics are

1.Application and domain specific

2.Reactive and real time

3.Operates in harsh environments

4.Distributed

5.Small size and weight

6.Power concerns
1. Application and domain specific

• Each ES having certain functions to perform.

• Developed to do intended functions only.

• Can not be used for any other purpose

• Ex: You can’t replace embedded control unit of microwave oven with airconditioner embedded
control unit.

• Ex: you can’t replace telecom Embedded with any other consumer electronics domain.

2. Reactive and real time

• ES are constant interaction with the real world through sensors and user defined I/P devices.

• Any changes in real world captured by the sensors in real time and control algorithm reacts in
designed manner to bring o/p variables in desired level

• The event may be periodic or unpredicted one.

• If unpredicted the device must capture events without missing them.

• ES produces changes in O/P in response to the changes in i/p referred as reactive system.

• Real time system means timing behaviour system should be deterministic: ES should response in
known amount of time.

• RTS should not miss any deadlines for tasks or operations.

• Ex: flight control system, antilock brake system (ABS).

3. Operates in harsh environments

• Not necessary all ES should be deployed (moved or kept) in controlled environments.

• Environment may be dusty, high temp. or subject to vibrations and shock.

• Systems placed in such areas should be capable to withstand all these adverse operating system

• The design should take care of the operating conditions where the system going to implement

• Ex: if system is installed in high temp zone then all components used in system should be high
temp. grade

• Proper shock absorption techniques should be provided to systems

• Power supply fluctuations, corrosion and component aging, etc factors that need to be taken into
consideration for ES to work in harsh environment.
4. Distributed

• Distributed means that ES may be part of larger systems.

• Many numbers of such distributed ES from a single large embedded control unit.

• Ex: vending machine contains a card reader vending unit (for pre-paid vending systems).

• Each of them are independent embedded units but they work together to perform overall vending
function.

• Ex: ATM contains card reader embedded unit, transaction unit, currency counter, printer unit. We
can visualize independent Embedded unit but they work together to achieve a common goal.

• Supervisory control and data acquisition SCADA is a system of software and hardware elements
that allows industrial organizations to: Control industrial processes locally or at remote locations.
Monitor, gather, and process real-time data.

5. Small size and weight

• Product aesthetics (a set of principles underlying the work of a particular artist or artistic
movement) is an important factor in choosing a product.

• For ex: when you plan to buy a new mobile phone, may make a comparative study on the pros and
cons of the products available in market.

• The product aesthetics (beauty) will be one of the deciding factors to choose a product (size,
weight, shape, style, etc)

• Most of the application demands small sized and low weight products.

6. Power concerns

• Power management important factor to be considered in designing ES.

• Designed in such a way to minimize the heat dissipation by the system

• The production of high amount of heat demands cooling requirements like cooling fans which in
turn occupies additional space and make the system bulky.

• Low power components are available.

• Power management is critical constraint in battery operated application.

• The more the power consumption the less is the battery life.
Quality attributes of ES

• Operational quality attributes are:

1. Response
• Measure of quickness of the system
• How fast system is tracking changes in i/p variables
• Most of ES demands fast response which should be almost real time
• Ex: comparing response flight control application with electronic toy

2. Throughput
• Deals with efficiency of system
• Rate of production or operation of a defined process over a stated period of time.
• Ex: in terms of card reader, throughput means how many transactions the reader can perform in a
minute or hour or in a day.
• Benchmark can be a set of performance criteria that product is expected to meet standard product
that can be used for comparing other products of the same product line.

3. Reliability
• Reliability is a measure of how much percentage you rely upon the proper functioning of the
system • Mean Time between failures and Mean Timet To Repair are terms used in defining system
reliability.
• Mean Time between failures can be defined as the average time the system is functioning before a
failure occurs.
• Mean time to repair can be defined as the average time the system has spent in repairs.

4. Maintainability
• Maintainability deals with support and maintenance to the end user or a client in case of technical
issues and product failures or on the basis of a routine system checkup
• It can be classified into two types:-
1. Scheduled or Periodic Maintenance
• This is the maintenance that is required regularly after aperiodic time interval.
Examples: 1. Periodic Cleaning of Air Conditioners
2. Refilling of printer cartridges.
2. Maintenance to unexpected failure
• This involves the maintenance due to a sudden breakdown in the functioning of the system.
• Example:1. Air conditioner not powering on
2. Printer not taking paper in spite of a full paper stack

5. Security
• Confidentiality, Integrity and Availability are three corner stones of information security.
• Confidentiality deals with protection data from unauthorized disclosure.
• Integrity gives protection from unauthorized modification.
• Availability gives protection from unauthorized user
• Certain Embedded systems have to make sure they conform to the security measures.
• Ex. An Electronic Safety Deposit Locker can be used only with a pin number like a password.
Classification of Embedded Systems

All types of embedded systems can be classified into two basic categories and their following
subcategories as follows.

Based on Performance and Functional Requirements

Real-Time Systems

▪ Perform a task in real-time

▪ Offer quick responses under critical situations.

▪ Further divided into two types of embedded systems:

1. Soft real-time embedded system: no time-bound operation is required. For instance, in a


microwave oven, there is no strict cooking time instruction. You can customize time delays as
per your requirement.

2. Hard real-time embedded system: strictly time-bound operation is necessary for a successful
output, ex: traffic light control.

Stand-Alone Systems

▪ Process digital/analog input signals into digital output

▪ Less complex

▪ Independent of any system

▪ Ex: doorbell, calculator, MP3 player

Network Systems

▪ Operate through a network interface

▪ Communication to network happens through LAN, WAN, or other protocols

▪ May be wired or wireless

▪ Ex: ATM machines, weather monitoring systems

Mobile Systems

▪ Small, portable and easy-to-carry

▪ Work on restricted memory space

▪ Constantly evolving to get into a miniature model

▪ Ex: mobile phones, digital camera

Based on the Performance of the Microcontroller

Small Scale Systems

▪ Entry-level embedded system with no design complexity involves

▪ Work with 8-bit (8051) or 16-bit (80196) microcontrollers


▪ Most of these systems are battery operated

▪ Hardware and software complexity is very low due to the small size of microcontrollers

▪ Easy to program using assembly language or C-programing language

▪ Requires small memory as it deals with a small amount of data

▪ Ex: robotic arm controller, electronic toys, automatic coffee vending machines, thermometer.

Medium Scale Systems

▪ System is designed using 16-bit or 32-bit microcontrollers

▪ Offers better speed than small scale Embedded system

▪ Hardware and software complexity is present

▪ Run through Microcontrollers and digital signal processors

▪ Requires comparatively more memory power than small scale ones

▪ Along with microcontrollers, you need application-specific operating systems

▪ Ex: Routers, ATMs, music systems, pagers

Sophisticated Systems

▪ Make use of 32-bit or 64-bit microcontroller and multi-core processors

▪ Requires very high memory power

▪ Power consumption is the highest among rest types of embedded systems

▪ Hardware and software complexities are enormous

▪ Speed is a major concern

▪ Some applications, like satellite systems, also involve real-time operating system (RTOS)

▪ Ex: mobile systems, washing machines, digital watches, LAN cards, multimedia systems

To ensure efficient board development with embedded systems, you need accurate component
footprint data, CAD models, and information about microcontrollers to be used in the application.

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.
• 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.
MICROPROCESSOR Vs MICROCONTROLLER

Difference between Microprocessor and Microcontroller

The following table highlights all the important differences between microprocessors and
microcontrollers −

Parameter Microprocessor Microcontroller

Microprocessors can be understood as Microcontrollers can be understood as the


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

A microprocessor is a processor where A microcontroller is a controlling device


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

Circuit The circuit is complex due to external Microcontrollers are present on chip
complexity connection. memory. The circuit is less complex.

Memory and I/O The memory and I/O components are The memory and I/O components are
components 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 status Microcontroller doesn’t have a zero status


Zero status flag
flag. flag.

Number of Microprocessors have less number of Microcontrollers have more number of


registers registers. registers.

Microprocessors are generally used in Microcontrollers are generally used in


Applications
personal computers. washing machines, and air conditioners.
EMBEDDED PROCESSOR (heart of Embedded System)

• Special microprocessors & microcontrollers often called, Embedded processors.

• An embedded processor is used when fast processing fast context-switching & atomic ALU
operations are needed.

Examples: ARM 7, INTEL i960, AMD 29050.

General purpose processor (DSP)

• DSP as a GPP is a single chip VLSI unit.

• It includes the computational capabilities of microprocessor and multiply & accumulate


units (MAC).

• DSP has large number of applications such as image processing, audio, video &
telecommunication processing systems.

• It is used when signal processing functions are to be processed fast.

Examples: TMS320Cxx, SHARC, Motorola 5600xx

MULTI PROCESSOR SYSTEM USING GPPs

• Multiple processors are used when a single processor does not meet the needs of different
task.

• The operations of all the processors are synchronized to obtain an optimum performance.

APPLICATION SPECIFIC SYSTEM PROCESSOR (ASSP)

• ASSP is dedicated to specific tasks and provides a faster solution.

• An ASSP is used as an additional processing unit for running the application in place of using
embedded software.

Examples: IIM7100, W3100A

ARM processor is a strong option for better performance. But when we consider the power
consumption, in the case of ARM it is around 400mW and the ATmega1031, AVR microcontroller
consumes low power around 16.5mW, but provides low performance.

Texas instruments MSP430 with wide range of operation modes consumes only 1.2mW with
reasonably good performance. So it is always left to the designer to choose a suitable device
according to the requirement
Communication Interfaces

For embedded systems to interact with the external world, a number of communication interfaces
are available.

They are

• Serial Communication Interfaces (SCI): RS-232, RS-422, RS-485 etc

• Synchronous Serial Communication Interface: I2C, JTAG, SPI, SSC and ESSI

• Universal Serial Bus (USB)

• Networks: Ethernet, Controller Area Network, LonWorks, etc

• Timers: PLL(s), Capture/Compare and Time Processing Units

• Discrete IO: General Purpose Input/Output (GPIO)

• Analog to Digital/Digital to Analog (ADC/DAC)

Part 3: Embedded Operating Systems


An embedded operating system is a small-scale computer of an embedded system with a limited
number of features. It is designed to carry out a function or a set of functions of an electronic end
product. Akin to a desktop PC that requires an OS like Windows, Linux, or Mac OS to run basic apps,
embedded systems also need an operating system to facilitate and expedite their functionality.

An embedded operating system is a specialized operating system (OS) designed to perform a specific
task for a device that is not a computer. The main job of an embedded OS is to run the code that
allows the device to do its job. The embedded OS also makes the device's hardware accessible to
software that is running on top of the OS.

Here are some common characteristics of an embedded OS:

• Power efficient

• Fewer storage capabilities

• Smaller processing power

• Fast and lightweight

• I/O device flexibility

• Real-time operation

• Tailored to the intended use case

Examples of embedded OS devices

Some examples of devices with embedded OSes include the following:


• ATMs

• cellphones

• electric vehicles

• industrial control systems (ICS)

• Arduino-based devices

Types of Embedded Operating System

There are various types of Embedded operating systems. Some of them are as follows:

1. Real-Time Operating System

A real-time operating system (RTOS) is a deterministic operating system with limited functionalities
that allows multi-threaded applications by giving processed outputs within set time limitations. Since
some apps are time-critical, they must be executed exactly when they are expected to maintain the
entire system functioning.

The real-time operating system is dependent on clock interruptions. Interrupt Service Routine
(ISR) interruptions are generated by this system. The Priority system was implemented by RTOS for
the execution of all types of processes. The process and the RTOS are synchronized and can
communicate with one another. The RTOS is stored on a ROM (Read Only Memory) chip because
this chip can store data for a long time.

2. Multi-tasking Operating System

The multitasking operating system may execute multiple tasks at the same time. In a multitasking
operating system, multiple tasks and processes run at the same time. If the system contains more
than one processor, it may perform a wide range of functions.
The multitasking operating system is switched between the multiple tasks. Some tasks are waiting for
events to occur, while others are receiving events and preparing to run. When using a multitasking
operating system, software development is easier since different software components may be made
independent of each other.

3. Pre emptive Operating System

A multitasking operating system that interprets task preemption is known as a preemptive operating
system. A task with a higher priority is always defined and executed before a task with a lower
priority. Such multitasking operating systems improve system reaction to events and simplify
software development, resulting in a more dependable system. The system designer may calculate
the time required for service interpreters in the system and the time required by the scheduler to
switch tasks. Such systems can fail to meet a system's deadline, and the program is unaware of the
missed deadline. CPU load can be naturally measured in a preemptive operating system by defining a
lower priority process that does nothing except increment the counter.

4. Rate Monotonic Operating System

Some embedded systems are designed to use a specific task scheduling method known as 'Rate
Monotonic Scheduling'. It is an operating system that assures that tasks in a system may operate for
a specific amount of time and duration of time. It is a priority-based scheduling algorithm. It is used
in operating systems as a preemptive. It means that all tasks can be interrupted or suspended by
other tasks within a short period of time. It is generally used to perform shorter tasks with higher
priority.

5. Single System Control Loop

It is a very simple type of operating system designed to perform only one function. It is used in
several devices, including smartphones, thermostats or temperature controls, digital controllable
equipment, etc. Users may set any point of temperature variable as desired in this type of OS.
Several sensors are included in this system to determine various temperature points in the
environment.

6. Templated

In the distributed and cloud computing context of an OS, templating refers to creating a single virtual
machine image as a guest operating system, then saving it as a tool for multiple running virtual
machines. The technique is used both in virtualization and cloud computing management, and is
common in large server warehouses.

7. Embedded

Embedded operating systems are designed to be used in embedded computer systems. They are
designed to operate on small machines with less autonomy (e.g. PDAs). They are very compact and
extremely efficient by design, and are able to operate with a limited amount of resources. Windows
CE and Minix 3 are some examples of embedded operating systems.
Mobile OS

• A mobile operating system is an operating system for mobile


phones, tablets, smartwatches, 2-in-1 PCs (that can be convert to a laptop mode or detach
and work as a tablet mode), smart speaker or other mobile devices.

• Mobile operating systems combine features of a personal computer operating system with
other features useful for mobile or handheld use, and usually including a wireless inbuilt
modem and SIM tray for telephony and data connection

Types of Mobile OS

1. Android OS: The Android operating system is the most popular operating system today. It is a
mobile OS based on the Linux Kernel and open-source software. The android operating system was
developed by Google. The first Android device was launched in 2008.

2. Bada (Samsung Electronics): Bada is a Samsung mobile operating system that was launched in
2010. The Samsung wave was the first mobile to use the bada operating system. The bada operating
system offers many mobile features, such as 3-D graphics, application installation, and multipoint-
touch.

3. BlackBerry OS: The BlackBerry operating system is a mobile operating system developed
by Research In Motion (RIM). This operating system was designed specifically for BlackBerry
handheld devices. This operating system is beneficial for the corporate users because it provides
synchronization with Microsoft Exchange, Novell GroupWise email, Lotus Domino, and other
business software when used with the BlackBerry Enterprise Server.

4. iPhone OS / iOS: The iOS was developed by the Apple inc for the use on its device. The iOS
operating system is the most popular operating system today. It is a very secure operating system.
The iOS operating system is not available for any other mobiles.

5. Symbian OS: Symbian operating system is a mobile operating system that provides a high-level of
integration with communication. The Symbian operating system is based on the java language. It
combines middleware of wireless communications and personal information management (PIM)
functionality. The Symbian operating system was developed by Symbian Ltd in 1998 for the use of
mobile phones. Nokia was the first company to release Symbian OS on its mobile phone at that time.

6. Windows Mobile OS: The window mobile OS is a mobile operating system that was developed
by Microsoft. It was designed for the pocket PCs and smart mobiles.

7. Harmony OS: The harmony operating system is the latest mobile operating system that was
developed by Huawei for the use of its devices. It is designed primarily for IoT devices.

8. Palm OS: The palm operating system is a mobile operating system that was developed by Palm
Ltd for use on personal digital assistants (PADs). It was introduced in 1996. Palm OS is also known as
the Garnet OS.

9. WebOS (Palm/HP): The WebOS is a mobile operating system that was developed by Palm. It based
on the Linux Kernel. The HP uses this operating system in its mobile and touchpads.
Part 4: Characteristics of Real Time Operating System

Real-time System is a system that is put through real time which means response is obtained within
a specified timing constraint or system meets the specified deadline. Real time system is of two types
– Hard and Soft. Both are used in different cases. Hard real time systems are used where even the
delay of some nano or micro seconds are not allowed. Soft real time systems provide some relaxation
in time expression.

Characteristics of Real-time System:

Following are the some of the characteristics of Real-time System:

1. Time Constraints: Time constraints related with real-time systems simply means that time
interval allotted for the response of the ongoing program. This deadline means that the task
should be completed within this time interval. Real-time system is responsible for the
completion of all tasks within their time intervals.

2. Correctness: Correctness is one of the prominent part of real-time systems. Real-time


systems produce correct result within the given time interval. If the result is not obtained
within the given time interval then also result is not considered correct. In real-time systems,
correctness of result is to obtain correct result in time constraint.

3. Embedded: All the real-time systems are embedded now-a-days. Embedded system means
that combination of hardware and software designed for a specific purpose. Real-time
systems collect the data from the environment and passes to other components of the
system for processing.

4. Safety: Safety is necessary for any system but real-time systems provide critical safety. Real-
time systems also can perform for a long time without failures. It also recovers very soon
when failure occurs in the system and it does not cause any harm to the data and
information.

5. Concurrency: Real-time systems are concurrent that means it can respond to a several
number of processes at a time. There are several different tasks going on within the system
and it responds accordingly to every task in short intervals. This makes the real-time systems
concurrent systems.

6. Distributed: In various real-time systems, all the components of the systems are connected
in a distributed way. The real-time systems are connected in such a way that different
components are at different geographical locations. Thus, all the operations of real-time
systems are operated in distributed ways.

7. Stability: Even when the load is very heavy, real-time systems respond in the time constraint
i.e. real-time systems does not delay the result of tasks even when there are several task
going on a same time. This brings the stability in real-time systems.

8. Fault tolerance: Real-time systems must be designed to tolerate and recover from faults or
errors. The system should be able to detect errors and recover from them without affecting
the system’s performance or output.

9. Determinism: Real-time systems must exhibit deterministic behaviour, which means that the
system’s behaviour must be predictable and repeatable for a given input. The system must
always produce the same output for a given input, regardless of the load or other factors.
10. Real-time communication: Real-time systems often require real-time communication
between different components or devices. The system must ensure that communication is
reliable, fast, and secure.

11. Resource management: Real-time systems must manage their resources efficiently, including
processing power, memory, and input/output devices. The system must ensure that
resources are used optimally to meet the time constraints and produce correct results.

12. Heterogeneous environment: Real-time systems may operate in a heterogeneous


environment, where different components or devices have different characteristics or
capabilities. The system must be designed to handle these differences and ensure that all
components work together seamlessly.

13. Scalability: Real-time systems must be scalable, which means that the system must be able
to handle varying workloads and increase or decrease its resources as needed.

14. Security: Real-time systems may handle sensitive data or operate in critical environments,
which makes security a crucial aspect. The system must ensure that data is protected and
access is restricted to authorized users only.

Part 5: Compare different Operating Systems used for embedded system designing

Multi-Tasking Operating System

It is a type of embedded system that is bound to perform multiple tasks simultaneously as per the
need of the application. Besides, it is specifically programmed to process between various systems.
And their numerous functions according to the need to make that application.

If multitasking is part of app development, then that one does the scheduling algorithm that can
quickly establish rules for better organizing the tasks. Multitasking OS includes a scheduling
algorithm that can simultaneously set rules for multiple tasks.

Real Time Operating System: explained in the previous page

Linux Operating System

Linus Torvalds introduced Linux OS for embedded systems and also made a copy of the Unix kernel.
It is an open-source software code used to create flexible, secure, and safe devices for daily use.

Linux is not intrinsically RTOS but extensions that might make it a viable option to use—well designed
to install in embedded systems of devices.

The most significant example of Linux is smart home devices, car consoles, smart tablets, digital
storage devices, etc.

Advantages of using Embedded Linux:

Linux works on two interfaces only with limited memory space: LED and serial ports.
• Linux is an independent platform.

• It allows multiple modifications in the source code to reuse the components.

• The embedded operating system software is cheaper and reduces the cost of hardware.

Moving on to the next OS, more recently, a new breed of embedded operating systems emerged
with a bespoke version of Android. At first impression, an Android embedded system may seem a
little odd as an embedded OS. But the fact is that Android is already a part of embedded Linux and a
popular choice as an embedded operating system.

Single System Control Loop

It is one of the most basic types of embedded OS systems used when the control is over a single
measured variable. The best example of this system is nowadays the intelligent home temperature
control that people use, developed with the help of an embedded OS.

Embedded Android

Is Android just Linux?

Well, the answer is still vague.

Linux is an excellent choice for embedded systems in many cases. So, what differentiates the Android
open source embedded operating system from other embedded Linux projects?

The basic definition is that Android sits on top of the Linux kernel, and below are the additional
features that add to its popularity.

• It’s free to use.

• Android is an obvious option for any touch screen product for its rich UI interface.

• Regular programming with tools for debugging.

• Open-source software to customize to your needs.

• Quick Prototyping

With all the above-explained types of embedded operating systems, let us now read which OS tops
the list and why it is the best for embedded systems.

Rate Monotonic Operating System

This embedded system is mainly used to accomplish specific tasks per the deadlines; this embedded
OS is available at your rescue. This task monitoring system’s primary purpose is to ensure the job’s
requirements. And there are specific functions that will be required to get special priority, and it will
do the same according to the time constraints.

Besides, the rate tends to assign specific tasks per the necessary guidelines to ensure that the
particular functions are met within the best priority treatment and get the possible jobs done on
time without lag. This OS is best used when the device parts are task-specific, as no other alternative
is available to do this job better.
UNIT 3: Open-Source Embedded Development Board (Arduino) and
Unit 4 (PART 1): using standard questions

Q1.

Briefly explain the concept of input and output port of embedded development board.
Also write a program for serial port interfacing.

In 8051 Microcontroller, I/O operations are performed by using four ports and 40 pins. I/O operation
port uses 32 pins with each port has 8 pins. The remaining 8-pins are used for providing

Let's see the 40-Pin Plastic Dual Inline Package (PDIP) integrated circuit of microcontroller:

Note - In DIP structure of microcontroller we can recognize the first and last pin by using the
cut present at middle of IC this cut is called as Notch of microcontroller. The first pin is
present at left side of notch and last pin is present at right side of notch.
I/O Ports and their Functions:
In microcontroller there are four Input/output ports P0, P1, P2, and P3, each port is 8-bit port having
8 pins each. During RESET, all the ports are used as input ports. When the port gets first 0, then it
becomes an output port. For reconfigure it as an input, the high signal (1) must be sent to a port.

Port 0 (Pin No 32 - Pin No 39):

Port 0 contains 8 pins. It can be used as input or output. In general we connect P0 with 10K-ohm pull-
up resistors for using it as an input or output port being an open drain.

It is also referred as AD0-AD7, which allowing it to be used as both address and data transfer port.
When we want to excess the external ROM, then P0 is used as both Data and Address Bus.

Address Latch Enable (ALE) Pin no 31 indicates if PO is used as address or data.

When ALE=0 then it provides data D0-D7.

When ALE=1 then it provides address A0-A7.

Let's see the structure of port 0 with externally connected pull up resistor:

Let's see an assembly language code for making the Port 0 to be worked as an input:-

1. MOV A, #FFH; (comments: A=FFH i.e. A=1111 1111)

2. MOV P0, A; (Port 0 all pin have 1's so that it work as Input)

Port 1 (Pin No 1-Pin No 8):

It is also an 8-bit Port and can be worked as either input or output. It doesn't require external
connected pull-up resistors because they are already present internally. Upon reset, Port 1 worked as
an input port.
If port 1 is configured as an output port, then to use port 1 as input port again, we write 1 to all bits
of port 1 as shown in the below code:-

1. MOV A, #FFH ; Value of Accumulator register A=FF hex

2. MOV P1, A ; Port 1 worked as an input port

3. MOV A, P1 ; get data from P1

4. MOV R5, A ; save it in Register R5

5. ACALL DELAY ; wait

6. MOV A, P1 ; get another data from P1

7. MOV R6, A ; save it in R6

8. ACALL DELAY ; wait

9. MOV A, P1 ; get data from P1

10. MOV R7, A ; save it in R7

Port 2 (Pin No 21-Pin No 28):

Port 2 uses a total of 8 pins and it can also be used as input and output operation. Same as Port 1, P2
also not require external pull- up resistors. Port 2 can be used along with P0 to provide 16-bit
address for an external memory. Therefore it is designated as (A0-A7), as shown in pin diagram.

If Port 2 is configured as an output port, then for using it as an input port again we write 1 to all bits
of port 2 as shown in the below code:-

1. MOV A, #FFH ; Value of Accumulator register A=FF hex

2. MOV P2, A ; Port 2 worked as an input port

3. BACK:

4. MOV A, P1 ; get data from P2

5. MOV P1, A ; save it in Port 1

6. SJMP BACK ; Keep doing that

Port 3 (Pin No 10-Pin No 17):

Port 3 is also of 8 bits and it can be used as Input/output. This port provides some important signals.

P3.1 and P3.0 are RxD (Receiver) and TxD (Transmitter) respectively and it is collectively used for
serial communication.

P3.3 and P3.2 pins are used as external interrupts.

P3.5 and P3.4 are used as timers T1 and T0 respectively.

P3.6 and P3.7 are Write (WR) and Read (RD) pins.
Let's see the Port 3 table showing an individual pin function:

I/O Ports and Bit Addressability:

It is a mostly used feature of 8051 while writing code for 8051. Sometimes there is a need to use only
1 or 2 bits of the port instead of using entire 8-bits. 8051 microcontroller provides the feature to use
each bit of the ports.

While using a port in a single-bit manner, we provide the syntax "SETB X.Y", where X is the port
number varies from 0 to 3, and Y is a bit number varies from 0 to 7.

For example: - "SETB P1.3" sets high bit 3 of port 1.

Let's see an assembly code for toggling the bit of P1.5 continuously:

1. AGAIN:

2. SETB P1.5

3. ACALL DELAY

4. CLR P1.5

5. ACALL DELAY

6. SJMP AGAIN
Single Bit Instruction:

Instruction Function

CLR bit Clear the bit (bit=0)

CPL bit Complement the bit (bit=NOT bit)

SETB bit Set the bit (bit = 1)

JB bit, target Jump to target if bit = 1 (jump if bit)

JBC bit, target Jump to target if bit = 1, clear bit (jump if bit, then clear)

JNB bit, target Jump to target if bit = 0 (jump if no bit)

Serial Port Interfacing Program Examples


NOTE:
Read the complete presentation from the link below
https://slideplayer.com/slide/13575290/

You can also follow the link below for more understanding
https://www.slideshare.net/anishgoel/embedded-systems-ppt-comm-interface

https://ebooks.inflibnet.ac.in/csp13/chapter/serial-port-communication/
Q2.
Explain the working and pin architecture of open-source embedded development board
using block diagram.
The Arduino microcontroller is an easy to use yet powerful single board computer that has
gained considerable traction in the hobby and professional market. The Arduino is open-
source, which means hardware is reasonably priced and development software is free.
The Arduino project was started in Italy to develop low cost hardware for interaction design.
The Arduino hardware comes in several flavors. In the United States, Sparkfun
(www.sparkfun.com is a good source for Arduino hardware.
With the Arduino board, you can write programs and create interface circuits to read
switches and other sensors, and to control motors and lights with very little effort.

Block Diagram of Arduino

Arduino Architecture:
Arduino’s processor basically uses the Harvard architecture where the program code and
program data have separate memory. It consists of two memories- Program memory and the
data memory.The code is stored in the flash program memory, whereas the data is stored in
the data memory. The Atmega328 has 32 KB of flash memory for storing code (of which 0.5
KB is used for the bootloader), 2 KB of SRAM and 1 KB of EEPROM and operates with a clock
speed of 16MHz.
Arduino Architecture

Processor: The processor is the heart of embedded system. The selection of processor is
based on the following consideration
• Instruction set
• Maximum bits of operation on single arithmetic and logical operation
• Speed
• Algorithms processing and capability
• Types of processor( microprocessor, microcontroller, digital signal processor,
application specific processor, general purpose processor)
Power source:
Internal power supply is must. Es require from power up to power down to start time task.
Also it can run continuously that is stay “On’ system consumes total power hence efficient
real time programming by using proper ‘wait’ and ‘stop’ instruction or disable some unit
which are not in use can save or limit power consumption.
Clock / oscillator Circuits:
The clock ckt is used for CPU, system timers, and CPU machine cycles clock controls the time
for executing an instruction. Clock oscillator may be internal or external .It should be highly
stable.
Real time clock (RTC):
It require to maintain scheduling various tasks and for real time programming RTC also use
for driving timers, counters needs in the system.
Resets Circuits and power on reset:
Reset process starts executing various instruction from the starting address. The address is
set by the processor in the program counter. The reset step resent and runs the program in
the following way
• System program that execute from beginning
• System boot up program
• System initialization program
Memory:
A system embeds either in the internal flash or ROM, PROM or in an external flash or ROM
or PROM of the microcontroller.

Pin Diagram with description


In addition to the specific functions listed below, the digital pins on an Arduino board can be
used for general purpose input and output via the pinMode(), digitalRead(), and
digitalWrite() commands. Each pin has an internal pull-up resistor which can be turned on
and off using digitalWrite() (w/ a value of HIGH or LOW, respectively) when the pin is
configured as an input. The maximum current per pin is 40 mA.
Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data. On the
Arduino Diecimila, these pins are connected to the corresponding pins of the FTDI USB-to-
TTL Serial chip. On the Arduino BT, they are connected to the corresponding pins of the
WT11 Bluetooth module. On the Arduino Mini and LilyPad Arduino, they are intended for
use with an external TTL serial module (e.g. the Mini-USB Adapter)
External Interrupts: 2 and 3. These pins can be configured to trigger an interrupt on a low
value, a rising or falling edge, or a change in value.
PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function. On
boards with an ATmega8, PWM output is available only on pins 9, 10, and 11.
Reset: 7. (Arduino BT-only) Connected to the reset line of the bluetooth module.
SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). These pins support SPI communication, which,
although provided by the underlying hardware. It allow serial communication with another
interface by connecting it serially.
LED: 13. On the Diecimila and LilyPad, there is a built-in LED connected to digital pin 13.
When the pin is HIGH value, the LED is on, when the pin is LOW, it's off.
Few of basic Adruino functions are:
• digitalRead(pin): Reads the digital value at the given pin.
• digitalWrite(pin, value): Writes the digital value to the given pin.
• pinMode(pin, mode): Sets the pin to input or output mode.
• analogRead(pin): Reads and returns the value.
• analogWrite(pin, value): Writes the value to that pin.
• serial.begin(baud rate): Sets the beginning of serial communication by
setting the bit rate.
Reasons why Arduino is being preferred these days (Features)
1. It is inexpensive
2. It comes with an open source hardware feature which enables users to develop their
own kit using already available one as a reference source.
3. The Arduino software is compatible with all types of operating systems like Windows,
Linux, and Macintosh etc.
4. It also comes with open source software feature which enables experienced software
developers to use the Arduino code to merge with the existing programming
language libraries and can be extended and modified.
5. It is easy to use for beginners.
6. We can develop an Arduino based project which can be completely stand alone or
projects which involve direct communication with the software loaded in the
computer.
7. It comes with an easy provision of connecting with the CPU of the computer using
serial communication over USB as it contains built in power and reset circuitry.

Features of Arduino Uno Board

The features of Arduino Uno ATmega328 includes the following.


• The operating voltage is 5V
• The recommended input voltage will range from 7v to 12V
• The input voltage ranges from 6v to 20V
• Digital input/output pins are 14
• Analog i/p pins are 6
• DC Current for each input/output pin is 40 mA
• DC Current for 3.3V Pin is 50 mA
• Flash Memory is 32 KB
• SRAM is 2 KB
• EEPROM is 1 KB
• CLK Speed is 16 MHz
Q3.
Explain the block diagram, architecture of ATmega 8 and it's pin diagram in complete
detail.

ATmega8 Pin Diagram

One of the most important features of ATmega8 microcontroller is that except 5 pins, all
other pins can be used for supporting two signals.
o Pins 9,10,14,15,16,17,18,19 are used for port B,
Whereas Pins 23,24,25,26,27,28 and 1 are used for port C and
Pins 2,3,4,5,6,11,12 are used for port D.
o Port B (PB7…PB0) XTAL1/XTAL2/TOSC1/TOSC2
Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for
each bit). The Port B output buffers have symmetrical drive characteristics with both
high sink and source capability. As inputs, Port B pins that are externally pulled low
will source current if the pull-up resistors are activated. The Port B pins are tri-stated
when a reset condition becomes active, even if the clock is not running.
o Port C (PC5…PC0)
Port C is a 7-bit bi-directional I/O port with internal pull-up resistors (selected for
each bit). The Port C output buffers have symmetrical drive characteristics with both
high sink and source capability. As inputs, Port C pins that are externally pulled low
will source current if the pull-up resistors are activated. The Port C pins are tri-stated
when a reset condition becomes active, even if the clock is not running.
o Port D (PD7…PD0)
Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for
each bit). The Port D output buffers have symmetrical drive characteristics with both
high sink and source capability. As inputs, Port D pins that are externally pulled low
will source current if the pull-up resistors are activated. The Port D pins are tri-stated
when a reset condition becomes active, even if the clock is not running.
o Pin 1 is used as Reset pin and on applying low level signal for time longer than
minimum pulse length will generate a reset signal.
o Pins 3 and 2 can also be used in serial communication for USART (Universal
Synchronous and Asynchronous Receiver Transmitter).
o Pin 5 and 4 are used as external interrupts.
o Pins 10 and 9 are used as timer counter oscillators as well as external oscillator
where the crystal is connected directly between the pins.
o Pin 19 is used as slave clock input or master clock output for Serial Peripheral
Interface (SPI) channel.
o Pin 18 is used as slave clock output or master clock input
o Pins 23 to 28 are used for analog to digital conversion (ADC) channels.
o Pin 12 and 13 are used as Analog Comparator inputs.
o Pins 6 and 11 are used as counter/timer sources.

ATmega8 Microcontroller Sleep Modes:


The Microcontroller operates in 5 sleep modes as given below:
o Power save Mode: It is used when Counter/Timer is clocked asynchronously. In
general this mode used for saving the operational power requirement of
microcontroller.
o Idle Mode: It stops the functioning of CPU, but allows operation of ADC, TWI, SPI,
and interrupts system and Watchdog. It is achieved by setting SM0 to SM2 bits of
Microcontroller Unit register flag at zero.
o Power down Mode: It enables external interrupts, the 2-wire serial interface, and
watchdog while disabling the external oscillator. It stops all generated clocks.
o ADC Noise Reduction Mode: It stops the central processing unit but allows the
functioning of ADC, timer/counter and external interrupts.
o Stand By mode: In this mode, only oscillator is allowed to operate by slowing all
other operation of microcontroller.

Block Diagram of ATmega 8L


Atmega8 AVR Microcontroller Architecture
Memory: It has 1Kbyte Internal SRAM, 8 Kb of Flash program memory and 512 Bytes of
EEPROM.
I/O Ports: It has three ports, namely port-B, port-C, and port-D and 23 I/O line can be
attained from these ports.
Interrupts: The two Exterior Interrupt sources are located at port D. Nineteen dissimilar
interrupts vectors supporting nineteen events produced by interior peripherals.
Timer/Counter: There are 3-Internal Timers are accessible, 8 bit-2, 16 bit-1, presenting
numerous operating modes & supporting internal/external clocking.
Serial Peripheral Interface (SPI): ATmega8 microcontroller holds three integrated
communication devices. One of them is an SPI, 4-pins are allocated to the Microcontroller to
implement this system of communication.
USART: USART is one of the most powerful communication solutions.
Microcontroller ATmega8 supports both synchronous & asynchronous data transmission
schemes. It has three pins allocated for that. In many communication projects, the USART
module is widely used for communication with PC-Microcontroller.
Two-Wire Interface (TWI): TWI is another communication device that is present in the
ATmega8 microcontroller. It permits designers to set up a communication b/n two devices
using two wires along with a mutual GND connection, As the o/p of the TWI is made using
open collector o/ps, therefore external pull-up resistors are compulsory to make the circuit.
Analog Comparator: This module is incorporated in the integrated circuit that offers a
contrast facility between two voltages linked to the two inputs of the comparator through
External pins associated with the Microcontroller.
ADC: Inbuilt ADC (analog to digital converter) can alter an analog i/p signal into digital data
of the 10-bit resolution. For a maximum of the low-end application, this much resolution is
sufficient.
Features of Atmega8 AVR Microcontroller Architecture
• Advanced RISC Architecture
o 130 Powerful Instructions – Most Single-clock Cycle Execution
o 32 × 8 General Purpose Working Registers
o Fully Static Operation
o Up to 16MIPS Throughput at 16MHz
o On-chip 2-cycle Multiplier
• High Endurance Non-volatile Memory segments
o 8Kbytes of In-System Self-Programmable Flash program memory
o 512Bytes EEPROM
o 1Kbyte Internal SRAM
o Write/Erase Cycles: 10,000 Flash/100,000 EEPROM
o Data retention: 20 years at 85°C/100 years at 25°C (1)
o Optional Boot Code Section with Independent Lock Bits
o In-System Programming by On-chip Boot Program
o True Read-While-Write Operation
o Programming Lock for Software Security
• Peripheral Features
o Two 8-bit Timer/Counters with Separate Prescaler, one Compare Mode
o One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and
Capture Mode
o Real Time Counter with Separate Oscillator
o Three PWM Channels
o 8-channel ADC in TQFP and QFN/MLF package (Eight Channels 10-bit
Accuracy)
o 6-channel ADC in PDIP package (Six Channels 10-bit Accuracy)
o Byte-oriented Two-wire Serial Interface
o Programmable Serial USART
o Master/Slave SPI Serial Interface
o Programmable Watchdog Timer with Separate On-chip Oscillator
o On-chip Analog Comparator
• Special Micro-controller Features
o Power-on Reset and Programmable Brown-out Detection
o Internal Calibrated RC Oscillator
o External and Internal Interrupt Sources
o Five Sleep Modes: Idle, ADC Noise Reduction, Power-save, Power-down, and
Standby
• I/O and Packages
o 23 Programmable I/O Lines
o 28-lead PDIP, 32-lead TQFP, and 32-pad QFN/MLF
• Operating Voltages
o 2.7V – 5.5V (ATmega8L)
o 4.5V – 5.5V (ATmega8)
• Speed Grades
o 0 – 8MHz (ATmega8L)
o 0 – 16MHz (ATmega8)
• Power Consumption at 4Mhz, 3V, 25C
o Active: 3.6mA
o Idle Mode: 1.0mA
o Power-down Mode: 0.5µA
Q4.
Explain the essential peripheral circuits for 8-bit microcontrollers.
https://embeddedinventor.com/9-essential-microcontroller-peripherals-explained/
Common embedded peripherals that most systems need include
• GPIO controllers
• Timers
• PWM controllers
• DACs
• ADCs
• Serial Communication Controllers for UART, SPI, I2C, and Ethernet
• Memory
• Interrupt controllers and
• Direct Memory Access controllers (DMA)

1. GPIO controllers
GPIO stands for General Purpose Input and Output. These refer to the pins that are coming
out of the microcontroller SoC.

The basic functionality of a GPIO controller includes


• setting the GPIO pins as either input or output,
• reading the voltage level, if they are set as input
• writing the voltage to 0 or 1 if they are set as output.
• can be routed to other peripherals such as ADCs and DACs to serve some alternate
functions as needed by the peripherals.
Generally, a single one of these GPIO controllers are able to control 8 IO pins and a
microcontroller can have more than one of these. These units are usually referred to as Ports
(Port A is controlled by GPIO controller A, port B is controlled by GPIO controller B,…)

2. Timers
Timing is a crucial part of any embedded system, be it controlling the blinking rate of the
LEDs or controlling the sampling rate of the ADCs, or a simple delay on the source code. This
need for timing is usually handled by devices called timers.
Timers can operate in 2 modes
1. One time mode and
2. Periodic mode
One-time mode
In One-time mode, we can set the timer to go off after a particular time duration, say 10 ms.
Once started, the timer counts down and once it runs out it notifies the core through a
mechanism called interrupts (discussed later in this article)and the timer gets disabled. This
action is very similar to using a stopwatch in count down mode.
Periodic mode
In periodic mode, once the timer runs out, it notifies the core, then instead of getting
disabled, it automatically reloads the initial value and starts counting down again. Basically,
all this mode does extra compared to the One-time mode is just the auto-restart!
There are several types of timers that can be present in an embedded system. Examples cam
include general-purpose timers, watchdog timers, and SysTick timers. Each of these is useful
in specific scenarios. You can read this article to learn more about timers.

3. Pulse Width Modulation (PWM) controllers


These are special kinds of timers that are directly able to control the voltage output at a
given GPIO pin.
The microcontrollers are digital devices that can only deal with binary voltage levels, level 0
and level 1. Level 1 can be 1.8v or 3.3v or 5v depending upon the microcontroller design and
Level 0 is usually 0v. If we need some other voltages in the middle, let’s say 0.45v, the only
way to accomplish this is by turning on and off the pins continuously at a very fast rate so
that the average voltage becomes 0.45v. The device that does this is called PWM
controllers.
For example, say we have a microcontroller with voltage levels of 0v and 5v and we need
2.5v output. We can use the PWM controller to do that for us by asking it to keep the pin at
0v for 1ms and 5v for 1ms and just alternate between the 2 for as long as we need this 2.5v
output.

PWM Duty Cycle


The duty cycle and period are the 2 most important parameters when designing the chip.
Duty cycle is the ratio of On-time to Off-time and the period of a PWM output is simply the
time duration of one period as shown in the image above.
The most common application of PWM is to drive the LEDs to variable brightness. Other
examples include controlling motors, audio amplifiers, and power supplies.

4. Digital to analog converters (DAC)


They take integers (digital numbers) as input and produce an equivalent analog signal as
output. PWM controller discussed above does something similar to it, but not exactly, the
difference being the fact that it can only produce digital voltage signals. That is, it cannot
produce analog signals.
For example, let’s say we need to create a sine waveform signal, then we need to give the
DAC a set of numbers as input one by one in with a fixed time interval. Let’s use a 16 point
sine wave to accomplish this. Sine function can take input from 0 to 2π, so the 16 points we
need are sine(0), sine(π/8), sine(2π/8), sine(3π/8) … sine(15π/8). ( sine(16π/8) becomes
sine(2π) which is same as sine(0).
DAC block diagram
So the resulting 16 points look like this.

The results are multiplied by 1000 and added with 1024 to get the integers that we need to
send to the DAC controller (more details about this conversion in the next section). DACs
simply take in this input number and hands it over to its holding module which holds the
output voltage of the DAC proportional to the input number. Since we are using a constant
interval transmission, we end up with a stepped sine wave as in the picture

Stepped sine wave


The next step is to put this output through some wave smoothening filters which basically
interpolates the sine wave and gives us an output like this
DAC output quality
The quality of the output can be increased by choosing a DAC that accepts a bigger range of
numbers as input. For example, an 8 bit DAC can only take 0 to 255, while a 32 bit DAC can
take 0 to 4294967295 and hence more accurate outputs!
Our example above assumed an 11 bit DAC (0 to 2045) and that’s the reason we multiplied
the results by a 1000 and added 1023 (sine function varies from -1 to 1) so that we can get
results in this range of 0 to 2045.
Applications of DAC
DAC is used in all application that involves an analog output. Some famous examples include
speakers, medical devices, AC motor drive controllers and analog video equipment.

5. Analog to digital converters(ADC)


Anywhere you see analog sensors being used as input, it is usually connected to special pins
with an ADC underneath, called analog pins. You can see the pins labeled A0, A1, A2,… in
this pic of my Arduino below.
These ADCs are devices that can sense the voltage at a given GPIO pin. It takes an analog
voltage and converts it to a digital number. It does so using a method called sampling and
quantization.

ADC conversion
As you can see in the above picture, the process is the exact inverse of what a DAC does, for
example here a sine wave is transformed into a series of numbers, which can be used inside
the microprocessor for further processing (in case of amplification and recording sound
signals) or making decisions (in case of sensor input like battery voltage and temperature
sensor)

6. Serial communication Controllers


To talk to the external peripherals, some sort of communication protocol is needed. This is
taken care of using devices called serial communication controllers. The most common
examples of serial communication protocols include UART, I2C, and SPI. There are several
others like I2S, USART, USB, Ethernet, Bluetooth, Wifi and so on. In essence, almost all of the
communication protocols we use these days are serial in nature.
Serial vs parallel communication
To understand what serial communication really means let’s see how different it is from
parallel communication. Imagine a hollow pipe, and your job is to send a set of 8 balls from
one end of the pipe to another. So you start putting them one by one through the pipe. This
is the principle behind a serial protocol. Here each ball represents a bit of data (either a zero
or a one) and the pipe represents the communication channel which can be a PCB track or a
USB cable or an ethernet cable or just air for wireless protocols like WiFi.

Now imagine a set of 8 pipes, and a set of 8 balls, here you can simply send the 8 balls
together instead of sending one by one. This is the principal of parallel communication
protocols.
Parallel though in paper sounds better than serial, in practical situations, since the balls need
to be reordered in their original order, lots of overheads and synchronization issues come up
and serial communication is still fast enough and reliable in most scenarios.

7. Memory
There are 2 types of memory
• Primary memory and
• Secondary memory
Primary memory is volatile and holds data and the source code that is presently being
processed, while the secondary memory is nonvolatile and used to hold constants and the
source code.
You can read about it in more detail in here (also available in the related articles section at
the bottom of the article).

8. Interrupt controllers
Interrupt controllers listen to the peripherals for events and reports to the processor once
an event occurs.
Lets first talk about what interrupts are by considering some real-life examples of interrupts.
• you are sleeping and in the morning the alarm you set goes off and wakes you up (by
interrupting your sleep)
• You are reading a book and your phone rings to alert you of a call (by interrupting
your reading session.)
These are 2 examples of day to day interrupts experienced by us humans.
This concept has been ported to embedded systems using special devices called interrupt
controllers. I like thinking of them as event listener peripherals. Their main job is to listen to
the events generated by the other peripherals and report them to the processor.
Examples of events that can produce interrupts include
• GPIO reads 1 or 0
• Timer countdown reached 0
• Serial communication received a packet of data and
• DMA has completed a transfer
The particular event that we need to listen to can be programmed by us and unnecessary
events can be ignored.
Once a registered event happens, the interrupt controller goes and tells the CPU about it, so
that the CPU can take appropriate action.
For example, consider a simple circuit where one pin is configured as digital input and
another as digital output as shown in the figure.

Here the job of the system is to light up the LED if the button is pressed. We can write code
to achieve this functionality in 2 ways.
Polling
This first method is that we continuously see if the button is being pressed and once it is,
then we turn ON the LED. This approach of doing things is also called polling. The code
snippet below shows how to implement this method.

This is analogous to look at the clock all night and getting out of the bed as soon as its 6 AM
and turns on the light! So we wasted the entire night without sleeping and wasted a lot of
energy, which is a very inefficient way of doing it!
Interrupts
Instead, the better way to do it is to go ahead with our sleep and just set an
alarm(/interrupt) to wake us up at 6 AM.
On the microcontrollers, we can accomplish this by setting up the interrupt controller to tell
the CPU that the button has been pressed.
The interrupt controller then listens to the button press on the GPIO input pin and once the
button is pressed, it wakes up the microcontroller and executes a function that turns the LED
on for us. Once the LED is ON, the CPU gets to go back to sleep. (unlike us who need to get
to work!)
This method has an energy-efficient implementation since the CPU is sleeping most of the
time.
But you may ask, what about the interrupt controller, won’t is waste energy by seeing if the
button is pressed or not 24/7? The answer to that question is yes the interrupt controller will
consume some power, but CPU can consume 100’s of times more energy than a typical
interrupt controller.
This mechanism of doing things is called interrupts.
The code snippet shown below shows the implementation of interrupts to achieve the same
result.

Here in the main function, as soon as everything is initialized, the CPU goes to sleep and only
wakes up when the interrupt controller sees a button press or button release event.
As you can see, the code looks more complicated once interrupts came into the picture, but
even setting up your alarm needs extra work, that does not mean it is the best way of getting
a good night’s sleep!
So whenever there is an opportunity, its good practice to use interrupts instead of polling.
(when laziness to implement more code kicks in, just remember the sleep and alarm
analogy!)
Interrupt vector table
In the above example, if button1 is pressed then LED1 must be lit and if button1 is released
then LED1 must be turned off. The CPU needs a way to figure out which ISR should be called
on button press and release. That is there needs to be a mapping between a given Interrupt
request (IRQ) and its Interrupt Service Routine (ISR)
IRQ stands for Interrupt ReQuest and ISR stands for Interrupt Service Routine. These are
just technical names, so don’t stress too much over it. Just remember that the interrupt
controller waking up the CPU is a ReQuest to service an Interrupt. (Or its an IRQ) , the
function that gets executed once IRQ comes is the ISR.
The interrupt vector table is simply a table with 2 columns, column1 contains the interrupt
number (IRQ number) and column2 contains the address of the function to be executed
(ISR) if a given interrupt occurs. Once an interrupt comes (the interrupt number comes in
with the IRQ), the CPU simply checks this table to get the address of the ISR and then it goes
and runs the appropriate code.
In the previous example, we had 2 IRQs: Button_pressed and Button_released, connected to
2 ISRs: LED_ON_ISR and LED_OFF_ISR respectively.

9. Direct Memory Access Controller


The 3 main types of operations a microprocessor perform include arithmetic operations,
logical operations and data move operations. By data move operations I mean transferring
data from one memory location to another, for example from UART buffer to the RAM and
vice versa.
Imagine you own a courier company and you hire an awesome programmer for 100 bucks
per hour. His main job includes, of course, creating awesome code for your courier website.
But he is getting constantly interrupted by customers coming in all day with parcels, and he
is wasting his time collecting those parcels and keep them in storage for transport later. So
you decide to hire another person, for say, 20 bucks/hour to take care of these simple parcel
reception duties, while your awesome programmer can focus on the job he is good at, this
way your overall productivity will increase immensely and so will your revenue!
This analogy is perfect for describing DMA. Here the microprocessor is your awesome
programmer, the customer coming in is say UART interrupts to the microprocessor, UART
data is the parcels and the second person hired is the DMA controller.
If a given application deals with large amounts of data transfer then all of the precious
microprocessors time will go on these data transfers, which will result in a very inefficient
process both in terms of power consumption and execution times. Hence it’s a good idea to
transfer the data moving responsibilities to a special device called the DMA controller, while
the processor can carry on doing it’s more intensive math operations!
These are the 9 essential microcontroller peripherals that you will probably come across very
frequently as an embedded engineer or a hobbyist. Having a good understanding of them is
very important as you can have a good overview of what’s possible and what’s not with your
hardware. This way you can pick the right microcontroller for a given application.
AVR I/O Port Programming
https://www.javatpoint.com/avr-input-output-port-programming
In AVR microcontroller family, there are many ports available for I/O operations, depending
on which family microcontroller you choose. For the ATmega32 40-pin chip 32 Pins are
available for I/O operation. The four ports PORTA, PORTB, PORTC, and PORTD are
programmed for performing desired operation.
The Pin diagram of ATmega32 microcontroller is shown below:

The number of ports in AVR family varies depending on number of pins available on chip.
The 8-pin AVR has port B only, while the 64-pin version has ports A to ports F, and the 100-
pin AVR has ports A to ports L.
The table showing Numbers of ports in some AVR family members is shown below:
Note: X indicates that the port is available.
The 40-pin AVR has four ports for using any of the ports as an input or output port, it must
be accordingly programmed. In AVR microcontroller not all ports have 8 pins. For example:-
in the ATmega8, Port C has 7 pins.
The Registers Addresses for ATmega32 Ports is given below:

Each port in AVR microcontroller has three I/O registers associated with it. They are
designated as PORTx, DDRx and PINx. For example: - in case of Port B we have PORTB, DDRB,
and PINB. Here DDR stands for Data Direction Registers, and PIN stands for Port Input pins.
Each of I/O registers is 8 bits wide, and each port has a maximum of 8 pins, therefore each
bit of I/O registers affects one of the pins.
For accessing I/O registers associated with the ports the common relationship between the
registers and the pins of AVR microcontroller is used.
The relation between the Registers and the Pins of AVR is shown below:
Part 4: Interfacing of Keypad with programming (Keypad Interfacing)
A matrix keypad is nothing but a systematic arrangement of buttons in horizontal and vertical
fashion. For example, a 4×4 Keypad consists of 16 keys or buttons that are arranged in 4 Rows and 4
Columns. The following image shows a typical Button Type 4×4 Matrix Keypad.

There are two types of matrix keypads available today. One is the traditional Button type Keypad as
shown in the image above while the other is a Membrane type Keypad, which doesn’t contain any
buttons but works due to electrical contact between surface of the key and the underlying circuit.

What does a 4x4 membrane keypad do?

The specific use of a 4 x 4 membrane keypad can vary depending on the application. For example, it
could be used for numeric or alphanumeric data entry, menu navigation, or as a simple control
interface for a device. Its compact size and low cost make it a popular choice for many applications
where a small and simple input device is needed.

How does a Membrane Keypad work?

When a button is pressed on a membrane keypad, it completes an electrical circuit and sends a signal
to the microcontroller. The microcontroller is a computer chip that processes the input from the
buttons and determines which key has been pressed.

All rows and columns in the keypad are wired together in order to reduce the number of i/o pins.
Normally connecting 16 push buttons like that would require 17 I/O pins. 16 for push buttons and 1
for ground.

By connecting rows and columns together only 8 pins are required. this specific technique is called
as multiplexing.

The 4x4 keypad has 4 rows and 4 columns so it has total of 4+4 =8 output pins

Assume all the rows of the Keypad are made LOW and all the columns of the Keypad are made HIGH
by the Microcontroller. When no button or key is pressed, this will be the default status of the rows
and columns.
Now, when a key is pressed, the corresponding column will become LOW as the current flows from
HIGH Column Pin to LOW Row Pin. The Microcontroller (or Arduino) can easily identify the Column of
the Key just by scanning for LOW on Columns.

The trick part comes in identifying the Row of the Key. For this, the Microcontroller should make the
Rows of the keypad HIGH, one-by-one and check for the Column Pins to become HIGH. This
procedure is continued till the earlier detected Column becomes HIGH.

This way, the microcontroller can determine both the Column and the Row of the Key and hence the
Key pressed is identified.

Circuit Diagram

In this circuit, I’ve connected the Rows of the keypad to the Digital Pins 0 through 3 of the Arduino
i.e. ROW1 to Digital Pin 0, ROW2 to Digital Pin 1, ROW3 to Digital Pin 2 and ROW4 to Digital Pin 3.
Similarly, the Columns of the Keypad are connected to Digital Pins 4 through 7 of Arduino.
Components Required

• Arduino UNO
• 16×2 LCD Display
• 4×4 Matrix Keypad
• 10KΩ Potentiometer
• 1KΩ Resistor (1/4 Watt)
• Breadboard
• Connecting Wires
• Power Supply

Circuit Design

The circuit design of the project is very similar to the Arduino Keypad interface shown above. The
additional component is the 16×2 LCD Display. The data pins of the LCD are connected to Digital Pins
11 through 8. The E and RS Pins of the 16×2 LCD Display are connected to Pins 12 and 13 of Arduino.

Code
Part 6: Interfacing of DC motor with programming
DC motor converts electrical energy in the form of Direct Current into mechanical energy in the form
of rotational motion of the motor shaft.

The DC motor speed can be controlled by applying varying DC voltage; whereas the direction of
rotation of the motor can be changed by reversing the direction of current through it.

A DC motor (Direct Current motor) is the most common type of motor. DC motors normally have just
two leads, one positive and one negative. If you connect these two leads directly to a battery, the
motor will rotate. If you switch the leads, the motor will rotate in the opposite direction.

Do not drive the motor directly from Arduino board pins. This may damage the board. Use a driver
Circuit or an IC.

Components Required −

• 1x Arduino UNO board


• 1x PN2222 Transistor
• 1x Small 6V DC Motor (L293D)
• 1x 1N4001 diode
• 1x 270 Ω Resistor
(A) Spinning of Motor

Circuit Diagram

Spin Control Arduino Code


Code to Note
The transistor acts like a switch, controlling the power to the motor. Arduino pin 3 is used to
turn the transistor on and off and is given the name 'motorPin' in the sketch.

Result
Motor will spin in full speed when the Arduino pin number 3 goes high.

(B) Controlling Motor Speed (L293D)

Schematic diagram of a DC motor

Main Arduino Code


Code to Note
The transistor acts like a switch, controlling the power of the motor. Arduino pin 3 is used to
turn the transistor on and off and is given the name 'motorPin' in the sketch.
When the program starts, it prompts you to give the values to control the speed of the
motor. You need to enter a value between 0 and 255 in the Serial Monitor.

In the 'loop' function, the command 'Serial.parseInt' is used to read the number entered as
text in the Serial Monitor and convert it into an 'int'. You can type any number here. The 'if'
statement in the next line simply does an analog write with this number, if the number is
between 0 and 255.

Result
The DC motor will spin with different speeds according to the value (0 to 250) received via
the serial port.

(C) Controlling the direction of spinning motor


To control the direction of the spin of DC motor, without interchanging the leads, you can use
a circuit called an H-Bridge. An H-bridge is an electronic circuit that can drive the motor in
both directions. H-bridges are used in many different applications. One of the most common
application is to control motors in robots. It is called an H-bridge because it uses four
transistors connected in such a way that the schematic diagram looks like an "H."
The L298 bridge IC can control the speed and direction of DC motors and stepper motors,
and can control two motors simultaneously. Its current rating is 2A for each motor.

Pin IN1 of the IC L298 is connected to pin 8 of Arduino while IN2 is connected to pin 9. These
two digital pins of Arduino control the direction of the motor. The EN A pin of IC is connected
to the PWM pin 2 of Arduino. This will control the speed of the motor.
Complete Arduino Code

Result

The motor will run first in the clockwise (CW) direction for 3 seconds and then counter-clockwise
(CCW) for 3 seconds.

Part 7: Interfacing of 16x2 LCD with programming


LCDs (Liquid Crystal Displays) are used in embedded system applications for displaying various
parameters and status of the system.

LCD 16x2 is a 16-pin device that has 2 rows that can accommodate 16 characters each.

LCD 16x2 can be used in 4-bit mode or 8-bit mode.


It is also possible to create custom characters.

It has 8 data lines and 3 control lines that can be used for control purposes.

For more information about LCD 16x2 and how to use it, refer the topic LCD 16x2 module in the
sensors and modules section.

The LCDs have a parallel interface, meaning that the microcontroller has to manipulate several
interface pins at once to control the display. The interface consists of the following pins:

• A register select (RS) pin that controls where in the LCD's memory you're writing data to. You
can select either the data register, which holds what goes on the screen, or an instruction
register, which is where the LCD's controller looks for instructions on what to do next.

• A Read/Write (R/W) pin that selects reading mode or writing mode

• An Enable pin that enables writing to the registers

• 8 data pins (D0 -D7). The states of these pins (high or low) are the bits that you're writing to
a register when you write, or the values you're reading when you read.

There's also a display contrast pin (Vo), power supply pins (+5V and GND) and LED Backlight (Bklt+
and BKlt-) pins that you can use to power the LCD, control the display contrast, and turn on and off
the LED backlight, respectively.

Components Required

• Arduino Board
• LCD Screen (compatible with Hitachi HD44780 driver)
• pin headers to solder to the LCD display pins
• 10k ohm potentiometer
• 220 ohm resistor
• hook-up wires
• breadboard

Schematic diagram of the circuit

The schematic (made using Fritzing).

CODE for Hello World Example

This example sketch prints Hello World! to the LCD and shows the time in seconds since the Arduino
was reset.

/*
LiquidCrystal Library - Hello World
Demonstrates the use a 16x2 LCD display. The LiquidCrystal library works with all LCD
displays that are compatible with the Hitachi HD44780 driver. There are many of them out
there, and you can usually tell them by the 16-pin interface.
This sketch prints "Hello World!" to the LCD and shows the time.
The circuit is as follows:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* LCD VSS pin to ground
* LCD VCC pin to 5V
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
https://docs.arduino.cc/learn/electronics/lcd-displays
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library by associating any needed LCD interface pin with the arduino pin
number it is connected to
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {
lcd.init();
lcd.clear();
lcd.backlight(); // make sure backlight is on
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// Print a message of both the line of the LCD.
lcd.setCursor(3,0); //Set cursor to character 2 on line 0
lcd.print("Hello World!");
lcd.setCursor(5,1); //Move cursor to character 2 on line 1
lcd.print("LCD_I2C");
}

void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print(millis() / 1000);
}
UNIT 5: Embedded system Applications (Arduino)

Part 1: Functional blocks of Line follower Robot using Arduino


• Line follower Robot is a very simple robot that follows a line, either a black line or a white line.

• Basically, there are two types of line follower robots: one is a black line follower which follows the
black line and the second is a white line follower which follows the white line.

Concepts of Line Follower

• The concept of working of a line follower is related to light. We use here the behaviour of light on
the black and white surfaces. When light falls on a white surface it is almost fully reflected and in the
case of a black surface, light is completely absorbed. This behaviour of light is used in building a line
follower robot.

In this Arduino based line follower robot, we have used IR Transmitters and IR receivers also called
photodiodes. They are used for sending and receiving light. IR transmits infrared lights. When
infrared rays falls on the white surface, it’s reflected back and caught by photodiodes which generate
some voltage changes. When IR light falls on a black surface, light is absorbed by the black surface
and no rays are reflected back, thus photo diode does not receive any light or rays.

Circuit Explanation

The whole Arduino line follower robot can be divided into 3 sections: sensor section, a control
section, and driver section.

Sensor section:

This section contains IR diodes, potentiometer, Comparator (Op-Amp) and LED’s. The potentiometer
is used for setting reference voltage at comparator’s one terminal and IR sensors are used to sense
the line and provide a change in voltage at the comparator’s second terminal. Then the comparator
compares both voltages and generates a digital signal at the output. Here in this line follower
circuit, we have used two comparators for two sensors. LM 358 is used as a comparator. LM358 has
inbuilt two low noise Op-amps.
Control Section:

Arduino Pro Mini is used for controlling the whole the process of the line follower robot. The outputs
of comparators are connected to digital pin numbers 2 and 3 of Arduino. Arduino read these signals
and send commands to driver circuit to driveline follower.

Driver section:

The driver section consists of motor driver and two DC motors. The motor driver is used for driving
motors because Arduino does not supply enough voltage and current to the motor. So we add a
motor driver circuit to get enough voltage and current for the motor. Arduino sends commands to
this motor driver and then it drives motors.

Working of Line Follower Robot using Arduino

Building a Line follower robot using Arduino is interesting. The line follower robot senses a black line
by using a sensor and then sends the signal to Arduino. Then Arduino drives the motor according to
sensors' output.

PROGRAM

Program Explanation
There are four conditions in this line following robot that we read by using Arduino. We have used
two sensors namely the left sensor and the right sensor.

Input Output Movement

Left Sensor Right Sensor Left Motor Right Motor Of Robot

LS RS LM1 LM2 RM1 RM2

0 0 0 0 0 0 Stop

0 1 1 0 0 0 Turn Right

1 0 0 0 1 0 Turn Left

1 1 1 0 1 0 Forward

We write the arduino line follower code according to the conditions shown in table above.
/*------ Arduino Line Follower Code----- */

/*-------defining Inputs------*/

#define LS 2 // left sensor

#define RS 3 // right sensor

/*-------defining Outputs------*/

#define LM1 4 // left motor

#define LM2 5 // left motor

#define RM1 6 // right motor

#define RM2 7 // right motor

void setup()

pinMode(LS, INPUT);

pinMode(RS, INPUT);

pinMode(LM1, OUTPUT);

pinMode(LM2, OUTPUT);

pinMode(RM1, OUTPUT);

pinMode(RM2, OUTPUT);

void loop()

if(digitalRead(LS) && digitalRead(RS)) // Move Forward

digitalWrite(LM1, HIGH);

digitalWrite(LM2, LOW);

digitalWrite(RM1, HIGH);

digitalWrite(RM2, LOW);

if(!(digitalRead(LS)) && digitalRead(RS)) // Turn right


{

digitalWrite(LM1, LOW);

digitalWrite(LM2, LOW);

digitalWrite(RM1, HIGH);

digitalWrite(RM2, LOW);

if(digitalRead(LS) && !(digitalRead(RS))) // turn left

digitalWrite(LM1, HIGH);

digitalWrite(LM2, LOW);

digitalWrite(RM1, LOW);

digitalWrite(RM2, LOW);

if(!(digitalRead(LS)) && !(digitalRead(RS))) // stop

digitalWrite(LM1, LOW);

digitalWrite(LM2, LOW);

digitalWrite(RM1, LOW);

digitalWrite(RM2, LOW);

}
Part 2: Functional blocks of accelerometer based gesture control robot
Accelerometer

An accelerometer is a one type of sensor and it gives an analog data while moving in the direction of
X, Y and Z. These directions depend on the type of sensor. The diagram of accelerometer is shown
below. This sensor consists of arrow directions, if we tilt the sensor in one direction, then the data at
the particular pin will change in the form of analog. The accelerometer consists of six pins, where the
function of each pin is discussed below.

• Pin-1: VDD pin is used to give +5V supply to this pin

• Pin-2: GND pin is connected to the ground for the purpose of biasing

• Pin-3: X pin will receive the data in the X direction

• Pin-4: Y pin will receive the data in the Y direction

• Pin-5: Z pin will receive the data in the Z direction

• Pin-6: ST pin is used to adjust the sensitivity of the accelerometer 1.5g or 2g or 3g or 4g

Comparator The comparator is used to change the analog voltage into digital voltage and compares
that analog voltage to a reference voltage and give a precise low voltage or high voltage

Encoder This encoder is used to encode the 4-bit data and transmits by using an RF transmitter
module.

RF Transmitter Module The RF TX module works with 433MHz frequency and this module is easily
available in the market with low cost.

Transmitter Section

The major components used in the receiving section include receiver, decoder, microcontroller and
motor driver.
RF Receiver The RF receiver of this project will receive the data which is transferred by the
transmitting device.

Decoder The decoder is used to change the serial data into parallel data which is received from the
RF receiver module.

Microcontroller The microcontroller is the most essential part of the robot. A 8051 family
microcontroller is used in the circuit to give a decision capacity

Motor Driver The motor driver is a device which gives the movement to do a task like a motor. So we
require motor driver to run them through the controller. The interface between motor &
microcontroller can be done using an L293D motor driver IC in this circuit.

At the receiver section, an RF receiver module receives the data from the transmitter. The received
data can be decoded by an IC HT12D. The received data can be processed by AT89S51
microcontroller and motor driver is used to control the motor.

Receiver Section

Working

Gesture controlled robot moves according to hand movement as we place transmitter in our
hand. When we tilt hand in front side, robot start to moving forward and continues moving forward
until next command is given.

When we tilt hand in backward side, robot change its state and start moving in backwards direction
until other command is given.

When we tilt it in left side Robot get turn left till next command.

When we tilt hand in right side robot turned to right.

And for stopping robot we keep hand in stable.


PROGRAM

There are total five conditions for this Gesture controlled Robot which are giving below:

Movement of Input for Arduino from


hand gesture

Side D3 D2 D1 D0 Direction

Stable 0 0 0 0 Stop

Tilt right 0 0 0 1 Turn Right

Tilt left 0 0 1 0 Turn Left

Tilt back 1 0 0 0 Backward

Tilt front 0 1 0 0 Forward

We have written the complete program according to the above table conditions. Below is the
complete code.

#define FD 16

#define BD 17

#define LD 18

#define RD 19

#define m11 3

#define m12 4

#define m21 5

#define m22 6

void forward()

digitalWrite(m11, HIGH);

digitalWrite(m12, LOW);

digitalWrite(m21, HIGH);

digitalWrite(m22, LOW);
}

void backward()

digitalWrite(m11, LOW);

digitalWrite(m12, HIGH);

digitalWrite(m21, LOW);

digitalWrite(m22, HIGH);

void left()

digitalWrite(m11, HIGH);

digitalWrite(m12, LOW);

digitalWrite(m21, LOW);

digitalWrite(m22, LOW);

void right()

digitalWrite(m11, LOW);

digitalWrite(m12, LOW);

digitalWrite(m21, HIGH);

digitalWrite(m22, LOW);

void Stop()

digitalWrite(m11, LOW);

digitalWrite(m12, LOW);

digitalWrite(m21, LOW);

digitalWrite(m22, LOW);

}
void setup()

pinMode(FD, INPUT);

pinMode(BD, INPUT);

pinMode(LD, INPUT);

pinMode(RD, INPUT);

pinMode(m11, OUTPUT);

pinMode(m12, OUTPUT);

pinMode(m21, OUTPUT);

pinMode(m22, OUTPUT);

void loop()

int temp1=digitalRead(FD);

int temp2=digitalRead(BD);

int temp3=digitalRead(LD);

int temp4=digitalRead(RD);

if(temp1==1 && temp2==0 && temp3==0 && temp4==0)

backward();

else if(temp1==0 && temp2==1 && temp3==0 && temp4==0)

forward();

else if(temp1==0 && temp2==0 && temp3==1 && temp4==0)

left();

else if(temp1==0 && temp2==0 && temp3==0 && temp4==1)

right();

else

Stop();

}
Part 3: Functional blocks of home automation using RF control.
Home automation

Home automation is constructing automation for a domestic, mentioned as a sensible home or smart
house. In the IoT home automation ecosystem, you can control your devices like light, fan, TV, etc. A
domestic automation system can monitor and/or manage home attributes lighting, climate,
entertainment systems, and appliances. It is very helpful to control your home devices home
automation systems typically involve the use of smart devices, such as thermostats, light bulbs, and
security cameras, that can be controlled and monitored through an app.
Circuit Design

The design of the circuit is explained with respect to transmitter section and receiver section
individually.

Note: We need to be extremely careful when connecting AC Mains supply to the relay board.
To understand the code of this
GOTO https://www.electronicshub.org/arduino-rf-home-automation/ (not needed)
ARDUINO CODES
LCD INTERFACING
• /*
• LiquidCrystal Library - Hello World
• The circuit:
• * LCD RS pin to digital pin 12
• * LCD Enable pin to digital pin 11
• * LCD D4 pin to digital pin 5
• * LCD D5 pin to digitalpin 4
• * LCD D6 pin to digital pin 3
• * LCD D7 pin to digital pin 2
• * LCD R/W pin to ground
• * LCD VSS pin to ground
• * LCD VCC pin to 5V
• * 10K resistor:
• * ends to +5V and ground
• * wiper to LCD VO pin (pin 3)
• */

• // include the library code:
• #include <LiquidCrystal.h>

• // initialize the library by associating any needed LCD interface pin
• // with the arduino pin number it is connected to
• const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
• LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

• void setup() {
• // set up the LCD's number of columns and rows:
• lcd.begin(16, 2);
• // Print a message on both lines of the LCD.
• lcd.setCursor(2,0); //Set cursor to character 2 on line 0
• lcd.print("Hello World!");

• lcd.setCursor(4,1); //Move cursor to character 2 on line 1
• lcd.print("LCD_I2C");
• }

• void loop() {
• }
LCD INTERFACING USING I2C
• #include <LiquidCrystal_I2C.h>

• LiquidCrystal_I2C lcd(0x27,16,2); // set the LCD address to 0x27 for a 16 chars and 2 line display

• void setup() {
• lcd.init();
• lcd.clear();
• //lcd.backlight(); // Make sure backlight is on3

• // Print a message on both lines of the LCD.
• lcd.setCursor(3,0); //Set cursor to character 2 on line 0
• lcd.print("Hello World!");

• lcd.setCursor(5,1); //Move cursor to character 2 on line 1
• lcd.print("LCD_I2C");
• }

• void loop() {
• }
KEYPAD INTERFACING
KEYPAD INTERFACING (SWITCH CASE)
• #include
• const byte ROWS = 4; // Four rows
• const byte COLS = 3; // Three columns
• // Define the Keymap
• char keys[ROWS][COLS] = { {'1','2','3'}, {'4','5','6'}, {'7','8','9'}, {'#','0','*'} };
• // Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
• byte rowPins[ROWS] = { 9, 8, 7, 6 };
• // Connect keypad COL0, COL1 and COL2 to these Arduino pins.
• byte colPins[COLS] = { 12, 11, 10 };
• // Create the Keypad Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
• #define ledpin 13
• void setup()
• {
• pinMode(ledpin,OUTPUT);
• digitalWrite(ledpin, HIGH);
• Serial.begin(9600);
• }
• void loop()
• {
• char key = kpd.getKey();
• if(key) // Check for a valid key.
• {
• switch (key)
• {
• case '1':
• Serial.println(key);
• break;
• case '2':
• Serial.println(key);
• break;
• case '3':
• Serial.println(key);
• break;
• case '4':
• Serial.println(key);
• break;
• case '5':
• Serial.println(key);
• break;
• case '6':
• Serial.println(key);
• break;
• case '7':
• Serial.println(key);
• break;
• case '8':
• Serial.println(key);
• break;
• case '9':
• Serial.println(key);
• break;
• case '0':
• Serial.println(key);
• break;
• case '*':
• Serial.println(key);
• break;
• case '#':
• Serial.println(key);
• break;
• }
• } https://www.instructables.com/interface-keypad-with-arduino/
• }
DC motor INTERFACING
• A DC motor (Direct Current motor) is the most
common type of motor. DC motors normally
have just two leads, one positive and one
negative. If you connect these two leads
directly to a battery, the motor will rotate. If
you switch the leads, the motor will rotate in
the opposite direction.

https://www.tutorialspoint.com/arduino/arduino_dc_motor.htm
• Do not drive the motor directly from Arduino board pins.
This may damage the board. Use a driver Circuit or an IC.
We will divide this chapter into three parts −
• Just make your motor spin
• Control motor speed
• Control the direction of the spin of DC motor
• Components Required
• 1x Arduino UNO board
• 1x PN2222 Transistor
• 1x Small 6V DC Motor
• 1x 1N4001 diode
• 1x 270 Ω Resistor
circuit diagram
Precautions
Take the following precautions while making the
connections.
First, make sure that the transistor is connected in the
right way. The flat side of the transistor should face the
Arduino board as shown in the arrangement.
Second, the striped end of the diode should be
towards the +5V power line according to the
arrangement shown in the image.
Spin ControlArduino Code

• int motorPin = 3;
• void setup()
• {}
• void loop()
• { digitalWrite(motorPin, HIGH);
• }
• The transistor acts like a switch, controlling the power to
the motor. Arduino pin 3 is used to turn the transistor on
and off and is given the name 'motorPin' in the sketch.
• Result
• Motor will spin in full speed when the Arduino pin number
3 goes high.
Motor Speed Control
• Code
• The transistor acts like a switch, controlling the power of the motor.
Arduino pin 3 is used to turn the transistor on and off and is given
the name 'motorPin' in the sketch.
• When the program starts, it prompts you to give the values to
control the speed of the motor. You need to enter a value between
0 and 255 in the Serial Monitor.
• In the 'loop' function, the command 'Serial.parseInt' is used to read
the number entered as text in the Serial Monitor and convert it into
an 'int'. You can type any number here. The 'if' statement in the
next line simply does an analog write with this number, if the
number is between 0 and 255.
• Result
• The DC motor will spin with different speeds according to the value
(0 to 250) received via the serial port.
Motor Speed Control

• int motorPin = 9;
• void setup() { pinMode(motorPin, OUTPUT);
Serial.begin(9600);
• while (! Serial);
• Serial.println("Speed 0 to 255");
• } void loop() { if (Serial.available()) { int speed =
Serial.parseInt();
• if (speed >= 0 && speed <= 255) {
analogWrite(motorPin, speed);
• }}}

You might also like