0% found this document useful (0 votes)
18 views86 pages

Intro Embedded Sys

Uploaded by

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

Intro Embedded Sys

Uploaded by

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

PHY 261

Programming with C++ I :


Introduction to
Embedded Systems

1
Introduction to Microcontrollers

MCUs vs CPUs

Why C++ for Embedded Systems

Introduction to Arduino IDE and simulation

Outline Basic Arduino Commands / Functions

The UNO board and Working with LEDs

Analog And Digital Signals And The Serial Port

Working with Input components

Working with Output components


2
SECTION 1: INTRODUCTION TO
MCUs
What are embedded systems?
Embedded systems are specialized computing systems designed to
perform dedicated functions or tasks within a larger system.
Unlike general-purpose computers that can run a variety of
applications, embedded systems are typically built to execute
specific functions or control specific hardware.

These systems are embedded as part of a larger device or product,


and they often operate in real-time environments.

3
Features of Embedded Systems

• Dedicated Functionality: Embedded systems are designed for a specific purpose.


• Real-time Operation: Many embedded systems must respond to external events within
a certain timeframe.
• Limited Resources: Embedded systems often have resource constraints, including
limited processing power, memory, and storage.
• Integration: Embedded systems are integrated into a larger system or product, and they
often work in conjunction with other components.
• Reliability: Many embedded systems are used in critical applications where reliability is
crucial.

4
Evolution of Microcontrollers in Embedded
Systems
1. Early Beginnings
•Embedded systems originated in the mid-20th century for real-time control in
military and industrial applications.
•Initial implementations involved discrete logic components and dedicated
hardware.

2. Introduction of Microcontrollers (MCUs)


•The 1970s marked a revolution with the introduction of microcontrollers.
•Intel's 8048, released in 1976, was one of the earliest MCUs, featuring on-chip
CPU, memory, and I/O ports.
5
Evolution of Microcontrollers in Embedded
Systems
3. Architectural Advancements
•Microcontroller architectures evolved with improvements in performance,
reduced power consumption, and enhanced capabilities.
•Introduction of Harvard architecture, pipelining, and advanced instruction sets
optimized MCU functionality.

4. Integration of On-chip Peripherals


•Early MCUs had limited on-chip peripherals, but advancements led to the
integration of timers, communication interfaces (UART, SPI, I2C), and ADC.
•On-chip peripherals reduced the need for external components, enhancing cost-
effectiveness. 6
Evolution of Microcontrollers in Embedded
Systems
5. Application Expansion
•Microcontrollers found applications in various industries, including automotive,
consumer electronics, medical devices, and industrial automation.
•Became essential in the development of smart and interconnected devices.

6. Miniaturization and Cost Reduction


•Ongoing efforts in miniaturization and cost reduction made microcontrollers
more accessible for mass production.
•Reduced power consumption and smaller form factors enabled integration into
portable and battery-powered devices.
7
Evolution of Microcontrollers in Embedded
Systems
Embedded System Development Ecosystem
•A robust ecosystem emerged with development tools, compilers, and integrated
development environments (IDEs).
•Diverse MCU families from different manufacturers provided options for
developers to choose the most suitable MCU for specific applications.

Present Day Impact


•Microcontrollers are ubiquitous, powering a wide range of devices from simple
household appliances to complex automotive control systems and IoT devices.
•Their evolution, coupled with a robust development ecosystem, has solidified
their foundational role in the design and implementation of embedded systems. 8
SOME COMMON MICROCONTROLLERS
1. Arduino UNO 2. Raspberry pi pico 3. Espressif ESP32

5. Arduino Mega
6. STM32

4. Arduino Nano

9
Applications of MCUs
• Automotive Control Systems
• Internet of Things (IoT) Devices
• Industrial Automation
• Medical Devices
• Consumer Electronics

10
11
SECTION 2: MCUs vs
CPUs
• Microcontrollers (MCUs) and Central Processing
Units (CPUs) are both types of processors, but they
serve different purposes and are designed for
different applications.
• CPUs are the primary components of a computer
responsible for executing instructions and
performing calculations. They act as the brain of a
system, carrying out tasks ranging from basic
arithmetic operations to running complex software
applications.

12
Feature Comparison between MCUs and CPUs
Feature Microcontrollers (MCUs) CPUs
Integration Integrated circuits combining CPU, Typically consist of a standalone
memory, and peripherals on a single CPU requiring external
chip. components for memory and
peripherals.
Specialised Designed for specific tasks, often General-purpose processors
Functions operating in real-time capable of running a wide range
environments. of applications.

Resource Often have resource constraints in Typically have higher processing


Constraints terms of processing power, power and are less constrained in
memory, and storage. terms of resources.
13
MCUs vs CPUs
Feature Microcontrollers (MCUs) CPUs
Applications Commonly used in embedded systems for Found in personal computers, servers,
specific applications like IoT devices, workstations, and devices requiring
automotive control, and industrial versatile computing capabilities.
automation.

External Integrated peripherals like timers, May require external components (e.g.,
Peripherals communication interfaces, and ADC on separate memory modules, peripheral
the same chip. controllers) for expanded functionality.

Operating Often run on bare-metal or lightweight Capable of running complex operating


Systems real-time operating systems. systems that support multitasking and
a wide array of applications.

14
Why MCUs are preferred in Embedded
Developments

Integration and Compactness: Microcontrollers (MCUs) integrate CPU,


memory, and peripherals on a single chip, providing a compact solution
suitable for space-constrained embedded systems

Cost-Effectiveness: MCUs are designed for specific applications, making


them more cost-effective than general-purpose CPUs, which is crucial for
mass production and cost-sensitive projects.

Low Power Consumption: Many MCUs are optimized for low power
consumption, making them ideal for battery-powered and energy-
efficient embedded devices, including IoT applications.
15
Why MCUs are preferred in Embedded
Developments

Real-Time Processing: MCUs are often tailored for real-time processing,


allowing quick and predictable responses to inputs and events, making
them suitable for control systems and robotics.

Specialized Functionality: Microcontrollers can be customized for specific


tasks, avoiding unnecessary features found in general-purpose CPUs. This
specialization results in efficient processing for the intended application.

Ease of Development: Microcontrollers often come with a dedicated


development ecosystem, including software development tools, libraries,
and integrated development environments (IDEs).
16
SECTION 3: C++ FOR EMBEDDED
SYSTEMS PROGRAMMING

C++ is often chosen for embedded systems


programming because it brings a good mix of helpful
features
And in this section we discuss why C++ is preferred
among numerous programming languages available.

17
Why C++ ???
 Organization and Reusability: C++ supports a way of
organizing code that's like building with LEGO bricks, making it
easier to manage and reuse pieces of code in embedded
systems.
 Efficiency: C++ allows developers to fine-tune how the
computer's memory is used, which is important for embedded
systems that often have limited resources. This helps make the
system work faster and use less power.
 Speed: C++ is known for its speed. It allows developers to write
code that runs quickly, making it suitable for applications where
fast responses are crucial, such as in control systems or real-
time operations.
18
Why C++ ???
 Size Optimization: C++ gives developers control over the size
of the code they write. In embedded systems, where storage
space may be limited, this ability to optimize code size is
valuable.
 Ready-Made Tools: There are many tools available for C++
that make the job of programming embedded systems easier.
These tools help catch mistakes and speed up the process of
writing code.
 Sharing and Compatibility: C++ code can often be used on
different types of embedded systems without much change.
This is handy because different systems might need the same
code to do similar tasks.
19
Why C++ ???
 Community Help: Many people use C++, so there's a big
community that shares tips, advice, and ready-made pieces of
code. This helps programmers learn and solve problems faster.
 Safety Features: C++ has some built-in safety features that
help catch mistakes before they cause problems. This is
important in situations where errors could be serious, like in a
car or a medical device.
 Widespread Use: C++ has been used successfully in many
types of embedded systems, like in cars, gadgets, and industrial
machines. This means there's a lot of experience and knowledge
about how to use C++ effectively in these kinds of projects.
20
SECTION 4: INTRODUCTION TO
ARDUINO IDE AND
SIMULATIONS

In earlier discussions on the fundamentals of


programming we talked about IDEs in this section we
build on that for Arduino IDE.

We’ll discuss
Installation of the Arduino IDE
Setup for ESP32
Features and Shortcuts
Simulating Embedded system development using
TinkerCad 21
ARDUINO IDE

Sketchbook Manager: for organizing and managing sketches


Board Manager: downloading and installing various microcontroller types
Library Manager: installing libraries for programming
Debugger: troubleshooting sketches
Search Tab

Serial Monitor and Plotter

22
INSTALLATION AND SETUP

The installation files will be shared in the class group, alternatively it can be downloaded at
https://www.arduino.cc/en/software#future-version-of-the-arduino-ide

The Arduino MCU board will be used throughout this course which is automatically installed
 Now you have the IDE ready for programming!
 In the board selector Type “Arduino UNO” and select it to be your default board

23
ARDUINO IDE SETUP

24
SIMULATION WITH TINKERCAD

 Visit https://www.tinkercad.com/joinclass/K3DCYQ9EB
 Login using your student ID name as your Nickname
 You can optionally sign up with a personal account for your personal practices and projects

25
SECTION 5: BASIC ARDUINO
COMMANDS / FUNCTIONS
A Brief Evolution of Arduino

• Inception (2003): Arduino is developed by Massimo


Banzi and collaborators at the Interaction Design
Institute Ivrea in Italy to simplify microcontroller
prototyping for students.
• First Release (2005): The Arduino NG board is officially
released, featuring the ATmega168 microcontroller and
a user-friendly IDE, marking the start of Arduino's
journey.

26
A Brief Evolution of Arduino
• Open Source Community (2005 onward): Arduino fosters a collaborative
community, with users contributing libraries, tutorials, and projects, creating a
vibrant ecosystem.
• Board Evolution: Arduino undergoes continuous development, releasing models
like Arduino Uno, Mega, and Nano, each offering improved features and
capabilities.
• Widespread Adoption: Arduino gains popularity among hobbyists, makers, and
professionals, finding applications in interactive art, home automation, and
robotics.
• Diverse Impact (2010s): Arduino's versatility leads to adoption in industrial
automation and IoT, making it a standard tool in education and showcasing its
relevance in various technological fields. 27
Arduino Terminologies
• Serial Monitor: A tool within the Arduino IDE that allows
communication between the Arduino board and the computer
via serial communication. It is commonly used for debugging and
real-time data monitoring.
• Library: Pre-written code modules that provide ready-to-use
functions for specific tasks. E.g. The <iostream>, <fstream> …
• Board: Refers to the specific model of Microcontroller being
used (e.g., Arduino Uno, Arduino Nano, ESP32). The choice of
board determines the hardware features and capabilities
available.
• Port: The communication port through which the Arduino board
connects to the computer. Users select the appropriate port in
the Arduino IDE before uploading code.
28
Arduino Terminologies
• Digital Pin: Input or output pins on an Arduino board that can be used
to read digital signals (HIGH or LOW) or send digital signals to
connected components.
• Analog Pin: Input pins that can read analog signals, providing a range
of values. Useful for interfacing with analog sensors or reading analog
voltages.
• PWM (Pulse Width Modulation): A technique used to simulate analog
output using digital pins. It allows users to control the intensity of an
output signal, like the brightness of an LED.
• Upload: The process of transferring the compiled Arduino sketch from
the computer to the Arduino microcontroller.
• Verify: Verifying the code ensures that there are no syntax errors in
the sketch. The Verify process checks the code for correctness and
highlights any errors or warnings without actually uploading the code
to the Arduino board. 29
The Arduino Program

• An Arduino programme is called a sketch and must have the


same name as it parent folder.
• A folder should only contain one sketch otherwise there’ll be
compilation errors
• Arduino sketches should have the .ino file extension. While
other file extensions may work, using .ino ensures that the
Arduino IDE recognizes the file as a sketch. In other cases the
.cpp extension can be used with an import of the Arduino
header file.
• Like “int main()” is to a C++ program an Arduino program
requires Two functions “void setup” and “void loop” .

30
The Setup Function
Purpose: The setup function is used for one-time setup tasks. It is executed
once when the Arduino board is powered on or reset.

Syntax:
void setup() {
// Initialization code goes here
}

Common Usage:
• Configuring pin modes (e.g., setting a pin as an input or output).
• Initializing serial communication.
• Setting up initial conditions for variables.
• Configuring external libraries or devices.
31
The Loop Function
Purpose: The loop function contains the main program logic and is executed
continuously in a loop after the setup function completes. It forms the core of
the Arduino sketch.

Syntax:
void loop() {
// Main program logic goes here
}

Common Usage:
• Reading sensor data.
• Controlling actuators.
• Responding to external events or inputs.
• Implementing iterative tasks. 32
pinMode(pin, mode)

digitalWrite(pin, value)

digitalRead(pin)
Functions analogWrite(pin, value)
You should analogRead(pin)
know delay(ms)

Serial.begin(baudRate)

Serial.print(value)
33
ARDUINO BASIC FUNCTIONS
1. pinMode(pin, mode):
Purpose: Configures a specified pin to behave as either an INPUT or OUTPUT.
Example: pinMode(13, OUTPUT); sets pin 13 as an output. And if mode =
INPUT, pin 13 becomes an input component

2. digitalWrite(pin, value):
Purpose: Writes a HIGH or LOW value to a digital pin.
Example: digitalWrite(13, HIGH); sets pin 13 to HIGH voltage(on). And to set
an off the value should be LOW

3. digitalRead(pin):
Purpose: Reads the digital value (HIGH or LOW) from a specified digital pin.
Example: int buttonState = digitalRead(2); reads the state of a button
connected to pin 2. 34
ARDUINO BASIC FUNCTIONS
4. analogWrite(pin, value):
Purpose: Writes an analog value (PWM) to a PWM-capable pin (usually
denoted by a ~ symbol).
Example: analogWrite(9, 128); sets a PWM value of 128 on pin 9.

5. analogRead(pin):
Purpose: Reads an analog value (0 to 1023) from an analog pin.
Example: float sensorValue = analogRead(A0); reads the analog value from
pin A0.

6. delay(ms):
Purpose: Pauses the execution of the program for the specified number of
milliseconds.
Example: delay(1000); pauses the program for one second. Since 1s = 1000ms 35
ARDUINO BASIC FUNCTIONS
7. Serial.begin(baudRate):
Purpose: Initializes serial communication with the specified baud rate.
Example: Serial.begin(9600); initializes serial communication with a baud rate
of 9600. This serves as a pathway for information exchange.

8. Serial.print(value), Serial.println(value):
Purpose: Outputs data to the serial monitor, works the same as cout in C++
Example: Serial.print("Hello "); Serial.println("Arduino!"); prints a message to
the serial monitor.

36
SECTION 6: THE UNO BOARD
AND WORKING WITH LEDs

• The UNO board is designed for ease of use,


versatility, and compatibility with a broad range of
projects.
• The Arduino Uno is powered by the Atmel
ATmega328P microcontroller, which operates at a
clock frequency of 16 MHz with a 32 KB of flash
memory, where the Arduino sketch (program) is
stored.

37
FEATURES OF THE UNO BOARD
• Memory:
32 KB Flash memory.
2 KB SRAM.
1 KB EEPROM.

• Digital I/O Pins:


14 digital input/output pins.
6 PWM (Pulse Width Modulation) outputs.

• Analog Input Pins:


6 analog input pins (A0 to A5).

• Voltage Regulator:
Onboard voltage regulator for 7-12V DC input or USB (5V) power.
38
THE UNO PINOUT

39
THE UNO PINOUT

1. Digital Pins (D0-D13): These pins can be used for both input and
output. They support digital signals, meaning they can be either HIGH
(5V) or LOW (0V).

2. Analog Pins (A0-A5): These pins can read analog signals, providing
a range of values between 0 and 1023. They are often used for
reading sensor values or other analog inputs.

3. Power Pins:
1. 5V: This pin provides a regulated 5V output, typically used to
power external components.
2. 3.3V: A 3.3V regulated output for lower voltage components.
3. GND (Ground): Ground pins are used as a reference point for
electrical potential. 40
THE UNO PINOUT

 PWM Pins (D3, D5, D6, D9, D10, D11): These pins support Pulse
Width Modulation, allowing for analog-like control of devices such
as LEDs or motor speed.

 Reset (RESET): This pin is used to reset the microcontroller.

 Serial Communication Pins (RX, TX): These pins are used for serial
communication (UART) and are crucial for programming the
Arduino and interfacing with other devices.

 External Interrupt Pins (D2, D3): These pins can be used to trigger
interrupts based on external events, allowing the microcontroller
to respond quickly to specific signals.
41
Your First Arduino Program

1. void setup() {
2. Serial.begin(9600);
3.
4. Serial.print("Hello Arduino World!!!\n");
5. } //Anything here runs just once
6.
7.
8. void loop() {
9.
10. Serial.print("Hello to everyone, many times");
11.
12. } // This function runs multiple times

42
What it all means

Line 1 : Starts the program with the setup function, which is mainly used for
initializations

Line 2 : We setup the Serial operations for communications using a buad


rate of 9600
Line 4 : An introductory message is printed out to serial using the print
function. The println function can also be used which works like a C++ cout
with an endl attached

Line 8 : Begins the loop function which will iterate till the mcu is disconnected
or turned off
43
Now let’s work with LEDs

• In this section we’ll be using our TinkerCad circuit simulation so join the classroom page an let’s get it started
• Use this link https://www.tinkercad.com/dashboard?type=circuits&collection=designs
• And choose Create > Circuit
• We will try out a basic breadboard connection with our simulator

• Now choose a breadboard from the right panel by dragging it to the workspace

This shows the basic connections in a


breadboard

A picture of the right panel in TinkerCad


44
Breadboard basic connections
The led has to be lit when the simulation is started; try the activity in your class page.

45
First blinking program

What algorithm are we going to use for a led to blink??

1. First we turn on an Led


2. We wait for some seconds
3. Turn off the Led
4. Wait for some seconds
5. Repeat from step 1

A picture of breadboard connection for the blinking program

46
Traffic Lights Control Program
Now let’s apply the led blinking concepts to control 3 LEDs; Red, yellow and
green in the form of traffic lights

Steps:
1. Turn the red Led on
2. Wait for some seconds and turn it off
3. Turn the yellow Led on
4. Wait for some seconds and turn it off
5. Turn the green Led on
6. Wait for some seconds and turn it off
7. Repeat step 1

47
Traffic Lights Control Program (Cont’d)
• Each led has it own variable to hold a pin number, which is then
initialized as output using the pinMode function.
• This program simulates a simple traffic light sequence where the red
light is on for 5 seconds, followed by the yellow light for 2 seconds, and
then the green light for 5 seconds.
• Modify the program in order to get an alert in the serial monitor
whenever a led goes on or off
• The blinking script can be placed in a function to make the code much
cleaner

48
A Basic Binary Counter Program

Binary Counter: A Digital Number Sequence 0000 - 0


0001 - 1
0010 - 2
A binary counter is a fundamental concept in digital
0011 - 3
electronics. Instead of using our familiar base-10 system,
0100 - 4
computers use a binary system with only two digits: 0 and 1. 0101 - 5
0110 - 6
Imagine a set of lights representing binary digits. Starting 0111 - 7
with all lights off (0000 in binary), the counter increments 1000 - 8
through binary numbers, creating a sequence like 0001, 0010, 1001 - 9
0011, and so on. Once it reaches the highest binary number, 1010 - 10
it resets and continues. 1011 - 11
1100 - 12
1101 - 13
Binary counters are crucial in digital systems, helping
1110 – 14
computers perform tasks and manage processes. 1111 - 15
Understanding them provides insight into the language of
computers, making them a key concept in the world of digital
technology. 49
A Basic Binary Counter Program

50
SECTION 7: ANALOG AND
DIGITAL SIGNALS AND THE
SERIAL PORT
• Digital signals are binary, meaning they can only have
two states: HIGH (1) or LOW (0). In Arduino, digital pins
are primarily used for digital signals.
• Analog signals represent a continuous range of values. In
Arduino, analog signals are typically read from sensors
like potentiometers, temperature sensors, or light
sensors.
• Analog-to-Digital Conversion (ADC): Arduino boards have
built-in Analog-to-Digital Converters (ADC) that convert
analog signals to discrete digital values ranging from 0 to
1023. The analogRead function is used to read analog
signals from sensors connected to analog pins.
51
Measuring Voltage and Current

• The Arduino board can function as a multimeter with a little boost.


• We can measure voltage and current with a reference resistance known.
• The operational voltage of the Arduino board is 5V

• So in this section we will use Arduino to measure voltage and current in a


simple circuit.
• Mapping analog readings to voltage and applying Ohm's Law.
𝑽𝑽 = 𝑰𝑰𝑰𝑰

52
Measuring Voltage and Current

53
What it all means

The program uses an analog pin to measure the voltage of the component
its connected to using the analogRead().

The map function on line 18. This function is used to scale the raw analog
value (which ranges from 0 to 1023) to the desired voltage range (0 to 5.0).

At a threshold the led will turn to show that there’s voltage in the pin.

The Pin can be reinserted anywhere to get the voltage at that point. A
voltmeter is used to verification.
54
Measuring Voltage and Current
Here is an example code measuring the current (I)

55
Pulse Width Modulation (PWM)
• PWM stands for Pulse Width Modulation. It's a technique used in electronics to generate
analog-like signals with digital devices, such as microcontrollers like the Arduino.
• PWM is widely used for tasks like controlling the speed of motors, adjusting the brightness
of LEDs, and creating sound in electronic projects.
• Only pins with the ‘~’ sign can use this property i.e. pins {3, 5, 6, 9, 10 and 11}
• Commonly used Arduino functions for PWM include analogWrite().

• PWM involves rapidly turning a signal (typically a square wave) on and off at varying
intervals.
• The average voltage over a given period corresponds to the desired analog value.

• As analog signals is from (0-1023) , the signal range for pwm is (0-255)

56
Pulse Width Modulation (PWM) Cont’d
Here is an example code of using pwm to change the brightness of an Led.
Make sure your pin is connected to a pwm enabled pin!!
Observe what happens in the Serial monitor

57
Serial Monitor and Plotter

• The Serial Monitor is a crucial tool in Arduino programming, providing a simple interface to
communicate with and monitor the Arduino board.
• It allows the Arduino to send text or numerical data back to the computer, facilitating debugging
and interaction with the code in real-time.

• Programmers use the Serial.begin() function to initialize serial communication and utilize
commands like Serial.print() and Serial.println() to send information to the Serial Monitor.
• This tool aids in understanding program behavior, verifying sensor readings, and debugging
code during development.
• The baud rate of the device needs to be the same as the one in the activation function
Serial.begin(baudRate) before data transfer can be observed in Arduino Uno it is 9600.

58
Reading values from the Serial Monitor

In this section we will learn how to send values into our Serial Monitor. It is a similar
operation as using cin or getline in C++

We use the following functions for the various datatypes


Int –- Serial.parseInt();
Float --- Serial.parseFloat();
Char --- Serial.read();
String --- Serial.readString();

To concatenate a value with a string in the print/println function place it in the String()
function eg. Serial.println(“Your age is: “ + String(age));

59
Reading values from the Serial Monitor
An example of taking an int value from serial monitor input

• On Line 13, we use a while


function to wait till when a user
inputs something, similar to
System(“pause”).
• Serial.available() shows that there
is available data being received in
our serial communication line.
• After a value is entered it is stored
in a variable “number”.

60
Serial Plotter

• The Serial Plotter is an extension of the Serial Monitor, specifically designed for
visualizing numerical data as graphs. It enables real-time plotting of data sent from
the Arduino, helping to analyze trends, patterns, or changes over time.
• Programmers can use the Serial.print() command to send numerical values, and the
Serial Plotter plots these values graphically.

• This tool is particularly valuable when working with sensors, as it provides a


dynamic and visual representation of data trends, making it easier to interpret and
debug complex systems.
• The Serial Plotter is a powerful tool for engineers and hobbyists working on
projects that involve data visualization and analysis.

61
Serial Plotter
Visualizing a plot of sine and cosine

62
Exercise

Design a program that takes brightness values from a user (In percentages) to control
the brightness of an LED.

Hint:
Map percentage values to pwm ranged values

63
SECTION 8: WORKING WITH
OUTPUT COMPONENTS
• RGB LEDs:
RGB LEDs go beyond simple illumination; they are miniature canvases of
color. With individual red, green, and blue diodes, they create a spectrum
of hues. Perfect for mood lighting or eye-catching displays, RGB LEDs turn
code into a visual masterpiece.
• Active Buzzers:
Active buzzers are the audible storytellers. They emit a continuous tone
when powered, making them ideal for alarms, alerts, or interactive sound
effects. Easy to integrate into Arduino projects.
• Passive Buzzers:
Passive buzzers bring melody to the mix. Requiring an external oscillating
signal, they act as musical transducers. Perfect for generating specific
tones or tunes, passive buzzers are the choice for projects with a melodic
touch. 64
Working with RGB LEDs

• You can produce almost any color by combining those three colors.
• With an RGB LED you can, of course, produce red, green, and blue light,
and by configuring the intensity of each LED, you can produce other
colors as well.

• To produce other colors, you can combine the three colors in different
intensities. To adjust the intensity of each LED you can use a PWM signal.

• To have an idea on how to combine the colors, take a look at the following
chart. This is the simplest color mixing chart, but gives you an idea how it
works and how to produce different colors.

65
Working with RGB LEDs

66
Working with RGB LEDs
Now, let’s look at program where we take user
colours and output it with the RGB.

67
Active Buzzers
Active buzzers typically operate within a specific voltage range, and it's crucial to
adhere to these requirements for optimal performance. Understanding the
buzzer's voltage specifications ensures proper functioning in diverse electronic
setups.

While active buzzers are known for continuous tone generation, their frequency
range might vary. Some models may offer a wider range of frequencies,
providing flexibility in creating diverse sound effects or musical notes in projects.

By sending a digital HIGH signal to the buzzer, you can activate the sound
generation.

The tone() function in Arduino generates a square wave of a specified frequency


on a specified pin, allowing for the production of sound through a connected
buzzer or speaker.
tone(pin, frequency, duration);
68
Active Buzzers

Let’s look at a simple program with the buzzer

69
Active Buzzers
A program to play Jingle bells using just the buzzer.

70
Active vs Passive Buzzers

Feature Active Buzzer Passive Buzzer


No (requires external
Internal Oscillator Yes
signal)
Easier, requires power
Ease of Use Requires external circuitry
supply
More control over sound,
Limited control,
Control and Flexibility external signal
continuous tone
modulation
Compatible with digital Requires analog signal,
Compatibility signals, easily interfaced may need additional
with microcontrollers circuitry
Melody generation,
Continuous tones, simple musical instruments,
Applications
sound effects, alarms specific sound
requirements 71
Exercise

Create a program to turn an alert sound on or off and depending on the


specific alert name it’ll produce a different sound

72
SECTION 8: WORKING WITH
INPUT COMPONENTS
• Pushbuttons:
A pushbutton is a simple, momentary switch that completes or interrupts an
electrical circuit when pressed. When the button is pressed, it closes the circuit,
allowing current to flow, and when released, the circuit opens.
• Potentiometer:
A potentiometer, or pot, is a variable resistor with three terminals, allowing it to
function as an adjustable voltage divider. By turning its shaft, the resistance
between the middle terminal and either of the outer terminals changes, providing a
variable voltage output.
• Photoresistor:
A photoresistor, or light-dependent resistor (LDR), is a component whose resistance
changes in response to the intensity of incident light. As illumination increases, the
resistance decreases, and vice versa. Photoresistors find applications in light-sensing
circuits, where their varying resistance can be utilized to control the behavior
73 of
other components.
Pushbuttons
Pushbuttons, commonly referred to as momentary switches, represent
foundational electronic components integral to user input mechanisms.
These devices facilitate interaction by momentarily altering the electrical
state of a circuit, initiating specific actions contingent upon the transition
between their pressed and released states.

Momentary Action: Pushbuttons operate on a momentary action


principle, meaning they are active only when physically pressed, reverting
to their initial state upon release.

Two States: These devices embody a binary state system, toggling


between "pressed" and "not pressed," consequently influencing the
continuity of the associated electrical circuit.

Digital Input: Widely utilized in microcontroller-based projects as digital


input elements, pushbuttons effectively respond to state changes
triggered by user interaction.
74
Switching an Led with a Pushbutton

75
Switching an Led with a Pushbutton
In the previous example we can only turn it on whilst we still press it. How about we make about program
remember the state of the button.

76
Led brightness control with a Pushbutton

77
Led brightness control with a Pushbutton CONT’D

Schematic Diagram for the previous simulation


78
Potentiometers

Variable Resistance: Potentiometers possess the ability to alter


resistance, adjusting the flow of electrical current through the device.

Three Terminals: Structurally, potentiometers consist of three


terminals—two outer terminals and a central terminal. The central
terminal is connected to a moveable wiper that slides along a
resistive track.

Voltage Divider Functionality: Acting as voltage dividers,


potentiometers split the input voltage proportionally based on the
position of the wiper along the resistive track.

Analog Control: These components are frequently utilized for analog


control applications, allowing users to modulate parameters such as
volume, brightness, or speed.
79
Led brightness with a Potentiometers

80
Changing colours with a Potentiometers

81
Changing colours with a Potentiometers (Cont’d)

82
Photoresistors
Resistance Variation: Photoresistors are made of semiconductor materials that
experience changes in conductivity when exposed to light. This results in a
variable resistance that is inversely proportional to the light intensity.

Operating Principle: The photoresistor operates on the principle of the


photoconductive effect, where incident photons create electron-hole pairs,
influencing the material's conductivity.

Low Light Resistance: In low-light conditions, the resistance of the photoresistor


is relatively high, limiting the current flow through the device.

High Light Resistance: As light intensity increases, the photoresistor's resistance


decreases, allowing more current to flow.

Applications: Widely used for ambient light sensing, automatic lighting controls,
camera exposure adjustments, and in various electronic circuits requiring light-
dependent responses. 83
Photoresistors Example
This example uses the photoresistor as the main input device together with leds and a buzzer

84
Photoresistors Example (Cont’d)

85
Reminder

You are to make sure all the simulations have been designed/prototyped by
everyone and the expected results have been achieved.

Practice and read instructions/ tutorials online


The applications of embedded systems are numerous explore them.

Projects will be assigned to the various groups and every member’s participation
will be required

THANK YOU.
86

You might also like