AMC Notes
AMC Notes
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.
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
It has Hardware
Low or no resource
Constraint constraint Size, power, cost, memory, real time
4.Distributed
6.Power concerns
1. Application and domain specific
• 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.
• 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
• 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.
• 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
• 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
• 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.
• 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
• The production of high amount of heat demands cooling requirements like cooling fans which in
turn occupies additional space and make the system bulky.
• The more the power consumption the less is the battery life.
Quality attributes of ES
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.
Real-Time Systems
2. Hard real-time embedded system: strictly time-bound operation is necessary for a successful
output, ex: traffic light control.
Stand-Alone Systems
▪ Less complex
Network Systems
Mobile Systems
▪ Hardware and software complexity is very low due to the small size of microcontrollers
▪ Ex: robotic arm controller, electronic toys, automatic coffee vending machines, thermometer.
Sophisticated Systems
▪ 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.
• 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.
• 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.
• Improved Security: Embedded systems can be designed with built-in security features, such
as encryption and authentication, to protect against cyber attacks and unauthorized access.
While embedded systems offer several advantages, there are also some potential disadvantages,
including:
• Limited Functionality: Embedded systems are designed to perform specific tasks and are
often limited in their functionality. They may not be suitable for applications that require
more complex or varied tasks.
• Limited Upgradability: Embedded systems are often designed with limited upgradability,
which can be a disadvantage in applications where future upgrades or modifications may be
required.
• Limited Connectivity: Some embedded systems may have limited connectivity options,
which can limit their ability to communicate with other devices or systems.
• Difficult to Debug: Embedded systems can be difficult to debug and diagnose when issues
arise, which can be a disadvantage in applications where system downtime is critical.
• 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
The following table highlights all the important differences between microprocessors and
microcontrollers −
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.
• An embedded processor is used when fast processing fast context-switching & atomic ALU
operations are needed.
• DSP has large number of applications such as image processing, audio, video &
telecommunication processing systems.
• 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.
• An ASSP is used as an additional processing unit for running the application in place of using
embedded software.
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
• Synchronous Serial Communication Interface: I2C, JTAG, SPI, SSC and ESSI
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.
• Power efficient
• Real-time operation
• cellphones
• electric vehicles
• Arduino-based devices
There are various types of Embedded operating systems. Some of them are as follows:
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.
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.
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.
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.
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
• 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.
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.
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.
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
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.
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.
Linux works on two interfaces only with limited memory space: LED and serial ports.
• Linux is an independent platform.
• 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.
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
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.
• Android is an obvious option for any touch screen product for its rich UI interface.
• 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.
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 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.
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:-
2. MOV P0, A; (Port 0 all pin have 1's so that it work as Input)
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:-
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:-
3. BACK:
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.6 and P3.7 are Write (WR) and Read (RD) pins.
Let's see the Port 3 table showing an individual pin function:
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.
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
JBC bit, target Jump to target if bit = 1, clear bit (jump if bit, then clear)
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.
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.
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.
1. GPIO controllers
GPIO stands for General Purpose Input and Output. These refer to the pins that are coming
out of the microcontroller SoC.
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.
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
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)
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.
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.
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.
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 −
Circuit Diagram
Result
Motor will spin in full speed when the Arduino pin number 3 goes high.
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.
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.
LCD 16x2 is a 16-pin device that has 2 rows that can accommodate 16 characters each.
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.
• 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
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)
• 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.
• 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.
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.
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------*/
/*-------defining Outputs------*/
void setup()
pinMode(LS, INPUT);
pinMode(RS, INPUT);
pinMode(LM1, OUTPUT);
pinMode(LM2, OUTPUT);
pinMode(RM1, OUTPUT);
pinMode(RM2, OUTPUT);
void loop()
digitalWrite(LM1, HIGH);
digitalWrite(LM2, LOW);
digitalWrite(RM1, HIGH);
digitalWrite(RM2, LOW);
digitalWrite(LM1, LOW);
digitalWrite(LM2, LOW);
digitalWrite(RM1, HIGH);
digitalWrite(RM2, LOW);
digitalWrite(LM1, HIGH);
digitalWrite(LM2, LOW);
digitalWrite(RM1, LOW);
digitalWrite(RM2, LOW);
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-2: GND pin is connected to the ground for the purpose of biasing
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.
There are total five conditions for this Gesture controlled Robot which are giving below:
Side D3 D2 D1 D0 Direction
Stable 0 0 0 0 Stop
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);
backward();
forward();
left();
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);
• }}}