Final Lab Manual
Final Lab Manual
Arduino Experiment 1
Basic Electronic Components and Tools
INTRODUCTION:
Resistor, capacitor, transistor, diode, operational amplifier, resistor array, logic gate, and others
are some of the basic electronic components.
An open-source electronics platform called Arduino is built on simple hardware and software. A
motor can be started, an LED can be turned on, and something may be published online by using
an Arduino board to receive inputs like light on a sensor, a finger on a button, or a tweet. Sending
a set of instructions to the board's microcontroller will instruct your board what to do. You
achieve this by using the Arduino Software (IDE), which is based on Processing, and the Wiring-
based Arduino Programming Language.
Over the years, countless of projects, ranging from simple household items to intricate scientific
instruments, have used Arduino as their brain. This open-source platform has attracted a global
community of makers, including students, hobbyists, artists, programmers, and professionals.
Their efforts have added up to an astounding quantity of accessible knowledge that may be very
helpful to both beginners and specialists.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
Page |2
In each box located on the left side, illustrate the given electronic component or tools. Make
your drawing neat and presentable. On the opposite side, write the functions(s) of the item.
1. Resistor
2. Capacitors
3. Transistor
4. Diode
5. Battery
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
Page |3
6. LEDs/RGB-LED
7. Potentiometers
8. Buzzers
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
Page |4
14. DC Motor
17. Breadboard
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
Page |5
19. Multimeter
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
Page |6
1. Which of the electronic components and tools are you most familiar with? Explain why?
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________
2. Which of them are you not familiar with? Write three (3).
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
Page |7
Arduino Experiment 2
Blinking an LED
INTRODUCTION:
Small, bright lights called LEDs, or Light Emitting Diodes, are used in a variety of applications.
With LEDs that are blinking, we'll get to work. It's as easy as turning on and off a light. Even
though it might not seem like much, establishing this baseline is essential because it will provide
you with a strong starting point as we move toward more challenging experiments. You'll get
hands-on practice using the Fritzing application for breadboarding, the Arduino Sketch coding
environment for the Arduino Uno, and the Proteus ISIS simulation environment for your
experiment.
What is LED?
When an electric current passes through a semiconductor device called a light-emitting diode
(LED), the LED emits light. When current flows through an LED, the electrons and holes recombine
and produce light. LEDs only let current flow in one direction—forward—and stop it from going
the other way.
P-N junctions in light-emitting diodes are heavily doped. When forward-biased, an LED will emit
colored light at a particular spectral wavelength depending on the semiconductor material
employed and the quantity of doping. An LED is enclosed with a transparent cover, as seen in the
image, to allow the light that is emitted to flow out.
LED Symbol
The LED symbol is the standard symbol for a diode, with the addition of two small arrows
denoting the emission of light.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
Page |8
Upon recombination, the energy is released in the form of photons. The energy is emitted as heat
in standard diodes. However, energy is discharged as photons in light-emitting diodes. This
phenomenon is known as electroluminescence. An electrical and optical phenomenon called
electroluminescence occurs when an electric current is sent through a substance, causing it to
emit light. The light intensity grows and reaches a maximum as the forward voltage rises.
Applications for LEDs include optical communication, remote-controlled operations, security and
alarm systems, robots, and more. Because of its durability, low power requirements, quick
response time, and quick switching capabilities, it is used in a variety of applications. Here are a
few standards that LED adheres to:
LEDs are employed for a variety of purposes, including TV backlighting, displays, automobiles,
and light-dimmer applications.
Types of LED
The list of several LED kinds created utilizing semiconductors is provided below:
• Miniature LEDs
• Red, Green, and Blue LEDs;
• High-Power LEDs;
• Flash LEDs;
• Bi and Tri-Color LEDs;
• Alphanumeric LED
• LED lighting
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
Page |9
LEDs have a few advantages over incandescent power lamps, including lower power consumption
and lower operating voltage requirements. LEDs require no warm-up period. They are durable
and long-lasting, emit monochromatic light, and have a long lifespan.
PART I. BREADBOARDING.
Below are the schematic diagram and parts needed to connect the circuit on a breadboard.
Draw the equivalent breadboard connection.
1. Arduino Uno
2. Breadboard
3. M-M Jumper Wires
4. LED
5. 330 Ohms Resistor
NOTE:
• Be aware of the
polarity of the
LED.
• Use +5V and
GND from
Arduino as
power source for
your circuit.
FRITZING:
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 10
Below are the Arduino Sketch code and the equivalent Proteus ISIS circuit connection. Compile
the code and retrieve the .hex file needed for the simulation.
PROTEUS ISIS:
Parts needed:
1. ARDUINO UNO R3
2. LED-YELLOW
3. RES
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 11
1. Try changing the 1000 in the code delay( ) functions to different numbers and see how it
affects the timing. Smaller values will make the loop run faster. Explain why?
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________
2. Decrease the delay to 10ms. Can you still see it blink? Find the smallest delay that you
can still see a blink. What is this frequency?
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________
3. Modify the code above to resemble a heartbeat. Write the code below.
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 12
4. Add one more LED and make it blink alternately. Write the code below.
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 13
Arduino Experiment 3
Potentiometer
INTRODUCTION:
A potentiometer is defined.
Since potentiometers are simply resistors but have variable resistance, their symbols are similar
to those of resistors. The potentiometer sign can be seen in this picture.
Now let's examine the operation of a potentiometer. The highest value (rated value) of that POT
will always be measured if you test the resistance between the outside terminals. For instance,
you will read the full 10 K between the outer terminals in the case of a 10 K POT. However, you
will obtain a result that is based on the location of the wiper if you measure the resistance
between one of the outer terminals and the wiper terminal. In the case of a 10 K pot, it can thus
range from 0 K to 10 K. Therefore, depending on the terminals utilized, the potentiometer can
be employed as a straightforward variable resistor, also referred to as a rheostat or a voltage
divider.
As Rheostat
By using just two of its terminals—the wiper and one of the two outer terminals—a
potentiometer can function as a rheostat. The POT serves as a two terminal variable resistor in
this situation.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 14
Source: www.electronicshub.org
As Voltage Divider
Potentiometers can also be utilized as voltage dividers, which is another beneficial purpose for
them. Two resistors connected in series make up a voltage divider circuit, if you recall. At the
ends of the resistors, a voltage is supplied, and an output voltage is measured across a resistor.
Use this straightforward circuit to change a high voltage to a low voltage. You may create a
voltage divider with a similar design using a potentiometer and all three terminals.
Source: www.electronicshub.org
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 15
The wiper and the outer terminal of the POT, which is linked to the GND of the input supply,
receive an output voltage when an input voltage is supplied between its two outer terminals.
Since a POT enables you to change the resistance, you can essentially change the Voltage
Divider's output voltage. This voltage divider hence has a variable output voltage.
Despite having the same purpose, there are numerous varieties of potentiometers available for
a range of uses. Following are some examples of common POT types: Rotary POT, Single Turn
POT, Multi-Turn POT, Linear POT, Dual Gang POT, Servo POT, Trimmer POT, Concentric POT,
Preset POT, and Digital POT are all examples of pots.
A control knob is a potentiometer. It has the same kind of control as one used to adjust the
volume or dim a lamp, for example. As it is turned, a potentiometer changes resistance. The
Arduino can sense the position of the knob by utilizing it as a "voltage divider" and use that value
to control anything you like (such as the rate at which an LED blinks, as we're doing here).
Hardware connections:
You'll be working with a potentiometer in this circuit. A variable resistor is another name for a
potentiometer. The middle pin produces a voltage between 0 and 5, depending on the position
of the potentiometer's knob when it is linked with 5 volts across its two outer pins. In this circuit,
you'll discover how to utilize a potentiometer to regulate an LED's brightness.
Potentiometers have three pins. The outer pins are wired to power and ground when we're
utilizing it as a voltage divider. The signal will be on the center pin.
(TIP: You can swap the 5V and GND pins to reverse the direction of the knob that seems
"backward" once your program has started running.)
Connect your LED's positive (longer leg) end to Arduino digital pin 13 (or another digital pin, but
make sure you modify the code accordingly).
Your LED's shorter, negative leg should be connected to an orange-orange-brown, 330 Ohm
resistor.
You will continue to use Fritzing for breadboarding, Arduino Sketch for programming your
Arduino Uno, and actual hardware to connect the circuit.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 16
PART I. BREADBOARDING.
Below are the schematic diagram and parts needed to connect the circuit on a breadboard. Draw
the equivalent breadboard connection.
1. Arduino Uno
2. Breadboard
3. M-M Jumper Wires
4. LED
5. 330 Ohms Resistor
6. Potentiometer
NOTE:
• Be aware of the
polarity of the
LED.
• Use +5V and GND
from Arduino as
power source for
your circuit.
FRITZING:
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 17
Below are the Arduino Sketch code and the equivalent Proteus ISIS circuit connection. Compile
the code and upload the file to your Arduino Uno.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 18
1. Discuss how the circuit works. What is the use of potentiometer in the circuit? Explain
your answer.
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________
2. Discuss how the following parts of the code affects the functionality of the circuit:
a. int sensorValue;
b. sensorValue – analogRead(sensorPin);
c. delay(sensorValue);
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 19
3. Interchange the +5v and GND connected to your potentiometer. With this connection,
what is the effect of the potentiometer in the circuit? Discuss your observation.
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________
4. Discuss the difference between digital and analog inputs. You may elaborate on your
answers by giving specific examples.
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 20
Arduino Experiment 4
Push Button Switch
INTRODUCTION:
A push button switch is a mechanical device that uses manual pressure to activate an internal
switching mechanism in order to regulate an electrical circuit. Depending on the needs of the
design, they are available in a number of forms, dimensions, and arrangements.
A straightforward in-out actuation mechanism is used in push button switches. They can be used
to start (on) or stop (break) a circuit. As an alternative, they can start/stop a certain function or
provide input for the user interface of a piece of equipment.
Push button switches can be divided into two types: momentary switches, whose functions only
last as long as the user is pressing the button, and maintained switches, whose functions are
locked in place after activation.
Push buttons can either be ordinarily open (NO) or normally closed (NC), depending on their
state. When activated, typically open ("OFF") switches complete the circuit, whereas normally
closed ("ON") switches interrupt the circuit. Push button switches can also be further classified
under this category based on the switching circuits they employ.
Single pole, single throw (SPST), single pole, double throw (SPDT), double pole, single throw
(DPST), and double pole, double throw (DPDT) are the most typical types. Since an SPST only has
two terminals, it can only open and close one circuit at a time. It could be used, for instance, to
turn on and off a motor.
An SPDT can control two distinct circuits because it has three terminals. As a result, it can be used
to switch between powering two different LEDs or to switch an item of equipment from a
sleeping state to an active one. Two separate circuits may be controlled simultaneously using
DPST and DPDT switch configurations. If one has a high voltage and the other a low voltage, for
example.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 21
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 22
In this experiment, we'll see how to use an I/O port and a button switch to turn on or off a single
LED. The input and output ports are referred to as the "I/O port". We'll read the output of an
external device using the input feature of the Arduino Uno I/O port. With the help of a debounce
and a button, we'll be able to operate an LED in two different ways.
Principle
A typical part used to operate electronic gadgets is a button. To connect or detach circuits, they
are typically employed as switches. Although there are many different types and sizes of buttons,
the one utilized in this experiment will be a 6mm mini-button, as seen in the images below. The
pins that are indicated by arrows of the same color are intended to be linked.
When the button is pressed, the pins pointed by the blue arrows will connect to the pins pointed
by the red arrows.
Generally, the button switch is directly connected in an LED circuit in order to turn the LED on or
off. This connection is relatively simple. However, sometimes the LED will light up automatically
without pressing the button, which is caused by various interferences. In order to avoid these
external interferences, we will connect a pull-down resistor, that is, connect a 1K–10KΩ resistor
between the button port and the GND. The function of the pull-down resistor is to consume
external interferences while connected to the GND for as long as the button switch is turned off.
This circuit connection is widely used in numerous circuits and electronic devices. For example,
if you press any button on your mobile phone, the backlight will light up.
Buttons are a very simple, very practical technology that is surprisingly easy to master.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 23
PART I. BREADBOARDING.
Below are the schematic diagram and parts needed to connect the circuit on a breadboard. Draw
the equivalent breadboard connection.
SCHEMATIC DIAGRAM
PARTS NEEDED:
1. Arduino Uno
2. Breadboard
3. M-M Jumper Wires
4. LED
5. 330 Ohms Resistor
6. 10k Ohms Resistor
7. Push Button Switch
NOTE:
• Be aware of the
polarity of the
LED.
• Use +5V and GND
from Arduino as
power source for
your circuit.
FRITZING:
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 24
Below are the Arduino Sketch codes. Compile the codes and upload the file to your Arduino
Uno/Mega.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 25
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 26
1. In “Control LED with Push Button “, what happens when the push button is pressed?
Alter the program to have an opposite behaviour. Write the equivalent code below.
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
______________________________________________
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 27
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 28
Arduino Experiment 5
Light Dependent Resistor (LDR) / Photo Resistor
INTRODUCTION:
Electronic components known as light dependent resistors, LDRs, or photoresistors are used to
detect light and modify a circuit's behavior based on the intensity of the light.
When it's required to detect the presence or level of light, electronic circuit designs frequently
include light-dependent resistors, also known as LDRs or photoresistors.
The carbon film resistor, metal oxide film resistor, metal film resistor, and similar resistors that
are frequently used in other electronic systems are very different from LDRs. They are made
expressly for the change in resistance caused by their light sensitivity.
These electronic parts are known by a number of names, including light-dependent resistors
(LDR), photoresistors, photocells, and photoconductors.
LDRs or photo-resistors are very practical to utilize in many electronic circuit designs, while other
electronic components like photodiodes or photo-transistors can also be used. For variations in
light level, they offer a significant shift in resistance.
LDRs have been employed in a wide range of applications due to their inexpensive cost, ease of
fabrication, and simplicity of usage. LDRs are still utilized in a number of applications where it is
important to detect light levels, even though they were once used in photographic light meters.
Light-dependent resistors are widely available; typically, electronic component distributors stock
them, and given how the supply chain for the electronics industry is now structured, this is the
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 29
typical method of acquiring them. Large and small distributors of electronic components usually
offer a wide assortment.
An LDR or photoresistor's resistance values frequently range from several megaohms in complete
darkness to a few hundred ohms under intense light.
LDRs are simple to use and come in a variety of LDR circuits, and they have a wide range of
resistance. The wavelength of the incident light affects how sensitive light-dependent resistors
or photoresistors are.
For LDRs to have their light-sensitive characteristics, semiconductor materials are used in their
construction. There are other materials that can be employed, but cadmium sulfide is one that is
frequently utilized for these photoresistors. However, the use of these cells is currently
prohibited in Europe due to cadmium's negative environmental effects.
These photoresistors are made of semiconductor material, but they differ from other
photodetectors like photodiodes and phototransistors in that they lack a PN junction, making
them totally passive devices.
The resistor circuit symbol serves as the foundation for the LDR symbol, which is used in
electronic circuits, but adds arrows to represent light. Thus, it adheres to the same convention
as photodiode and phototransistor circuit representations, which employ arrows to depict the
direction of light for these components.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 30
Both the more modern rectangular box resistor symbol and the more traditional zig-zag line
resistor circuit symbols are used to represent the light-dependent resistor/photoresistor circuits.
Frequently, the symbol for a light-dependent resistor may not have a circle around it. This is
frequently done on electronic circuit schematics to conserve space and lessen the complexity of
the design by reducing the number of lines and circles.
Without getting into complex explanations, the fundamentals of how an LDR operates are rather
simple to comprehend. An electrical current is made up of electrons moving through a material,
which must first be understood.
A significant number of free electrons in good conductors are capable of drifting in a specific
direction in response to a potential difference. Because there are so few free electrons in
insulators with high resistance, it is difficult to transport those electrons and for a current to flow.
Any semiconductor material with a high resistance is used to create an LDR or photoresistor. The
fact that so few electrons are free and able to move, while the vast majority are trapped in the
crystal lattice and unable to do so, accounts for its high resistance. As a result, the LDR resistance
is strong in this state.
The semiconductor lattice absorbs light photons when they strike it, transferring some of their
energy to the electrons in the process.
Some of the electrons receive enough energy from the energy given to them to escape the crystal
lattice and begin conducting electricity. As a result, the semiconductor resistance and thus the
overall LDR resistance are reduced.
The action is cumulative; as more light hits the LDR semiconductor, more electrons are freed to
conduct electricity and the resistance decreases.
The photoresistor is a light-sensitive resistor with a horizontal body that is exposed to light from
a structural perspective.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 31
Photoresistor structure
Source: www.electronics-notes.com
The active semiconductor region is typically weakly doped and is placed atop a semi-insulating
substrate.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 32
Many of the small photoresistors or light-dependent resistors that are utilized nowadays have
this type of construction. It's not difficult to recognize the interdigital pattern.
Cadmium is not utilized in any products in Europe due to environmental concerns, and the use
of this type of semiconductor has drastically decreased worldwide.
Photoresistor types
LDRs, photoresistors, and other light-dependent devices can be grouped into one of two types
or categories:
These liberated electrons can therefore conduct electricity. The device becomes more conductive
and more electrons are released as more light strikes it, which lowers resistance as conductivity
increases.
Extrinsic photoresistors: These devices are made from semiconductors and materials that have
been doped with impurities. A new energy band is produced above the current valence band by
these impurities or dopants.
As a result of the narrower energy gap, electrons require less energy to move into the conduction
band.
No matter the kind of photoresistor or light-dependent resistor, both types show a rise in
conductivity or a decline in resistance with increasing levels of incident light.
It has been demonstrated that the sensitivity of photoresistors varies depending on the
wavelength of the light striking the sensitive part of the device. If the wavelength is outside of a
certain range, there is no discernible effect, and the effect is highly evident.
The various electronic components can be utilized for a variety of purposes because devices
manufactured from various materials react differently to light of various wavelengths.
Extrinsic photoresistors are also discovered to be useful for infrared and to have a tendency to
be more sensitive to longer wavelength light. However, caution must be given when using
infrared to prevent heat buildup brought on by the radiation's escalating effect.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 33
The latency, or the amount of time it takes for an electrical component to react to changes, is a
crucial characteristic of photoresistors, also known as light-dependent resistors. This factor could
be especially crucial for a circuit design.
The LDR or photoresistor is not a good choice where there are reasonably rapid shifting values of
light since it takes a considerable length of time from any changes in a light level before it attains
its final value for the new level of light. But if the light varies gradually over time, they are more
than sufficient.
The resistance recovery rate is the pace at which the resistance varies. When light is applied after
complete darkness, the LDR or photoresistor typically responds within a few tens of milliseconds,
but when light is removed, it can take up to a second or more for the resistance to reach its final
level.
The dark resistance after a certain amount of time, usually measured in seconds, is one of the
requirements often listed in the electrical component datasheets for photo-resistors as a result.
Frequently, two values—one for one second and the other for five seconds—are stated. These
provide information about the resistor's delay.
Photoresistors can be seen in a wide range of electronic circuit designs and are used in a wide
range of applications. They are inexpensive, sturdy, and have a relatively straightforward
structure.
They are extensively utilized in a wide range of electrical devices and circuit designs, such as
photographic light meters, fire or smoke detectors, burglar alarms, and lighting controls for street
lamps.
Light-dependent resistors can be utilized in a variety of circuits. These LDR circuits may be built
using operational amplifiers, FETs, bipolar transistors, etc.
However, a potential divider serves as the foundation for the majority of LDR circuits, and this
can be combined with many additional circuits to process the voltage as needed.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 34
Two resistors connected in series, with one end commonly connected to a fixed potential and
the other to the ground, make up a basic potential divider.
It is quite straightforward to calculate the output voltage using the formula below.
Note that this is based on the supposition that the output of the potential divider circuit does not
include any loads that could significantly impact the voltage. The circuit will typically function as
predicted if the load has a high impedance; otherwise, the load and R2 should be computed in
parallel to generate the total resistance of the low branch of the potential divider.
It is clear that the output voltage from the potential divider will fluctuate if the light-dependent
resistor is, for instance, R2.
Then, a transistor, FET, operational amplifier, or other suitable circuit can be connected to this
output voltage. It can be utilized in a variety of other circuits or to enhance the difference, for
example.
The output voltage, assuming no load, will vary between 8.33 volts for the low light condition
and 0.166 volts for the full light condition, for instance, if an LDR varies between, say, 50 k for the
low light condition and 2 k when illuminated, and the potential divider is fed with 10 V.
This voltage may easily be utilized to drive a logic line that could be used for processing by feeding
it into a comparator or other suitable circuit.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 35
When considering the usage of light-dependent resistors, also known as LDRs or photoresistors,
in any electronic circuit design, there are a number of specifications that are crucial.
LDRs are very practical electronic parts that may be included in a number of electrical circuit
designs for light-detecting applications. They are especially helpful because the LDR resistance
fluctuates over such a wide range, and there are numerous LDR circuit types available.
Although their performance is relatively slow, light-dependent resistors are frequently employed
and offer a low-cost yet efficient way of sensing light and general light levels.
You'll be employing a photoresistor in this circuit, which adjusts its resistance in response to the
amount of light the sensor receives. Because the Arduino reads voltage rather than resistance
directly, we employ a voltage divider to use our photoresistor. When exposed to a lot of light,
this voltage divider will output a high voltage; when not, it will output a low value.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 36
Potentiometers, photoresistors, and other sensors you'll employ are actually resistors. According
to whatever they are perceiving (light intensity, etc.), their resistance varies. The analogue input
pins on the Arduino measure voltage rather than resistance. However, we can easily use resistive
sensors with the Arduino by including them into a "voltage divider".
Two resistors make up a voltage divider. The sensor you'll be using is the "top" resistor. One
that is "bottom" is a typical, fixed resistor. The middle resistor will output a voltage proportional
to the values of the top and bottom resistors when you connect the top resistor to 5 volts and
the bottom resistor to ground. The output voltage will change along with one of the resistors
when it does (as it would when your sensor detects something)!
The resistive sensors (flex sensor, light sensor, softpot, and trimpot) in the majority of Arduino
kits are around 10K Ohms, though the sensor resistance will vary. A 10K resistor is a fantastic
option for the fixed "bottom" resistor since we typically want it to be close to this number.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 37
PART I. BREADBOARDING.
Below are the schematic diagram and parts needed to connect the circuit on a breadboard. Draw
the equivalent breadboard connection.
SCHEMATIC DIAGRAM
PARTS NEEDED:
1. Arduino Uno
2. Breadboard
3. M-M Jumper Wires
4. LED
5. 330 Ohms Resistor
6. 10k Ohms Resistor
7. Photo Resistor
NOTE:
• Be aware of the
polarity of the
LED.
• Use +5V and GND
from Arduino as
power source for
your circuit.
FRITZING:
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 38
Below is the Arduino Sketch code. Compile the code and upload the file to your Arduino
Uno/Mega.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 39
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 40
Connect the circuit shown below and upload the code to the circuit:
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 41
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 42
1. Change the “\t” to “\n” on line 25. Insert “delay(100); on line 26. Open your serial
monitor, what is the value when the LED is lit? What is the value when the LED is off?
Explain why you got such values.
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________
2. Explain the use of the function map ( ) and the function constrain( ).
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________
3. How does a voltage divider work? What is the use of the 10k Ohms resistor in the circuit?
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
____________________________________________________________________
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 43
4. Discuss how the second circuit works? How is it related to the first circuit? Explain your
answer.
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 44
Arduino Experiment 6
IR Remote Controlled LED with 16x2 LCD
INTRODUCTION:
There are numerous practical uses for infrared (IR) communication, which is a commonly utilized
and simple wireless technology. The most prevalent examples in daily life are infrared
thermometers, motion sensors, and TV/video remote controls.
Numerous interesting Arduino projects also employ IR connectivity. You can create remote-
controlled robots, distance sensors, heart rate monitors, DSLR camera remote controls, TV
remote controls, and a lot more with just a basic IR transmitter and receiver.
Let’s first go over what infrared is and how it functions in this tutorial. After that, I'll demonstrate
how to configure an Arduino with an IR receiver and remote. I'll also demonstrate how to operate
devices linked to the Arduino using practically any IR remote (such as the one for your TV).
Source: www.circuitbasics.com
Since IR is a form of light, IR communication needs a straight line of sight between the transmitter
and receiver. Like WiFi or Bluetooth, it cannot communicate through walls or other things.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 45
The IR transmitter breakout boards for the Arduino use the same kind of LED. On the front of
this IR transmitter, you can observe it:
The IR receiver transforms the IR light into an electrical signal using a photodiode and pre-
amplifier. Most IR receiver diodes have the following appearance:
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 46
The sun, lightbulbs, and anything else that generates heat emits infrared light. This indicates that
there is a lot of IR light noise present everywhere around us. A signal modulation approach is
utilized to keep the IR signal from being hampered by this noise.
An encoder on the IR remote transforms a binary signal into a modulated electrical signal during
IR signal modulation. To the transmitting LED, this electrical signal is delivered. The modulated
electrical signal is transformed into a modulated IR light signal by the transmitting LED. After
demodulating the IR light signal, the IR receiver transforms it back to binary before sending the
data to a microcontroller:
Source: www.circuitbasics.com
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 47
A series of IR light pulses that are turned on and off at a high frequency known as the carrier
frequency make up the modulated IR signal. Most transmitters utilize a carrier frequency of 38
kHz since it is uncommon in nature and can be identified from background noise. In this manner,
the 38 kHz signal will be recognized by the IR receiver as coming from the transmitter and not
the background noise.
The receiver diode can detect IR light at all frequencies, but because of a band-pass filter, it can
only transmit IR at 38 kHz. The modulated signal is then sent to a microcontroller after being pre-
amplified and converted to a binary signal.
IR Coding
The remote control's buttons each produce a different hexadecimal code that is generated. This
data is modulated and transmitted over IR to the receiver. The receiving microcontroller needs
to be aware of the code each key on the remote corresponds to in order to determine which key
was pressed.
You have to determine the code generated for each key on your specific remote because
different remotes transmit different codes in response to key presses. The IR key codes need to
be mentioned in the datasheet if you can locate them. If not, there is a straightforward Arduino
sketch that, when you hit a key, will scan the majority of common remote controls and send the
hexadecimal codes to the serial monitor. We must first connect the receiver to the Arduino prior
to setting things up.
An infrared receiver, often known as an IR receiver, is a piece of hardware that receives and
decodes infrared signals to convey information from an infrared remote control to another
device. In order to uniquely identify the infrared signal, it receives, the receiver often outputs a
code. The signals from the remote control are then translated using this code into a language
that the other device can understand. Since infrared is a form of light, it must be seen directly in
order to function at its best, yet objects like glass and walls can still reflect it. Poorly positioned
IR receivers can generate "tunnel vision," which reduces a remote control's operational range
because they are positioned excessively back into a device's casing.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 48
PART I. BREADBOARDING.
Below is the equivalent breadboard connection. On the right side are the parts needed to
connect the circuit.
PARTS NEEDED:
1. Arduino Uno
2. Breadboard
3. M-M Jumper Wires
4. LED
5. 330 Ohms Resistor
6. IR Remote Controller
7. IR Remote Receiver
NOTE:
• Be aware of the
polarity of the
LED.
• Use +5V and
GND from
Arduino as
power source for
your circuit.
WIRING
Note that the “V-out” lead of the infrared receiver must be connected to Digital Pin 11 on the
Arduino, add an LED and a resistor. Connect the LED to digital pin 10.
Sketch Code
• We need to invoke the “IRremote” library first. You may do either of the following:
o Click “Sketch” menu from the Arduino Sketch IDE, choose “Include Library”, then
choose “Add .ZIP Library...”, locate the IRremote.zip and press “OPEN”.
o Or
o Unzip the RAR and save it to the file Arduino libraries directory
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 49
After uploading the code, open the serial monitor of the Arduino IDE and configure the baud
rate 9600 in line with Serial.begin(9600).
After configuration, press the button on the remote controller towards the infrared receiver.
Each button has a hexadecimal code. We can see the code on serial monitor no matter which
button we press. For example, we press button “0”, the hexadecimal code received is FD30CF
or FF6897.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 50
If you keep pressing one button, the serial monitor reads “FFFFFFFF”.
If it is received properly in the serial port, the code should be six digits starting with FD. If the
controller does not send out the signal towards the infrared receiver, it might receive wrong
code as we can see below.
The original infrared decoding is too complicated to manipulate, which is why we use the library
that is built by others without completely understanding it. Since we have got the idea of
decoding for infrared signal, let’s make an infrared controlled LED.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 51
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 52
PART III. FRITZING. Add three more LEDs to control. Draw the equivalent breadboard
connection. Use this as a reference to answer the CHALLENGE question number 2.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 53
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 54
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 55
2. This time, alter the REMOTE CONTROLLED LED program and use connection you have
done from “PART III. FRITZING”. Use number “1” to control LED1 and LED2 while
number “2” to control LED3 and LED4. Note that LED1 and LED2 should alternately
turns ON and OFF which should also be the same condition with LED3 and LED4.
Write the equivalent Arduino Sketch Program below.
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
______________________________________________
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 56
Arduino Experiment 7
Sounder using Buzzer
INTRODUCTION:
The piezo, commonly referred to as the buzzer, is a component that produces sound. It is a digital
component that may be connected to digital outputs, and when the output is HIGH, it generates
a tone. To produce different tones and effects, it can also be connected to an analog pulse-width
modulation output. The Buzzer has an 85 dB sound output and runs on both 3.3V and 5V. This
module can be used to give your application audio feedback that sounds like the click of a button
on a digital watch.
Piezoelectric buzzers make an audible sound. They can be used as an alert or notice when a
motion sensor is activated, or when a sensor reaches a specified value when connected to the
Arduino. Additionally, they can be programmed to generate musical notes.
Active buzzers and passive buzzers are the two categories of piezoelectric buzzers that are
frequently utilized in electronics projects. Due to the fact that they only require a DC voltage to
generate sound, active buzzers are so-called. An AC voltage is required for passive buzzers to
emit sound.
Connecting active and passive buzzers to a DC voltage source, such as a 9-volt battery, makes it
simple to distinguish between them. The buzzers are polarized, therefore before connecting it to
a battery, make sure you know which terminal is positive and which is negative.
A passive buzzer emits a loud clicking sound when you connect a battery to it. However, an active
buzzer will emit a loud buzzing sound when connected to a battery.
Magnetic buzzers come in the form of active and passive buzzers. A coil of wire that is attached
to the buzzer's pins is located inside the device. The wire coil is encircled by a round magnet as
well. Above the circular magnet and wire coil is a thin metal film with a metal weight fastened to
the top. Magnetic inductance causes the wire coil to shake when current pulses are applied,
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 57
which causes the metal weight and metal film to move up and down. Sound waves are produced
by the metal film's vibration:
www.circuitbasics.com
You create a circuit in this activity that you may use to experiment with sound. When a button
is pressed, a buzzer and an LED both make noise and light up.
PART I. BREADBOARDING.
Below are the schematic diagram and parts needed to connect the circuit on a breadboard.
1. Arduino Uno
2. Breadboard
3. M-M Jumper Wires
4. LED
5. 330 Ohms Resistors
6. 10K Ohms Resistors
7. Pushbuttons
8. Piezo Buzzer
NOTE:
• Be aware of the
polarity of the
LED.
• Use +5V and
GND from
Arduino as
power source for
your circuit.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 58
The Arduino Sketch code is provided below. compile the code, then upload it to the Arduino.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 59
1. Try changing the value of the toneFreq and observe how it affects the sound of the
buzzer. Write your answer below.
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 60
4. The buzzers for a quiz could be made using the basic idea of this circuit. Include a
second pushbutton and an LED (perhaps of a different color). Change the program such
that the circuit records which button is pressed first. Play a new tone and turn on the
appropriate LED. The buzz's duration will need to be decided by the program. On Part I,
create your Fritzing schematic for this circuit. Below, enter your Arduino sketch.
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 61
Arduino Experiment 8
Servo Motor Control
INTRODUCTION:
Because they typically move to a location rather than rotating constantly, servo motors let you
accurately regulate physical movement. Because the motor driver is already present in them,
connecting and controlling them is straightforward.
A small DC motor is built into servos and is gear-connected to the output shaft. The output shaft
is connected to a potentiometer (pot) and also operates a servo horn.
Source: www.lastminuteengineers.com
The error amplifier in the control unit compares the motor's current position to the desired
position using position feedback from the potentiometer.
The control unit corrects the inaccuracy by moving the motor's present position towards the
desired position.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 62
Source: www.lastminuteengineers.com
Great tools that can turn to a certain position are servo motors.
They typically have a servo arm with a 180-degree rotation. A servo may be directed to a certain
location using the Arduino, and it will do so. Just like that!
In the field of remote control (RC), servo motors were first applied to driving RC automobiles or
flaps on RC planes. They eventually discovered applications in robotics, automation, and, of
course, the Arduino community.
Here, we'll demonstrate how to connect a servo motor and then turn it in various directions.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 63
Servos are intelligent machines. They acquire the position from the Arduino and travel there
using only one input pin. They are equipped internally with a motor driver and a feedback circuit
that ensure the servo arm moves to the proper position. What sort of signal, though, do they get
on the input pin?
It is a square wave that resembles PWM. The signal has 20-millisecond cycles, and most of the
time, the value is LOW. The signal is HIGH for one to two milliseconds at the start of each cycle.
It depicts 0 degrees at 1 millisecond and 180 degrees at 2 milliseconds. It represents the range of
values from 0-180 in between. This is a really effective and reliable method. It's a little bit simpler
to understand because of the image.
Keep in mind that when utilizing the Servo library, the Arduino UNO and comparable boards'
PWM pins 9 and 10 are automatically disabled.
Here are a few more tips we can use to control servos because it's simple to do so:
Arduino includes a function servo built in that can regulate the precise pulse time that makes it
easier to control servos write(degrees). Not all servos, nevertheless, adhere to the same timings
in every position. Normal definitions state that 1 millisecond equals 0 degrees, 1.5 milliseconds
equal 90 degrees, and 2 milliseconds equals 180 degrees. There are servos with narrower and
wider ranges.
Additional servos
We must define numerous servo objects, assign unique pins to each one, and address each servo
separately in order to use more than one servo. First, we must declare all of the servo objects
that we require:
Then we need to attach each object to one servo motor. Remember, every servo motor uses an
individual pin:
The servo grounds connect to the Arduino's GND, the servo power to either 5V or VIN (depending
on the power input), and finally, each signal line needs to be linked to a different digital pin.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 64
Contrary to popular misconception, any digital pin will work to operate servos instead of just
PWM pins.
A unique variety of servos known as continuous rotation servos exists. A continuous rotation
servo rotates either clockwise or anticlockwise at a speed proportional to the input signal, as
opposed to a normal servo, which moves to a specified position dependent on the input signal.
For instance, the Servo1.write(0) function causes the servomotor to spin fully anticlockwise. The
Servo1.write(180) function turns the motor fully clockwise whereas the Servo1.write(90)
function stops it.
PART I. BREADBOARDING.
PARTS NEEDED:
1. Arduino Uno
2. Breadboard
3. M-M Jumper Wires
4. Potentiometer
5. Servo Motor
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 65
Below is the Arduino Sketch code. Compile the code and upload to Arduino.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 66
1. Write your observations on the two codes. How do they differ? How will the two be
useful?
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________
2. Alter the “Controlling Servo in Sketch” and control two servo motors. Write you answer
below
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 67
Arduino Experiment 9
RGB-LED
INTRODUCTION:
What's even more exciting than an LED that blinks? a distinct color. Red, green, and blue LEDs,
sometimes known as RGB LEDs, have three distinct color-emitting diodes that can be combined
to produce a wide range of hues. You'll discover in this circuit how to mix unusual colors with an
RGB LED. Almost any color is available depending on how bright each diode is!
Using the analogRead() function, we've seen that the Arduino can read analog voltages (voltages
between 0 and 5 Volts). Is it possible for the Arduino to also produce analog voltages? The
response is both no and yes. True analog voltage output is not available on the Arduino.
However, the Arduino can mimic it using a technique known as PWM (Pulse-Width Modulation)
because it is so quick.
The Arduino can turn a pin on and off roughly one thousand times per second since it is so quick.
PWM takes one step further by altering how long the blinking pin is HIGH compared to how long
it is LOW. A LED connected to that pin will appear bright if it is primarily HIGH. The LED will appear
dim if it spends the majority of its time at LOW. The Arduino gives the appearance of a "true"
analog output even though the pin is actually blinking far more quickly than your eye can see.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 68
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 69
PARTS NEEDED:
1. Arduino Uno
2. Breadboard
3. M-M Jumper Wires
4. RGB-LED
5. 3 - 220ohms resistors
PART I. BREADBOARDING.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 70
Below is the Arduino Sketch code. Compile the code and upload it to Arduino.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 71
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 72
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 73
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 74
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 75
4. Write your observations on the two codes mainColors( ) and showSpectrum( ). How do
they differ? How will the two be useful?
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 76
Arduino Experiment 10
Ultrasonic Sensor HC-SR04
INTRODUCTION:
Like bats, the HC-SR04 ultrasonic sensor uses sonar to calculate the distance to an object. It
provides superior non-contact range detection in a user-friendly design with high accuracy and
reliable readings.
1" to 13 feet or 2 cm to 400 cm. Unlike sharp rangefinders, it is unaffected by sunshine or dark
objects, yet acoustically soft objects like cloth can be challenging to identify. It includes an
ultrasonic transmitter and receiver module in its entirety.
Features
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 77
We can determine the distance to an object by measuring the interval between the signal's
transmission and reception. We can do this because we are aware of the sound's air velocity.
Sensor
Pins
You will learn more about how this sensor functions as a result of this experiment. After that,
you can apply this example to your own works.
Be aware that utilizing this sensor can be made simpler by the Arduino library NewPing.
PARTS NEEDED:
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 78
PART I. BREADBOARDING.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 79
Below are the Arduino Sketch codes. Compile the code and upload it to Arduino.
Sample program A
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 80
Additionally, you establish three long-type variables: duration, cm, and inch. The duration
variable stores the interval between the signal's emission and reception. The cm and inch
variables will store the distance in centimetres and inches, respectively.
We initialize the serial port with a 9600 baud rate in setup() and configure the echo pin as an
input and the trigger pin as an output.
We activate the sensor in the loop() by sending a HIGH pulse lasting 10 microseconds. However,
in order to guarantee a clear HIGH pulse, we must supply a short LOW pulse:
The signal from the sensor is then read; it is a HIGH pulse with a period measured in microseconds
from the time the signal is sent and when its echo is received by an object.
All that is left to do is translate the duration into a distance. The formula below can be used to
get the distance:
Due to the fact that the wave was delivered, hit the object, and then returned to the sensor, we
must divide the travel time by 2.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 81
Then specify the pins for the echo and trigger. The Arduino digital pin 11 and pin 12 are used to
connect the trigger and echo pins, respectively. To utilize the library, you must also define the
MAX_DISTANCE variable.
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON
P a g e | 82
1. Write your observations on the two codes Sample program A and Sample program B. How do they
differ? How will the two be useful?
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
____________________________
2. Alter the program and include a 16x2 LCD in the experiment. Display the distance on the LCD
instead of the Serial Monitor. Write your equivalent code below.
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
______________________________________________________________________________________
LABORATORY MANUAL IN EMBEDDED SYSTEMS USING ARDUINO | By: BRAVO and TUAZON