Circuit Design Simulation Quick Start
Circuit Design Simulation Quick Start
I N N O VAT I O N S
SERIES
Circuit Design
and Simulation
Quick Start
Guide
Create Schematics and Layout
Electronic Components
—
Ashraf Said Ahmad AlMadhoun
Maker Innovations Series
Jump start your path to discovery with the Apress Maker Innovations
series! From the basics of electricity and components through to the most
advanced options in robotics and Machine Learning, you’ll forge a path to
building ingenious hardware and controlling it with cutting-edge software.
All while gaining new skills and experience with common toolsets you can
take to new projects or even into a whole new career.
Chapter 1: Microcontroller�������������������������������������������������������������������1
Introduction�����������������������������������������������������������������������������������������������������������1
Embedded Microcontroller������������������������������������������������������������������������������������3
Microcontroller and Microprocessor���������������������������������������������������������������������4
More on Microcontrollers and Microprocessors���������������������������������������������������9
Microcontroller: The Silent Commanders��������������������������������������������������������9
Microprocessor: The Computational Powerhouses���������������������������������������10
Symbiosis and Distinction�����������������������������������������������������������������������������11
Microcontroller and Microprocessor Comparison�����������������������������������������������12
Central Processing Unit���������������������������������������������������������������������������������������13
Machine Cycle�����������������������������������������������������������������������������������������������������14
Fetching Instruction and Its Execution����������������������������������������������������������������16
Address, Data, and Control: The Buses���������������������������������������������������������������18
Control and Monitoring Devices��������������������������������������������������������������������������20
Control Devices���������������������������������������������������������������������������������������������21
Monitoring Devices����������������������������������������������������������������������������������������21
Integration and Connectivity��������������������������������������������������������������������������22
Challenges and Considerations���������������������������������������������������������������������22
Control Devices���������������������������������������������������������������������������������������������23
v
Table of Contents
Monitoring Devices����������������������������������������������������������������������������������������24
Integration and Connectivity��������������������������������������������������������������������������24
Challenges and Considerations���������������������������������������������������������������������25
Future Prospects�������������������������������������������������������������������������������������������26
Microcontroller Types������������������������������������������������������������������������������������������26
Microcontroller: 8 Bit������������������������������������������������������������������������������������������27
Microcontroller: 16 Bit����������������������������������������������������������������������������������������29
Microcontroller: 32 Bit����������������������������������������������������������������������������������������30
Embedded Microcontroller����������������������������������������������������������������������������������32
Microcontroller with External Memory���������������������������������������������������������������34
The Architectural Specifications of Microcontroller��������������������������������������������35
Von Neumann Architecture���������������������������������������������������������������������������������37
Harvard Architecture�������������������������������������������������������������������������������������������39
Basic Principles���������������������������������������������������������������������������������������������40
Key Characteristics����������������������������������������������������������������������������������������40
Advantages����������������������������������������������������������������������������������������������������41
Applications���������������������������������������������������������������������������������������������������41
CISC (Complex Instruction Set Computer) Architecture for Microcontroller��������42
Key Characteristics and Features������������������������������������������������������������������44
Advantages of CISC Architecture for Microcontrollers����������������������������������45
Challenges and Considerations���������������������������������������������������������������������46
RISC (Reduced Instruction Set Computer) Architecture for Microcontroller�������47
SISC (Specific Instruction Set Computer) Architecture for Microcontroller���������50
Applications of Microcontrollers�������������������������������������������������������������������������51
vi
Table of Contents
Chapter 2: Basics�������������������������������������������������������������������������������57
Exporting Design in EAGLE.BRD Format�������������������������������������������������������������62
Exploring Component Manuals���������������������������������������������������������������������������62
Generating a Shareable CSV File������������������������������������������������������������������������65
Interacting with the CSV File�������������������������������������������������������������������������������66
vii
Table of Contents
Index�������������������������������������������������������������������������������������������������177
viii
About the Author
Ashraf Said Ahmad AlMadhoun is an educator, a mechatronics engineer,
an electronics and programming hobbyist, and a maker. He hosts the
popular EduEng YouTube channel and has authored four books on
microcontrollers. As a Chief Educational Engineer since 2007 for the
Educational Engineering Team, a company he founded, Ashraf’s mission
is to explore new trends and technology and help educate the world and
make it a better place. Educational Engineering offers educational courses
and bootcamps, articles, lessons, and online support for electronics
hobbyists, programming hobbyists, microcontroller hobbyists, STEM
students, and teachers. His passion for microcontrollers and programming
and in particular for the world of Arduino, PIC microcontroller, and the
Raspberry Pi has guided his personal development and his work through
Educational Engineering.
ix
About the Technical Reviewer
Massimo Nardone has more than 22 years
of experience in security, web and mobile
development, cloud, and IT architecture. His
true IT passions are security and Android. He
has been programming and teaching how to
program with Android, Perl, PHP, Java, VB,
Python, C/C++, and MySQL for more than
20 years. Massimo also holds a master of
science degree in computing science from the
University of Salerno, Italy. He has worked as
a project manager, software engineer, research engineer, chief security
architect, information security manager, PCI/SCADA auditor, and senior
lead IT security/cloud/SCADA architect for many years. His technical
skills include security, Android, cloud, Java, MySQL, Drupal, Cobol, Perl,
web and mobile development, MongoDB, D3, Joomla, Couchbase, C/C++,
WebGL, Python, Pro Rails, Django CMS, Jekyll, Scratch, etc. Massimo also
worked as visiting lecturer and supervisor for exercises at the Networking
Laboratory of the Helsinki University of Technology (Aalto University). He
holds four international patents (PKI, SIP, SAML, and Proxy areas).
xi
CHAPTER 1
Microcontroller
Introduction
In the vast landscape of technological innovation, microcontrollers emerge
as the unsung champions orchestrating a symphony of digital wonders
that shape our modern lives. These unassuming yet powerful devices have
left an indelible mark on our world, influencing everything from our daily
routines to the intricate machinery that drives industries forward. The
journey of microcontrollers is one of transcending boundaries, seamlessly
blending into the fabric of our existence while simultaneously driving
progress and innovation.
Picture this: You enter a bustling restaurant, the rhythmic clatter of
cutlery and the warm ambience enveloping you. Little do you know that
microcontrollers silently facilitate the swift transactions at the cash register,
ensure the precision of weighing scales, and even manage the ambient lighting
that sets the mood. These ubiquitous data processors quietly synchronize
each element, enhancing your experience without seeking recognition.
In the realm of domestic comfort, microcontrollers continue to weave
their magic. They are the enigmatic brains behind your oven, meticulously
preparing your meals to perfection, and the washer/dryer, expertly
handling your laundry with care. Not to be overlooked, the trusty alarm
clock that gently rouses you from slumber is another creation indebted to
these miniature powerhouses.
2
Chapter 1 Microcontroller
Embedded Microcontroller
An embedded controller is an integral component within a broader
system, playing a crucial role in managing and directing specific
functionalities of the overall device. This specialized computing unit is
intricately woven into the fabric of the device, geared toward executing a
particular function beyond the realm of general-purpose computing. It is
imperative to differentiate between the terms “embedded controller” and
“microcontroller,” as the former encompasses a wider array of computing
entities that extend beyond the latter’s boundaries.
Microcontrollers are a subset of embedded controllers, encompassing
a specific category of computing devices characterized by their
compactness, integration of processing, memory, and input/output
components onto a single chip. While the terms are sometimes used
interchangeably, it’s essential to recognize that not all embedded
controllers fit the microcontroller mold. The 68000, 32032, and x86
are prime examples of embedded controllers that don’t fall under the
microcontroller umbrella due to their larger scale and more versatile
computing capabilities.
The scope of an embedded controller’s responsibilities is impressively
diverse. These controllers oversee an assortment of tasks, ranging from the
intricate regulation of household appliances like microwave ovens to the
intricate management of critical systems such as car braking mechanisms
or even military-grade hardware like cruise missiles. This capacity for
multifaceted control showcases the adaptability of embedded controllers
in responding to vastly different operational requirements.
One common thread shared between microcontrollers and embedded
controllers is their effective utilization of on-chip resources. By capitalizing
on the integrated capabilities of their hardware components, these
controllers streamline their operations, contributing to optimized
performance and efficient resource management. The symbiotic
relationship between hardware and software intricately woven into
3
Chapter 1 Microcontroller
4
Chapter 1 Microcontroller
5
Chapter 1 Microcontroller
6
Chapter 1 Microcontroller
7
Chapter 1 Microcontroller
8
Chapter 1 Microcontroller
More on Microcontrollers
and Microprocessors
Microcontroller: The Silent Commanders
Imagine a device that not only processes data but also interacts with the
physical world, executing a predefined set of tasks with precision and
finesse. Enter the microcontroller, a versatile yet compact computing
marvel that operates as a self-contained system on a chip (SoC). At its core,
a microcontroller encapsulates a central processing unit (CPU), memory,
input/output (I/O) ports, and often other essential peripherals.
Microcontrollers are the architects of embedded systems, orchestrating
a symphony of tasks in devices that span from consumer electronics
to industrial automation. Their design philosophy revolves around
specialization; they are tailored to excel in specific applications, optimizing
power consumption, size, and cost. Microcontrollers are the workhorses
behind the scenes, executing dedicated functions without the need for
external support.
9
Chapter 1 Microcontroller
10
Chapter 1 Microcontroller
11
Chapter 1 Microcontroller
12
Chapter 1 Microcontroller
13
Chapter 1 Microcontroller
Machine Cycle
Embarking upon the journey of executing a command, the processor
traverses a carefully choreographed sequence of phases, each imbued with
its own unique significance. This intricate symphony of computational
activity commences with a poignant first act:
14
Chapter 1 Microcontroller
15
Chapter 1 Microcontroller
With the address in hand and the stage set, the process advances to the
second act:
16
Chapter 1 Microcontroller
17
Chapter 1 Microcontroller
18
Chapter 1 Microcontroller
19
Chapter 1 Microcontroller
20
Chapter 1 Microcontroller
Control Devices
Control devices are designed to influence the behavior of machines,
equipment, or systems according to specific requirements or commands.
They empower users to direct processes, adjust parameters, and initiate
actions. These devices act as the interface through which human input is
translated into actionable commands for machines to execute.
One common example of a control device is the remote control used
to manage televisions, home theaters, and other entertainment systems. It
allows users to change channels, adjust volume, and navigate menus, all
from a comfortable distance. In industrial settings, control panels are used
to oversee manufacturing lines, regulating speed, temperature, and other
critical factors to ensure optimal product quality and efficiency.
Advanced control devices, such as Programmable Logic Controllers
(PLCs), are widely employed in industrial automation. PLCs are
programmable devices that can execute complex sequences of operations
based on input from sensors, switches, and other devices. They enable
real-time adjustments, error detection, and consistent execution of tasks
without human intervention.
Monitoring Devices
Monitoring devices are designed to collect, display, and convey
information about the status, performance, or condition of a system,
process, or environment. They provide critical insights to users, enabling
them to make informed decisions and take appropriate actions based on
real-time data.
Consider environmental monitoring devices, such as weather
stations, which measure temperature, humidity, wind speed, and other
atmospheric conditions. This data is essential for predicting weather
patterns, studying climate trends, and making informed decisions related
to agriculture, construction, and disaster management.
21
Chapter 1 Microcontroller
22
Chapter 1 Microcontroller
Control Devices
Control devices facilitate human intervention in the operation of
machines, equipment, and systems. They can be as simple as switches
and buttons or as complex as advanced industrial controllers. Examples
include
23
Chapter 1 Microcontroller
Monitoring Devices
Monitoring devices gather data from sensors and present it in
a comprehensible format for analysis and decision-making.
Examples include
24
Chapter 1 Microcontroller
25
Chapter 1 Microcontroller
Future Prospects
The future of control and monitoring devices holds promising
developments:
Microcontroller Types
The internal bus width, architecture, memory, and instruction set of
microcontrollers may be used to categorize them. Figure 1-4 shows the
many microcontrollers available.
26
Chapter 1 Microcontroller
Microcontroller: 8 Bit
In the realm of computational orchestration, a pivotal player takes
the stage—the microcontroller—a digital virtuoso designed to
seamlessly execute intricate commands with finesse. Among the ranks
of microcontrollers, an 8-bit microcontroller stands as a remarkable
manifestation of computational prowess, its ALU—an Algebraic Logic
Unit—wielding its arithmetic and logical acumen with remarkable
precision upon 8-bit bytes. This dexterity ensures that operations
unfurl upon a canvas composed of 8 bits, a realm that caters to the fine
granularity of data manipulation.
27
Chapter 1 Microcontroller
28
Chapter 1 Microcontroller
Microcontroller: 16 Bit
Within the realm of digital marvels, the microcontroller emerges as a
virtuoso, its capabilities attuned to the intricate dance of commands
and data. Amidst this array of computational artisans, the 16-bit
microcontroller takes its place as a luminary—a beacon of heightened
precision and computational prowess. The heart of this distinction rests
within its ALU—an Algebraic Logic Unit—a domain where mathematics
and logic converge upon a 16-bit stage, orchestrating a symphony of
actions with an expanded palette of bits.
At the core of the 16-bit microcontroller’s elegance lies its intrinsic
alignment with a word’s magnificence—16 bits of data delicately
interwoven, capable of conveying complexities beyond the scope of their
smaller 8-bit counterparts. These microcontrollers embrace their role
with unparalleled finesse, embracing instructions that beckon the ALU
to embark upon a journey across these 16-bit landscapes, unraveling the
nuances of data and command interaction.
This intrinsic synergy extends beyond mere instruction execution,
weaving itself into the very fabric of the microcontroller’s architecture.
Beneath the surface, a digital thoroughfare stretches—its lanes widened to
accommodate the magnificence of 16 bits. This internal bus, 16 bits wide,
parallels the grandeur of the microcontroller’s word length, facilitating the
fluid passage of data across its intricate network.
Venturing into the annals of microcontroller history, exemplars
rise to the fore, etching the essence of 16-bit microcontrollers into the
very framework of digital evolution. The Intel 8096 series, an emblem of
computational sophistication, exemplifies the heights that can be achieved
with a 16-bit architecture. In parallel, the Motorola MC68HC12 and
MC68332 families cast their legacy upon the sands of time, emblematic of
16-bit excellence that reverberates through the ages.
29
Chapter 1 Microcontroller
Microcontroller: 32 Bit
Within the intricate tapestry of computational ingenuity, a remarkable
archetype emerges—the 32-bit microcontroller—a beacon of
computational might and precision. This titan of digital orchestration
draws its potency from a pivotal source—the Algebraic Logic Unit (ALU)—a
veritable crucible where the magic of 32-bit arithmetic and logical
operations unfurls. In a single instruction, this ALU navigates the expanse of
32 bits, conducting a symphony of calculations with remarkable finesse.
30
Chapter 1 Microcontroller
The defining attribute of the 32-bit microcontroller lies within its very
essence—a 32-bit internal bus width—a digital thoroughfare that mirrors
the grandeur of the ALU’s operations. This widened path stands as a
testament to the microcontroller’s capacity, facilitating the harmonious
flow of data within its circuitry. This internal network becomes the stage
upon which the symphony of computational mastery is enacted—a realm
where bits intermingle, giving rise to nuanced results of unparalleled
complexity.
Embarking upon the annals of microcontroller heritage, certain
luminaries claim their position among the 32-bit elite, etching their
impact upon the continuum of technological advancement. The Intel
80960 family stands as a testament to precision and power, a progenitor
of 32-bit excellence that has shaped the course of computational history.
Meanwhile, the Motorola M683xx and Intel/Atmel 251 families also
grace this pantheon, their very existence a nod to the splendor of 32-bit
architecture.
However, this distinction transcends mere nomenclature—it’s
a metamorphosis of computational might. The leap from 16 bits to
32 bits elevates the microcontroller’s capabilities to unprecedented
heights, facilitating complex operations with remarkable efficiency. The
very architecture of the microcontroller undergoes a transformation,
accommodating the intricacies of 32-bit operations and opening the doors
to a realm where computations occur with breathtaking precision.
In the domain of performance, 32-bit microcontrollers truly
shine, harnessing their expanded bit space to usher in a new era of
computational power. With each instruction executed, the ALU grapples
with a realm of complexity, orchestrating calculations that transcend the
limitations of their predecessors. This heightened computational prowess
propels the microcontroller to new heights, positioning it as a harbinger of
precision, speed, and efficiency.
31
Chapter 1 Microcontroller
Embedded Microcontroller
Embedded microcontrollers emerge as the silent architects of seamless
functionality within the intricate tapestry of embedded systems. These
microcontrollers, residing as minuscule chips, harbor within their confines
a symphony of essential functional components—nurturing the very
essence of embedded systems with finesse and precision. At the heart of
their design lies the harmonious interplay of diverse elements, including
program and data memory, weaving a digital fabric that empowers
embedded systems to flourish.
Central to this paradigm is the notion of integration—a concept
that finds its apex within the microcontroller’s architecture. It is the
embodiment of all necessary functional blocks onto a solitary chip that
renders a microcontroller “embedded.” This self-contained entity assumes
the role of a master conductor, orchestrating the nuanced interactions
that define an embedded system’s capabilities. Among these, the
venerable 8051 microcontroller shines as an exemplar—a testament to the
transformative impact of this embedded architecture.
32
Chapter 1 Microcontroller
33
Chapter 1 Microcontroller
34
Chapter 1 Microcontroller
T he Architectural Specifications
of Microcontroller
Within the intricate tapestry of computational paradigms, the realm of
processors emerges as a pivotal divide—a juncture that delineates the
trajectories of computation. At its core, this division crystallizes into two
luminous archetypes: the Von Neumann, also known as the Princeton
architecture, and the Harvard architecture. These two luminaries, each
with its own constellation of attributes, unfurl a duality that echoes
through the annals of computing history.
The nuances of data and application storage and retrieval become
the touchstones that define this architectural divergence. In the realm
of Von Neumann architecture, a fluid synergy emerges, with data and
applications akin to ephemeral spirits that inhabit a common domain.
Here, the memory reservoir serves as an abode—a repository where both
data and instructions mingle harmoniously. A procession of fetch, decode,
execute, and store unfolds, each step orchestrated within the confines of a
unified memory space.
35
Chapter 1 Microcontroller
36
Chapter 1 Microcontroller
37
Chapter 1 Microcontroller
38
Chapter 1 Microcontroller
Harvard Architecture
Harvard architecture, a fundamental concept in computer architecture,
plays a pivotal role in defining how a computer’s processor interacts with
memory and executes instructions. Named after the Harvard Mark I relay-
based computer from the 1940s, this architecture has evolved over the
years and continues to influence modern computer designs. Let’s delve
into the details of Harvard architecture, its characteristics, advantages, and
applications.
39
Chapter 1 Microcontroller
Basic Principles
Harvard architecture is characterized by its separation of memory for
instructions and data, maintaining distinct pathways for fetching and
processing instructions and data. In this architecture, there are separate
memory units and buses for instruction memory (program memory) and
data memory, ensuring that the processor can simultaneously access both
instruction and data.
Key Characteristics
Separate Memory Spaces: In a Harvard architecture system, instruction
memory and data memory are physically separate. This separation allows
for concurrent access to both instruction and data, improving overall
system efficiency.
Dedicated Buses: Harvard architecture systems employ separate buses
for fetching instructions and reading/writing data. This parallel access
increases throughput and reduces potential bottlenecks.
Instruction Pipelining: The distinct memory paths enable efficient
pipelining, where multiple instructions can be in various stages of
execution simultaneously.
Fixed Instruction Length: Harvard architecture often uses fixed-length
instruction formats, simplifying the decoding process and improving
predictability in instruction fetch and execution.
Performance: The architecture’s parallelism and efficient memory
access contribute to improved performance, making it well-suited for
applications that require high-speed processing.
40
Chapter 1 Microcontroller
Advantages
Faster Throughput: The parallelism offered by Harvard architecture
enables faster execution of instructions, as instructions can be fetched
while data is being processed.
Predictable Timing: The separation of instruction and data memory
simplifies timing analysis, leading to more deterministic execution times.
Reduced Bottlenecks: Dedicated buses for instructions and data
eliminate contention for memory access, reducing potential bottlenecks in
the system.
Higher Performance in Specific Applications: Harvard architecture
is well-suited for applications with heavy instruction access, such as
embedded systems, digital signal processing, and microcontrollers.
Applications
Embedded Systems: Many microcontrollers and digital signal processors
(DSPs) use Harvard architecture due to its efficiency in real-time applications.
Signal Processing: DSPs and multimedia processing units benefit
from Harvard architecture’s ability to simultaneously handle complex
instruction sequences and data manipulation.
Microcontrollers: Low-power microcontrollers often employ Harvard
architecture, optimizing their processing capabilities while minimizing
energy consumption.
Specialized Processors: Harvard architecture is used in specialized
processors for tasks like encryption, graphics processing, and network
packet handling.
In modern implementations, some architectures use a modified
Harvard architecture, where aspects of Von Neumann architecture
(a unified memory for data and instructions) are integrated with the
Harvard approach. This modification can balance the advantages of both
architectures to suit specific requirements.
41
Chapter 1 Microcontroller
42
Chapter 1 Microcontroller
43
Chapter 1 Microcontroller
44
Chapter 1 Microcontroller
45
Chapter 1 Microcontroller
46
Chapter 1 Microcontroller
47
Chapter 1 Microcontroller
48
Chapter 1 Microcontroller
49
Chapter 1 Microcontroller
50
Chapter 1 Microcontroller
Applications of Microcontrollers
In the intricate web of embedded systems, a quintessential element takes
center stage—the microcontroller, a digital maestro that orchestrates a
symphony of functions within these intricate constructs. Within this realm,
a microcontroller isn’t merely a cog in the wheel; it’s the driving force that
empowers home monitoring systems, breathing life into their functionality
and ensuring seamless operation.
Beyond its foundational role in home monitoring, the realm of
microcontrollers extends its grasp across a multitude of domains, each
a canvas for its versatile capabilities. From the automotive sector to
the domain of household appliances—microwave ovens, refrigerators,
televisions, and VCRs—the microcontroller dons myriad roles, weaving a
tapestry of precision and automation. The automobile landscape witnesses
the microcontroller’s prowess in engine control and climate diagnostics,
while the factory floor becomes an arena where microcontrollers orchestrate
operations with finesse. From the realms of instrumentation to the expanse
of aerospace, the microcontroller’s touch is felt—an indelible mark that
transforms ordinary devices into instruments of efficiency and precision.
51
Chapter 1 Microcontroller
52
Chapter 1 Microcontroller
53
Chapter 1 Microcontroller
54
Chapter 1 Microcontroller
55
CHAPTER 2
Basics
Embarking on a comprehensive journey to explore the intricacies of circuit
simulation, we will navigate step by step through the process using the
versatile platform of Tinkercad. Through this detailed guide, you will gain
a profound understanding of initiating the simulation process and delving
into the immersive world of virtual circuits.
Begin by accessing the digital realm of Tinkercad via your web browser.
As the official Tinkercad website, tinkercad.com, loads before you, you’ll
find an array of possibilities awaiting your exploration. To unlock the full
potential of Tinkercad’s circuit simulation capabilities, click the “Sign In”
option, which serves as your gateway to a realm of digital creativity and
hands-on learning.
With your eagerness to delve into circuit simulation, you’ll be
prompted to provide your credentials. Input your registered email address
and the corresponding password associated with your Tinkercad account.
This personalized key grants you access to a world of innovation where you
can engage in immersive circuit simulations.
Upon signing in, the interface of Tinkercad greets you, presenting
an array of options on the left side of the screen. This interface serves as
the launchpad for your circuit simulation journey. Among these options,
find and click “Circuits,” the guiding star that beckons you to explore the
intricate world of circuitry. This is your starting point, your compass to
navigate through the intricacies of circuit simulations.
58
Chapter 2 Basics
59
Chapter 2 Basics
60
Chapter 2 Basics
Check out the starter circuits which you can find by clicking the Basics
options given on top right corner shown on Figure 2-4.
61
Chapter 2 Basics
62
Chapter 2 Basics
As you engage with the Export and Share buttons, you open gateways to
extend the reach of your design. Exporting in the EAGLE.BRD format lays
the groundwork for physical realization, inviting the transformation of bits
and bytes into tangible circuitry. The Share button, on the other hand, is the
conduit for collaboration, facilitating the exchange of ideas and expertise.
And there’s more—a feature that illuminates your path toward
mastery. On the right side of the interface, a discreet yet invaluable
option beckons you—a gateway to component manuals. This gateway
provides a roadmap to understanding the intricacies of each component’s
functionality, specifications, and optimal usage.
With these features at your fingertips, you navigate the intricate
landscape of electronic design with finesse. As you stand at the crossroads
of exportation, sharing, and in-depth understanding, you wield the tools to
shape the course of your circuit design journey. Every click, every choice,
and every exploration propels you closer to mastery, transforming the
digital into the tangible and expanding the horizons of your electronic
creations.
63
Chapter 2 Basics
You can click the Basic on Starter menu to simulate some other
premade basic circuits as we have shown in Figure 2-4. You can also
explore other options given in that menu, for example, Arduino, to
simulate Arduino-based circuits. Let’s explore the last option in that menu,
named All. Click the LED dimmer circuit. It consists of an LED and a
potentiometer to control the brightness of the LED.
Now we have a menu on the left top, as you can see in Figure 2-6 with
a red rectangle. The first option is used to Rotate component, then we
have an option to delete the components, and the next options are for
undo and redo. You can also keep some notes by using the Noes option on
this menu.
On the left side, we have a quick guide that you can use to make sure
that you are doing things right. This is mentioned with a blue rectangle in
Figure 2-6.
The zoom in and out option is given on top left corner and is shown
with a green circle on Figure 2-6.
Figure 2-6. Menu, Quick Guide, and Zoom in and out options
64
Chapter 2 Basics
You can also see and download the component list using the
Component List option on the top right menu which is shown in
Figure 2-7.
65
Chapter 2 Basics
Component Details Unveiled: As you delve into the CSV format, the
details of your circuit components are poised to take center stage. This
file eloquently showcases the names of each component, accompanied
by their respective quantities and values. This structured arrangement
ensures that your design’s building blocks are comprehensively
conveyed.
Visualizing the Component List: For clarity and insight, visualize
the culmination of your design’s components through the prism of a
comprehensive list. This list—akin to a map of your circuit’s landscape—
is exemplified in Figure 2-8. It serves as both a reference point and a
testament to the meticulous organization of your design.
66
Chapter 2 Basics
67
CHAPTER 3
Explaining the
Interface
and Simulating
Your First Circuit
Continuing our exploration of the dynamic landscape of Tinkercad, we
embark on a new chapter—an odyssey of enhanced understanding and
mastery. Building upon the foundation laid in the previous chapter, where
we delved into the process of setting up your account and acquainting you
with the platform’s basic interface, we now transition into a deeper realm
of exploration.
Diving into Details: With this chapter, the canvas expands, inviting you
to dive deeper into the intricacies of Tinkercad. Here, we navigate beyond
the surface, peeling back the layers to reveal the comprehensive toolkit
that empowers your creative endeavors.
70
Chapter 3 Explaining the Interface and Simulating Your First Circuit
Editing Components
You can start by opening one of the starter kits as shown in Figure 3-1.
We will opt the Blink circuit having one red LED in it. Let us place a
resistor in series from the basic components, and the final circuit should
look like the one in Figure 3-2.
71
Chapter 3 Explaining the Interface and Simulating Your First Circuit
72
Chapter 3 Explaining the Interface and Simulating Your First Circuit
Establishing Connections
Linking to the Arduino: An essential bridge in your circuit is the
connection to the Arduino board. As you weave the threads of
connectivity, channel your focus toward the top hole numbers—0, 1,
and 2. These entry points hold the key to orchestrating the dance of
electronic signals, giving life to your circuit’s behavior.
Completing the Circuit: In the realm of electronic symbiosis,
grounding is paramount. Ensure that the trio of LEDs maintains its
connection to the ground, completing the circuit’s loop. Through this
bond, the LEDs find their grounding, anchoring your circuit’s operation.
73
Chapter 3 Explaining the Interface and Simulating Your First Circuit
74
Chapter 3 Explaining the Interface and Simulating Your First Circuit
75
Chapter 3 Explaining the Interface and Simulating Your First Circuit
76
Chapter 3 Explaining the Interface and Simulating Your First Circuit
77
Chapter 3 Explaining the Interface and Simulating Your First Circuit
Wiring Components
Venturing into the next phase of your circuit exploration, the canvas before
you awaits the imprint of components—a fusion of elements that breathe
life into your design. Your mission begins with the orchestration of a
symphony of parts—a breadboard, a 9V battery, a button, and the ever-
essential resistors. These building blocks are your tools, your notes, in this
composition of electronic artistry.
78
Chapter 3 Explaining the Interface and Simulating Your First Circuit
A Choreography of Arrangement
Reshaping the Landscape: As components gather, a choreography of
arrangement begins. Each element takes its place in the ensemble—a
dance that mirrors your intentions. In this intricate ballet of parts, the
scene transforms—rearranging itself to match the blueprint of Figure 3-6.
A Glimpse of the Vision: With a deft hand and a keen eye, you mold the
components into alignment—a vision realized, a circuit formed. The scene
before you takes on the semblance of your design’s blueprint, a testament
to your manipulation of digital matter.
As you embark on this endeavor, you wield a digital brush—a brush
that paints connections and weaves pathways. The components, the wires,
and the colors are your medium—a medium that holds the promise of
illumination and interaction. Through each click, each connection, you
chart a course toward a circuit that echoes your intentions.
Connect the circuit in a configuration that LED is connected to resistor
and resistor is connected to switch. Do not forget to connect the upper and
lower rows of the breadboard to provide positive and negative voltage. The
resistance value we are going to use is 220 Ohm. Connect the LED’s second
terminal with ground, and the final circuit should look like Figure 3-7.
79
Chapter 3 Explaining the Interface and Simulating Your First Circuit
Adding Components
Let us add some more components and see how other things work. For
executing this part, we need to add batteries and a motor. Here we will
use two 1.5V battery with the DC motor. Connect these components as
connected in Figure 3-8.
80
Chapter 3 Explaining the Interface and Simulating Your First Circuit
When you press the start simulation button, you will see the motor
rotating, and the RPMs will also be written on the motor as can be seen in
Figure 3-9.
Press the start simulation button. And click the photo-resistor; you
will see a slider as given in Figure 3-11. By moving the slider to right and
left, the amount striking the sensor is being changed. You should see the
changing motor speed as you change the amount of light. The speed of
81
Chapter 3 Explaining the Interface and Simulating Your First Circuit
the motor should be least when the slider is at the opposite side of the
sun symbol indicating the least amount of light is present for the sensor.
And the speed should be highest when the amount of light is greatest.
Congratulations, you have simulated your first interactive circuit design in
Tinkercad.
Till now, we were suing two 1.5V batteries, but we can alter the power
given to the motor by changing the batteries. Go to the components,
and select the basic components category; select one 1.5V cell. Click the
cell and you will see a menu containing different options related to the
battery. You can change the number 4, and you will end up having the
configuration given in Figure 3-12.
82
Chapter 3 Explaining the Interface and Simulating Your First Circuit
number of batteries parameter to 2, 1, and again 4 and you will see the
difference. More voltage causes greater speed, and lesser voltage results in
low speed.
For you own learning, you can change the type of the battery and see
the results; you can also play with other options of different components.
Happy learning!
83
CHAPTER 4
Breadboard and
RGB LEDs
Now that we have introduced you with the electronic components and
Tinkercad, we can move forward and make simple circuit with a unique
type of LED called RGB LED. This unique LED can glow in three different
colors, red, green, and blue. In this chapter, we will talk about breadboards
and RGB LEDs mainly and see how helpful the tool Tinkercad is.
A breadboard is a powerful prototyping tool that will let you take
your electronic skills to the next level. With it, you can connect many
components together, so let us learn how to use it by testing out a special
type of LED called an RGB LED. First create a new design. Go to the
basics, search for breadboard, and drag a breadboard. You will see a small
breadboard: a mini breadboard and a full-size breadboard as can be seen
in Figure 4-1.
86
Chapter 4 Breadboard and RGB LEDs
87
Chapter 4 Breadboard and RGB LEDs
Take a closer look on the breadboard, and you will see alphabets on
the corners and numbers on longer sides of the breadboard indicating
rows and columns. You can hover over the holes, and the green connected
line will indicate the connection between certain holes which can be seen
in Figure 4-5. The lines from A to E and F to J are connected, but E and F
are not connected with each other.
88
Chapter 4 Breadboard and RGB LEDs
Now add the RGB LED and some resistors in the design. Search LED
RGB from the search bar and drag into the workspace. Rotate it so that
each pin is in a separate hole on the breadboard. The four pins are red,
green, blue, and cathode which can be seen by bringing the cursor onto
each pin of the LED. Now we will add a resistor to the cathode leg and
connect resistor’s other terminal with the ground on the power 480 Ohm,
and the circuit will look like Figure 4-6.
As we saw it earlier that the gap between the two sides of the
breadboard separates the connection, we will make use of it while
connecting the push button. Push button is a momentarily switch, which
makes connection momentarily when pressed. Search a push button from
the search bar, and connect it onto the breadboard such that two legs
(1a and 2a) are on one side of the gap and other two (1b and 2b) are on
the other side preventing to get short. Connect one side with the positive
supply and other side of the button to the red pin of the LED as illustrated
in Figure 4-7.
89
Chapter 4 Breadboard and RGB LEDs
After clicking the Simulate button, press the pushbutton, and the LED
should turn red whenever the button is pressed. Once it is done, add two
more pushbuttons, and connect them to green and blue pins of the LED as
shown in Figure 4-8. On pressing each pushbutton, one of the three colors
of the LED should glow. This is how we simulated the RGB LED with the
help of one resistor, a batter, and three pushbuttons turning on each light
at a time.
90
CHAPTER 5
Ohm’s Law
It is high time that we learn about a fundamental concept in circuit
designing which is known as Ohm’s law. In this chapter we are going
to discuss about its concept and its application to safely light up a
LED. Figure 5-1 shows a simple circuit that will be used for demonstration
purposes in this chapter, and it contains only four components, battery,
resistor, LED, and a switch. You should know that electric current flows
from the positive terminal of a power source, i.e., a battery, to the negative
terminal completing its path. This is denoted by “I” and demonstrated by
a dashed arrow in Figure 5-1, and we can the direction of the current as
arrow is headed from the positive to negative terminal. Another important
and related concept of electricity is voltage. When current flows through a
component like LED or resistor, there is an associated change in potential
energy across that component; this potential difference is known as
voltage denoted by “V” in Figure 5-1. The amount of voltage drop across
the component depends on its resistance which is simply the amount of
the obstruction it causes in the flow of current. Resistance can be seen
denoted as “R” in Figure 5-1. Resistance, although seems an unwanted
quantity because it hinders the flow of current, plays a very important role
in circuit theory. It makes sure that your electronic components do not
fry because of the access current in the circuit. If you directly connect an
LED with a battery, without a resistance in the circuit, your LED will be
burnt away. So adding resistance into the circuit is crucial, but how much
resistance should we add? What if we add a lot of resistance that only a
few milliampere of current can flow through the circuit? Your LED will
not glow then. Here is when Ohm’s law comes into play. It helps us to find
the right combination of resistance, current, and voltage. It formally states
that “the voltage across a conductor is directly proportional to the current
flowing through it.” The mathematical expression of this law is given in
Equation 5.1.
V = IR (5.1)
Let us get back to Tinkercad to see the Ohm’s law in action. Add an
LED and a battery in the workspace and connect them like Figure 5-2. the
positive terminal of the 9V battery is connected to anode and negative
terminal to the cathode of the LED. Press Start Simulation button to see
what will happen with our LED.
92
Chapter 5 Ohm’s Law
As expected, the LED seems damaged, and if you hover over the LED,
the message says that current through the LED is 915 mA while absolute
maximum is 20 mA. So, it has too much current which it could not handle
and thus damaged. This scenario can be seen in Figure 5-3.
93
Chapter 5 Ohm’s Law
What do you think how can we prevent this from happening? You have
guessed it right; we are going to employ Ohm’s law here. We have voltage
of 9V, and LED can safely handle a current of 20mA (0.02A). So, we put
these values in the formula to calculate the resistor value that can help us
save our LED from damaging.
V = IR
R =V /I
R = 9 / 0.02
R = 450 Ohms
The resistance that we need is 450 Ohms for this circuit. This means
that if we want to ensure that there is only 20 mA of current flowing
through the LED, we need to add a resistor with a value of 450 Ohms to
our circuit. Let us check this out in simulation by adding a resistor to the
circuit, and it will look like Figure 5-4.
94
Chapter 5 Ohm’s Law
As our next step, we click on Simulation button, and see that the LED
turns red without getting damaged by the excessive current. Let us see if
we reduce the resistor value from 450 Ohms. In Figure 5-5, we can see that
we add 10 Ohms, and the LED still blows away because there is 395 mA
current across it while the maximum is 20 mA.
What do think will happen if we change the places of LED and resistor,
like if we connect the resistor at cathode instead of anode of LED? It
actually does not matter whether the resistor comes before or after; either
way it will limit current flow, but it may not be true for other cases and
arrangements of circuit elements. You can test this out for yourself if you
want. Did you notice how the color bands on the resistor change when we
change their values? If not, then you can quickly change the resistor value
and see it yourself. This is called color coding of resistor. All of these color
bands represent some value and together they make the overall value
of the resistor. There exists a table representing the associated values of
different colors on a resistor. It is up to you now to search it yourself. Happy
learning!
95
CHAPTER 6
Let us add one LED. Now let us add another one. Then add a 3V
battery and rotate it like Figure 6-2. Then let us a meter to measure the
voltage and current through the circuit. For this, add multimeter once, and
then copy and paste it or add another one.
Now connect these elements together as given in Figure 6-3. You can
change the wire color to red and black to specify different terminals and
connection as in Figure 6-3. The rule for connecting the multimeter is
different for measuring voltage and for measuring current. The meter
to measure voltage is also known as “Voltmeter,” and the meter used
to measure quantity of current is called “Ammeter.” With this, we can
move on to the connection rule. As for voltmeter, we need to measure
the voltage, we connect with the same two leads of the LED as the above
multimeter (one on the left side) is connected in Figure 6-3. For measuring
Ammeter, we need to break the circuit where LED is connected; connect
one terminal of the meter to the LED and the other terminal to the point
where we broke the circuit. In our case, the break point is the positive
terminal of the battery, so the connections would look like ones given
with the multimeter on the right side in Figure 6-3. Surprisingly, we have
created a series circuit in Figure 6-3. By definition, a series circuit is one in
which components are connected end to end, and there is only one path
of the current. If we closely see the circuit in Figure 6-3, the LEDs, battery,
98
Chapter 6 Series and Parallel Circuits
Run the simulation and you will see the results similar to Figure 6-4.
We can see that the voltage is 1.5V, and the current seems to be very low
as 0A. This configuration is called series, where we have a single path for
current. The current enters from positive terminal of the battery, enters to
the first LED, leaves the first LED, enters the second one, and then leaves
the second LED to back to negative terminal.
99
Chapter 6 Series and Parallel Circuits
Now, let us talk about the second part of this chapter, parallel circuit.
Let us add the necessary components. We need four LEDs, a battery, and a
multimeter like Figure 6-5.
Wire up the LEDs in parallel circuit such that both the leads of all
LEDs should be connected to each other. The parallel circuits are those in
which there are multiple paths for current, each for each component. For
example, in our case, we have four LEDs; there must be four paths for the
current. If you see the circuit, each LED is directly connected to the battery
cell as can be seen in Figure 6-6.
100
Chapter 6 Series and Parallel Circuits
Now, change the color of the wires as given in Figure 6-7 to indicate
the positive and negative connection of the supply. Unlike the series
circuit, the current goes from the battery and comes back to it after moving
through one LED only. In parallel circuits, the voltage is same across all
the components. So, we can measure voltage only across one component,
and we will know the voltage across all. In Figure 6-6, we have connected
a multimeter as ammeter to measure the current through an LED as the
current varies in parallel components, but as we have connected the same
components in this circuit, the current will also be the same.
101
Chapter 6 Series and Parallel Circuits
102
Chapter 6 Series and Parallel Circuits
Now run the simulation, to see the measured voltage and current.
The voltage is around 2.10V. The voltage across each LED will be the same
because of the parallel connection.
Figure 6-11 shows the running simulation of both series and parallel
circuits with measured voltage and current.
103
Chapter 6 Series and Parallel Circuits
The main difference between a series and parallel circuit is that series
circuit has only one path between the positive and negative terminal of
the battery, but the parallel circuit has its own separate path between the
positive and the negative terminal.
Now you have learned about some of the basic differences between
series and parallel circuits. You can continue tinkering by practicing
hooking up additional LEDs in this circuit. You can try changing the
battery type or adding additional batteries in series to remember voltage
should add up in a series circuit. You may have to adjust the resistor value
or add a resistor in some cases to make sure that your circuit is running
effectively and correctly. If you closely see, there is a warning on the LED
due to excessive current. If you want to get rid of this warning, you can add
a resistor. Let us add a 100 Ohm resistor. Now as you can see in Figure 6-12,
we no longer have any warning in here.
104
Chapter 6 Series and Parallel Circuits
But since we did not take the Ohm law in the previous lesson, let
us measure how much of the resistor we need to use. Here we have a
3V power source, and we know that we only need 20 mA to go through
this LED.
So, by Ohm’s law, V = I*R, and thus, R = V/I and by putting V=3V and
I=20mA. Thus, R = 3/0.02 equals to 150-ohm resistor to make sure that our
LED were lighting up correctly. I hope that you now have a clear idea about
series and parallel circuits.
105
CHAPTER 7
Arduino Output
Basics
Have you ever been curious how each light of the traffic light gets turn on
and off for a particular time duration? If yes, then this chapter is for you in
which you will first learn how you can control the blinking of an LED, then
learn how to handle multiple LEDs and their on and off timing, and at the
end, you will learn to control the brightness of the LED. We will learn all
these by creating circuits on the Tinkercad platform.
the red color to the anode of the led and wire connected to digital pin 13,
and set the black color to the cathode of the led. Now run the simulation.
What do you visualize? LED is blinking, and its blinking duration is
decided by the default code of Arduino. We will soon see how it is getting
on and off and how we can change its on and off duration, but before that
let’s understand the placement of components. If you reverse the LED
connection by connecting its anode to the ground and cathode to a resistor
which is followed by digital pin 13, your LED would be paralyzed because
its legs get connected in a certain way. Although the placement of the
resistor does not matter, you may connect it between the cathode of LED
and the ground or in the same way as shown in Figure 7-1. The resistor is
needed to limit the flow of current that will prevent LED from burning.
Now let’s understand how LED is blinking in a certain way and how
can you control it in your desired way. So, in the upper tabs part as shown
in Figure 7-2, you can see there is a drop-down menu mentioned as block
or text or block + text any of the abovementioned would appear to you in
your Tinkercad platform. Once you click the blocks option, you will see
multiple options that would be visible to you, different colors for each
block set like blue for Output, Control, green for Math, black for Notation,
108
Chapter 7 Arduino Output Basics
and so on. If you hate coding, you can control your output just by using
these blocks. You can click any of these, and you get a heap of options
here as you can see all that you need to do we input and output is simply
drag and drop. As you can see, there are already some blocks connected
in a certain way, and it is showing the default code of Arduino that is
controlling the LED connected to digital pin 13 of Arduino.
Now let us dive deep and understand what is written for us. In blue
blocks you can read blue blocks as set built-in LED to high or low is
written. From the drop-down, you change its state to either high or low.
High means logic 1 or positive voltage signal, and low means logic 0 and
Ground. And orange blocks are control blocks by using them; we add the
delay mentioned as wait in Figure 7-2; 1-sec delay is set high. From the
drop-down option unit from secs to milliseconds can be changed and
can write the wait value instead of 1, vary the delay value, and run the
simulation you can visualize the on and off period of LED. As you can see
here, everything is working just fine. You can connect the blocks logically
the way you want just by dragging existing blocks to the trash and dragging
new blocks and drop into the workspace and then connecting as you want.
109
Chapter 7 Arduino Output Basics
Now if we go to the text area, you can see that we have this code
written for us as shown in Figure 7-3; this code is written concerning the
arrangement of blocks as we saw earlier. So, when you draw a block, it will
turn to code and burn it to this algorithm board.
In the text, you can see the void setup to set the pin mode of Arduino
either as input or output. Here, pin 13, i.e., LED_BUILTIN, is set as the
output pin which means that we can send signals from the Arduino board
to this pin and do not receive signals from it. Then in the void loop, we
write the code that we want to repeat forever; digitalWrite(LED_BUILTIN,
HIGH) sends a digital signal 1 to piPIN3 which will turn on the LED; the
delay of one thousand minute seconds which means one second is written
as we added in the block area, and digitalWrite(LED_BUILTIN, LOW)
sends a digital signal 0 to PIN 13 which would turn off the LED. The on-
and-off period is determined by delay. Now we have seen how the blinking
of the LED is controlled by opening this text and blocks.
What you need to do now is start this thing out for yourself. You can
easily download the code from the download icon beside the blocks menu.
You can open the downloaded code by Arduino IDE as shown in Figure 7-4
and then burn it to an Arduino board, and see how it works on our real-life
Arduino board.
110
Chapter 7 Arduino Output Basics
You can also add libraries in your Tinkercad code. To see available
libraries, click on the library icon; some of the libraries are shown in
Figure 7-5.
111
Chapter 7 Arduino Output Basics
112
Chapter 7 Arduino Output Basics
113
Chapter 7 Arduino Output Basics
In the realm of coding, the stage is set for our LEDs to take their cues,
their choreography scripted with lines of logic. As the curtain rises on the
“Code” tab, we are presented with two distinct paths to wield our artistic
control—text or blocks, each poised to translate our intentions into the
language of electrons.
Now, let our intention take form. Imagine a scenario where one LED
must bask in its luminance while its companions await their moment
in the shadows. With this vision in mind, we embark on crafting the
symphony of commands that shall animate our LEDs.
As the script unfurls, a clear pattern emerges—akin to the rise and
fall of performers on a stage. Each section of code is an act, a sequence of
commands carefully orchestrated to manifest our vision. Picture the stage:
three LEDs, waiting in the wings, their brilliance poised to shine.
In this act, the prologue of “void setup” plays out—a prelude to
the grand performance. With each line, a pin’s role is defined—a stage
manager allocating cues to performers. As we traverse the threshold
of the “void loop,” our script takes on a rhythmic cadence, a loop that
encapsulates the essence of our story.
Within this loop, the “digitalWrite” command becomes our
conductor’s baton, summoning a single LED to grace the stage. As the
first LED takes its bow, it bathes the scene in its luminous glow, its
performance set to last precisely 1000 milliseconds. But the stage is vast,
and other LEDs await their cues.
Like clockwork, the command “delay” invokes a hushed pause—a
moment of anticipation before the next performer emerges. As the LED’s
brilliance recedes, another light takes its place, basking in a one-second
spotlight, its aura pulsating through the circuitry.
The script continues its waltz, each LED taking its turn in a sequence of
brilliance, a dance of light and dark, illumination and obscurity. And as the
loop draws to a close, the cycle begins anew—LEDs ascending the stage in
a harmonious rhythm, a symphony of illumination.
114
Chapter 7 Arduino Output Basics
And so, dear scriptwriter, you stand at the crossroads of text and code,
poised to breathe life into your electronic narrative. Each line a note, each
command a step, as your LEDs perform their roles in this grand electronic
ballet. With every iteration of the loop, the LEDs enact their dance—a
dance crafted by your intentions, shaped by your code, a dance that
exemplifies the interplay of creativity and technology that Arduino brings
to life.
115
Chapter 7 Arduino Output Basics
116
Chapter 7 Arduino Output Basics
So, with the stage set and the analog pins as our allies, let us embark on
this journey of LED modulation—a voyage where the symphony of digital
precision blends seamlessly with the artistry of light, creating a harmonious
dance of luminescence that speaks to the very essence of creativity.
In the vast and intricate tapestry of electronic exploration, we find
ourselves on a journey to craft circuits—exquisite tapestries of wires,
intricate components, and the harmonious interplay of electrons. It is a
symphony of technology and creativity, where the mundane becomes
the extraordinary, and the abstract transforms into tangible reality. With
Tinkercad as our virtual canvas, we are poised to infuse existence into our
digital dreams, to orchestrate the ethereal ballet of light and energy that
resides within the realm of electronics.
Figure 7-8. Pins with wave sign are analog output pins of Arduino
118
Chapter 7 Arduino Output Basics
119
Chapter 7 Arduino Output Basics
Connections come to life—an LED finds its abode, nestled upon pin
9, its radiance destined to be painted in hues of yellow. The stage set, the
players take their positions—the wires of power, one in resplendent red,
the other in steadfast black, grounding the realm in potential.
An oscilloscope emerges—an enigmatic observer, its purpose to unveil
the arcane voltages coursing through the circuit’s veins. Wires of yellow
and black once more, a chorus of electrons ready to divulge their secrets.
As our circuit unfurls, its artistry akin to Figure 7-8, we stand at the
precipice of simulation. An LED poised to respond, to dance, to illuminate.
Voltage waves yearning to be seen, to tell their tales of rise and fall.
The digital realm reverberates with anticipation. The connections,
the colors, the components—they are the palette of creation. In this
symposium of electrons, we transmute concepts into reality, and with a
click, a circuit springs to life—a testament to our virtual craftsmanship, a
harbinger of enlightenment.
The canvas of creation beckons, and we stand at the threshold of
realization. With a palette of blocks, we shall weave the tapestry of our
intent. As novice navigators, we turn to the “block mode,” a gentle breeze
to guide us through the labyrinthine corridors of code.
Figure 7-10. Drag count up block, rename variable name, and set its
max and min count
120
Chapter 7 Arduino Output Basics
121
Chapter 7 Arduino Output Basics
122
Chapter 7 Arduino Output Basics
123
Chapter 7 Arduino Output Basics
Figure 7-12. Set brightness value from 255 to 0 and add wait block
124
Chapter 7 Arduino Output Basics
125
Chapter 7 Arduino Output Basics
Figure 7-13. (a) Showing the full brightness mode of LED and (b)
and (c) showing how the signal across LED decreases to 0 which
results in fading of the LED
126
Chapter 7 Arduino Output Basics
127
Chapter 7 Arduino Output Basics
128
CHAPTER 8
130
Chapter 8 Arduino Input Basics
The essence of a push button’s magic lies in its very nature—a switch
that responds to the gentle pressure of a fingertip, akin to a whisper that
stirs a symphony. Once pressed, its innate magic comes to life. As the
physical world melds with the realms of electrons, an electrical circuit is
seamlessly woven into existence. This circuitry forms the conduit through
which a signal embarks on its journey—a signal that carries within it the
command to fulfill a predefined task or function.
Within the heart of the Arduino, digital input pins slumber, waiting for
their moment in the spotlight. These pins possess the remarkable ability to
sense the state of input signals, like an oracle interpreting cosmic whispers.
The push button’s purpose becomes clear as we bridge the gap between its
terminals and the digital input pin. The act of pressing the button forges a
connection—a dance that completes the circuit, unleashing an electrical
signal that reverberates through the corridors of the control system or
microcontroller.
A visual narrative emerges as we journey into the realm of circuitry.
Behold Figure 8-1—a crystallization of our understanding, a visual tableau
that captures the essence of the push button’s union with circuitry. An
Arduino takes center stage, surrounded by an ensemble of components—a
breadboard, resistors, a push button, and the humble LED. Each element
plays its part in crafting this electronic ballet.
131
Chapter 8 Arduino Input Basics
Figure 8-1. Connect push button and LED with digital pin
of Arduino
132
Chapter 8 Arduino Input Basics
133
Chapter 8 Arduino Input Basics
definition in their state. The pull-down resistor steps onto this stage as a
master choreographer, orchestrating equilibrium when no external hand
guides the input’s motion.
The dance between resistors and input signals becomes profound
when we confront the specter of the “floating” state—an ethereal realm
where undirected inputs waltz with electrical noise, yielding erratic
oscillations between high and low states. Chaos ensues, compromising
the circuit’s harmony and injecting unpredictability into its operation. The
pull-down resistor emerges as a sentinel against this cacophony, providing
a steadfast connection to the ground that quells the unruly cacophony.
This practice, while elegant, doesn’t forsake the needs of an active
circuit. In moments when the input is called to action by an external
circuit, the pull-down resistor steps aside gracefully, allowing the external
force to assert its influence without hampering the flow of current.
In Figure 8-1, our narrative visualizes this symphony—where a push
button and an LED coalesce. When the button remains untouched, the
digital pin 2 finds solace in the grounded embrace of the pull-down
resistor, eradicating any inklings of a “floating” state. Yet, as the button’s
heart beats with intent, a path to power manifests, illuminating the LED
and bestowing upon the digital pin 2 the high state.
The real triumph of the pull-down resistor surfaces as we unmask the
veil of uncertainty that plagues a floating input. The resistor’s presence
eradicates the tumultuous dance of electrical noise, allowing the signal’s
true intent to prevail. However, the resistor doesn’t just alleviate chaos;
it fends off the intrusive cacophony of electromagnetic interference
and static electricity, safeguarding the integrity of the input signal and,
consequently, the sanctity of the output.
Let us also touch upon the counterpart—the pull-up resistor—a guardian
of a different realm. These resistors tether inputs to power, creating stability
in a world of electric symphonies. In essence, the pull-up and pull-down
resistors intertwine to bring forth a state of equilibrium, ensuring that each
input dances to the beat of certainty, devoid of noise-induced disruptions.
134
Chapter 8 Arduino Input Basics
Figure 8-2. Code block to read state of push button and to control the
LED blinking accordingly
135
Chapter 8 Arduino Input Basics
Through this exercise, the art of reading values as input finds its
culmination. The push button—a tangible entity—becomes a conductor
of light, initiating and extinguishing the LED’s glow. The code, woven
with the fabric of conditional evaluation, becomes the translator between
physical touch and digital command.
136
Chapter 8 Arduino Input Basics
137
Chapter 8 Arduino Input Basics
138
Chapter 8 Arduino Input Basics
Arduino’s analog pins serve as portals that channel these signals, while the
ADC orchestrates the grand translation into digital data. As we traverse
the six analog pins, we open doors to a world where Arduino’s capabilities
extend beyond the confines of on and off, embracing the rich nuances of
continuous signals. This chapter unveils Arduino’s metamorphosis into a
translator between the analog and the digital, broadening the horizons of
our journey into electronics and interaction.
139
Chapter 8 Arduino Input Basics
140
Chapter 8 Arduino Input Basics
141
Chapter 8 Arduino Input Basics
142
Chapter 8 Arduino Input Basics
Figure 8-6. Code block to read analog value and to control the delay
accordingly
143
Chapter 8 Arduino Input Basics
144
Chapter 8 Arduino Input Basics
145
CHAPTER 9
148
Chapter 9 Dealing with RGB LED with Potentiometers
This stage, set in the realm of the virtual, serves as the canvas upon
which our illumination masterpiece shall be painted. Through the
interplay of color pins, resistors, and Arduino’s prowess, a new narrative
unfolds—one where colors transcend their ordinary boundaries, where
technology becomes the brush, and where creativity paints the canvas
of light.
In closing, the world of RGB LEDs and Arduino beckons us into a realm
of limitless potential. Through this harmonious partnership, we become
creators of illumination, crafting a symphony of colors that transcends the
ordinary. The circuit, a portal between imagination and reality, offers a
playground for exploration. As we navigate from connections to code, we
journey into a domain where light becomes our medium and colors our
brushstrokes—a tale of innovation, transformation, and the boundless
fusion of creativity and technology.
In the realm of creative coding and luminous expression, we find
ourselves ready to craft our own symphony of light. As our journey unfolds,
we step into the world of code creation, guided by the pulsating heart of
our RGB LED. Let us embark upon this journey, selecting blocks from our
digital arsenal to orchestrate a harmonious dance of colors and brightness.
With eager anticipation, our gaze falls upon the block window—a
treasure trove of possibilities. Within its confines, we find the tools to shape
light, to breathe life into our LED canvas. Among the offerings, we discern
the RGB LED block—an ambassador of illumination. With a deft hand, we
pluck this block from the window and place it upon our digital canvas, as
depicted in Figure 9-2.
149
Chapter 9 Dealing with RGB LED with Potentiometers
With the RGB LED block on our virtual stage, a choice presents itself—
the selection of pins to which the colors of our LED are tethered. This
decision, akin to selecting a palette, defines the avenues through which
light will flow. Figure 9-2 serves as our guide, demonstrating the selection
of pins 9, 10, and 11—a trinity of possibility that beckons us to unveil the
RGB LED’s true potential.
As our brush meets canvas, a new dimension unfurls—a palette
of colors bathed in a gradient of luminosity. In Figure 9-3, a color bar
emerges—an embodiment of choice and expression. With a simple
click, a world of hues unfolds before us. By selecting a hue—let’s say
the passionate embrace of red—we set the stage for a captivating
transformation. The RGB LED, ever obedient to our commands, responds
by adjusting the brightness of each LED diode, crafting a symphony of
crimson luminosity.
150
Chapter 9 Dealing with RGB LED with Potentiometers
151
Chapter 9 Dealing with RGB LED with Potentiometers
In this journey, the blocks become our tools, the canvas becomes
our LED, and code becomes our artistry. The process of selection and
arrangement, guided by the intuitive interface, transforms the abstract into
the tangible. Through a sequence of clicks and choices, we have witnessed
the dawn of a new era—an era where colors and light intertwine, where
creativity and technology converge in a symphony of vibrant illumination.
In conclusion, the narrative woven through the process of code
selection and execution showcases the remarkable synergy between
creativity and technology. The blocks, those building blocks of expression,
empower us to transform the mundane into the extraordinary. The LED, a
canvas of light, becomes an instrument of our imagination. As we journey
from selection to execution, we unveil a tapestry where the virtual and the
tangible intersect—an artful dance where code illuminates our vision.
Within the realm of Figure 9-5, a textual tableau unfolds, revealing the
inner workings of a symphony of light and shadow, guided by the subtle
nuances of PWM (Pulse Width Modulation). This narrative beckons us
to embark on an exploration of how the brightness of our LED can be
harnessed and manipulated to paint an enchanting canvas of luminosity.
As the curtain rises, we are greeted by the resonance of the PWM pins
of our Arduino—three digital emissaries designated to partake in the art
of illumination. These pins, adorned in the role of outputs, stand ready to
transmit the painterly strokes of analog voltages that will transform our
LED’s brilliance.
The maestro of this luminous opera is the “analogWrite” command—
an instrument through which Arduino weaves its magic. This command,
akin to a conductor’s baton, orchestrates the transmission of PWM signals
to the designated output pins. These PWM signals, reminiscent of ethereal
waves, carry values that stretch along a spectrum from 0 to 255—a familiar
territory discussed in earlier chapters.
152
Chapter 9 Dealing with RGB LED with Potentiometers
153
Chapter 9 Dealing with RGB LED with Potentiometers
154
Chapter 9 Dealing with RGB LED with Potentiometers
155
Chapter 9 Dealing with RGB LED with Potentiometers
156
Chapter 9 Dealing with RGB LED with Potentiometers
Figure 9-7. Block Coding: Using blocks instead of writing lines of code
157
Chapter 9 Dealing with RGB LED with Potentiometers
158
Chapter 9 Dealing with RGB LED with Potentiometers
159
Chapter 9 Dealing with RGB LED with Potentiometers
Figure 9-11. Just vary the respective potentiometer of red light results
in display of red light
160
Chapter 9 Dealing with RGB LED with Potentiometers
analog pins: A0, A1, and A2. These pins, like receptive senses, interpret the
nuances of the surrounding environment, capturing analog signals that
ultimately mold the behavior of our RGB LED.
The act of defining pin modes echoes the allocation of roles within
a theatrical ensemble. As the curtain rises, the analog pins, aptly poised
to interpret the world’s subtle language, are cast into roles of humble
observers. Configured as inputs, they await their cues, ready to engage
in a dialogue with the surrounding variables. In contrast, the digital
pins, electrified with potential, assume the roles of protagonists. Cast as
outputs, they bear the responsibility of painting the RGB LED’s canvas with
vivid hues.
In the symphonic crescendo of code execution, analog values emerge
as the conduits of information, flowing into their designated variables.
Each variable becomes a chalice, cradling the essence of the analog
world it represents. The potency of these variables lies in their ability to
encapsulate reality, transforming physical phenomena into digital form.
The “analogWrite” command stands as the conductor’s baton,
orchestrating a choreography of voltages. As the digital pins, numbered 9,
10, and 11, respond to this command, they imbibe the values encapsulated
within the variables. These values serve as instructions, dictating the
intensity of the light each diode emits. The result is an enchanting display
of luminosity, where the RGB LED emerges as a canvas, painted stroke by
stroke with the hues stored within the variables’ depths.
In conclusion, the journey through Figure 9-12 unravels a narrative of
integration. It is a tale where code bridges the realms of the digital and the
analog, and where variables serve as vessels of understanding. The code
weaves a tapestry of communication between pins and LEDs, casting a
spotlight on the potential for artistic expression through technology. It is
within this digital choreography that the RGB LED and the potentiometer
dance in unison, each movement guided by the elegantly orchestrated
sequence of commands and variables.
161
Chapter 9 Dealing with RGB LED with Potentiometers
162
CHAPTER 10
164
Chapter 10 Arduino Serial Monitor
165
Chapter 10 Arduino Serial Monitor
166
Chapter 10 Arduino Serial Monitor
With the strategic placement of the “print serial monitor” block, our
simulation embarks on a new phase. Upon initiating the simulation, a
transformation unfolds within the serial monitor window. What was once
a static “hello world” metamorphoses into a dynamic tapestry of data.
Each iteration of the simulation presents an opportunity to witness the
responsive interaction between the Arduino input pin and the subsequent
display of resistance values.
In essence, this immersive experience encapsulates the dynamic
interplay between hardware and software. The code, a manifestation of
logic and instructions, synergizes with the physical world through the
input pin. The ensuing visual feedback, projected onto the serial monitor
window, completes the circuit of interaction, transforming the virtual into
the tangible.
This exploration not only enriches our understanding of code
execution and hardware integration but also highlights the role of visual
aids in comprehending complex systems. The serial monitor, once a silent
observer, becomes a vital medium of communication, bridging the gap
between the abstract and the concrete.
In conclusion, the journey to extract resistance values from an Arduino
input pin and display them within the serial monitor window is an
exhilarating odyssey. The symbiotic dance between input and output, the
orchestration of code blocks, and the transformation of virtual interactions
into real-world observations collectively compose a symphony of
technological exploration. This journey underscores the potential of
interactive learning environments to nurture a profound understanding of
coding, electronics, and their harmonious fusion.
To elaborate further on this topic, let’s delve into the process of
incorporating the analog potentiometer value into the code and visualizing
its effects through the serial monitor. In order to achieve this, we introduce
a novel variable known as “sensor value” within the code block. This
variable becomes the conduit through which the analog potentiometer’s
value is transmitted and subsequently displayed.
167
Chapter 10 Arduino Serial Monitor
168
Chapter 10 Arduino Serial Monitor
169
Chapter 10 Arduino Serial Monitor
170
Chapter 10 Arduino Serial Monitor
171
Chapter 10 Arduino Serial Monitor
172
Chapter 10 Arduino Serial Monitor
173
Chapter 10 Arduino Serial Monitor
2. Electronics Hobbies:
174
Chapter 10 Arduino Serial Monitor
175
Chapter 10 Arduino Serial Monitor
As you venture into these realms, keep in mind that every challenge
you face is an opportunity to learn and grow. Embrace the process of
experimentation, accept failure as a stepping stone, and celebrate your
successes as milestones of your journey. The path ahead is as diverse as
your imagination, and your circuit design knowledge is the compass that
guides you toward endless exploration and innovation. The world is your
canvas—let your circuits paint the future.
176
Index
A exploration, 143
IDE, 111
Adaptive cruise control, 53
Arduino Analog output, fading
ADC, see Analog-to-digital
LED, 117–127
converter (ADC)
Arduino digital output
Address retrieval and connection, 16
algorithm board, 110
Advanced driver assistance
breadboard, 112
systems (ADAS), 53
circuit, 113
Aerospace and defense, 54
code, 108
Aerospace applications for flight
connect LED with, 108
control, 54
creativity and technology, 115
Agriculture, 55
LED control, 107
Airbag deployment, 53
multiple LEDs and
Air quality, 55
breadboard, 113
Algebraic Logic Unit (ALU),
simulation, 109
17, 27, 29, 30
text for coding, 110
Ammeter, 98, 101, 102
void setup, 114, 115
Analog pins of Arduino, 139, 155
Arduino input basics
Analog-to-digital converter (ADC),
abstract phenomena, 138
138–140, 168
analog input, 137–142, 144
analogWrite command, 125, 126,
circuit’s harmony, 134
153, 161
code blocks, 129
Anti-lock braking systems (ABS), 53
coding with intent and
Arcade machines, 54
purpose, 135
Arduino, 55
intention and execution, 137
analog pins, 154, 155
LED with digital pin, 132
board, 126
mechanical systems, 145
exercises, 128
178
INDEX
179
INDEX
Educational Tools, 55 H
Electrical noise, 134
Handheld gaming devices, 54
Electronic metamorphosis, 122
Hardware complexity of CISC
Electronic signals, 73
architectures, 46
Embedded controller, 3, 4
Hardware components, 3, 45
Embedded microcontrollers, 32, 33
Hardware Emphasis, 45
Embedded systems, 41, 53
Harmonizing aesthetics with
Energy management systems, 54
function, 74
Energy utilization, 54
Harvard architecture, 35, 36,
Entertainment and Gaming, 54
39, 40, 42
Entrepreneurship, 175
memory access, 41
Environmental monitoring
predictable timing, 41
devices, 21
Harvard architecture system, 40
Environmental monitoring
Higher-level abstractions, 45
systems, 55
High-stakes systems, 4
Erasable Programmable Read-Only
Home automation, 54, 173
Memory (EPROM), 7
Home monitoring systems, 51
Evolution of microcontroller
technology, 28
Experimentation, 76, 176 I, J, K
Exporting Design in EAGLE.BRD Industrial automation, 9, 21, 53
Format, 62 Informational portal, 62
External memory Information transmission, 18
microcontroller, 34, 35 Infotainment systems, 53
Input/output (I/O) capabilities, 7
F Instruction Decode and
Facial recognition systems, 55 Control Unit, 5
Fading LED, 117–127 Instruction decoding, 14
Fingerprint scanners, 55 Instruction decoding overhead, 46
5G connectivity, 26 Integrated Development
Environment (IDE), 163
Integrated systems, 25
G Integration, 22
Gaming consoles, 54 Intel 8051, 8, 28
180
INDEX
Intel 8086/8088, 5 M
Intel 8096 series, 8, 29, 31, 44
Machine cycle, 14–16
Interconnected
Medical devices, 33, 54
ecosystems, 25
Medical monitors, 24
Internet and exchange data, 53
Memory access modes, 44
Internet of Things
Microchip, 5
(IoT), 22, 53, 174
Microcoding, 45
Interoperability, 25
Microcomputer realm, 7
Intuitive user interfaces, 25
Microcontrollers, 1, 133
analog-to-digital converter
L (ADC), 138
applications, 51–55
Lane departure warning, 53
architectural specifications, 35–37
LED, 59–61, 75–77, 79, 80, 94
architecture, 9
and battery cell, 98
architecture and functionality, 9
and battery, 93, 98
capabilities, 2
binary signals, 117
compact integration, 8
blinking, 136
computational requirements, 8
blinking control, 135
control processes, 8
colors, 74
data processing, 42
complete circuit, 94
digital lives, 2
damage, 93
economic advantage, 8
in ethereal rhythms, 133
8-bit microcontroller, 27, 28
fading, 117, 119–128
embedded systems, 9
modulation, 117
embedding intelligence, 2
performance, 116
energy-efficient
in perpetual brilliance, 137
characteristics, 4
and potentiometer, 140
external memory, 34, 35
and resistor, 95
input/output (I/O) operations, 8
series and parallel circuits,
input/output (I/O) ports, 9
97, 98, 105
instruction execution, 42
tangible entity, 136
vs. microprocessor, 12, 13
Lighting systems, 54
peripherals, 2
Low-power microcontrollers, 41
181
INDEX
182
INDEX
183
INDEX
184
INDEX
V Von Neumann-based
microcontrollers, 37–39
Variable Frequency Drives
(VFDs), 23
Variable-Length Instructions, W, X, Y, Z
CISC, 45
Water quality, 55
VCRs, 10, 51
Wearable fitness trackers,
Very Large Scale Integration
22, 53, 175
(VLSI) chip, 5
Weather conditions, 55
Virtual design, 80
Weather data, 55
Voice-controlled assistants, 54
Wind turbines, 54
Voltmeter, 98, 102, 103
Wireless speakers, 54
Von Neumann and Harvard
Wiring components, 78
architectures, 36, 37
WRITE operation, 19
Von Neumann architecture, 36,
38, 39, 41
185