Professional Documents
Culture Documents
Principles of Embedded System Lab Manual
Principles of Embedded System Lab Manual
Principles of Embedded System Lab Manual
By:
Engr. Ronnie M. Dysangco
Engr. Maria Cecilia A. Venal
Table of Contents
INTRODUCTION .................................................................................................................................3
ACTIVITIES .........................................................................................................................................5
Activity No. 1 .........................................................................................................................6
SERIAL MONITOR DISPLAY .........................................................................................6
Activity No. 2 ....................................................................................................................... 10
LIGHT EMITTING DIODE (LED) DISPLAY ..................................................................... 10
Activity No. 3 ....................................................................................................................... 15
RGB (LED) DISPLAY ................................................................................................... 15
Activity No. 4 ....................................................................................................................... 21
LED LIGHTS, SHIFT REGISTER AND SERIAL MONITOR ................................................. 21
Activity No. 5 ....................................................................................................................... 30
DIGITAL INPUTS ....................................................................................................... 30
Activity No. 6 ....................................................................................................................... 34
RGB LED FADER ........................................................................................................ 34
Activity No. 7 ....................................................................................................................... 39
ANALOG INPUTS ...................................................................................................... 39
Activity No. 8 ....................................................................................................................... 44
SENSOR AND SOUNDS.............................................................................................. 44
Activity No. 9 ....................................................................................................................... 50
LCD DISPLAY ............................................................................................................ 50
Activity No. 10 ..................................................................................................................... 56
MOTORS .................................................................................................................. 56
Appendix ......................................................................................................................................... 70
2
INTRODUCTION
Embedded System
It is housed on a single microprocessor board with the programs stored in ROM. Virtually all appliances that
have a digital interface -- watches, microwaves, VCRs, cars -- utilize embedded systems. Some embedded
systems include an operating system, but many are specialized where the entire logic can be implemented
as a single program.
Breadboard
Breadboard is a way of constructing electronics without having to use a soldering iron. Components are
pushed into the sockets on the breadboard and then extra 'jumper' wires are used to make connections.
The middle section of the board has two columns, each with 30 strips of connector, like the one pulled out
and to the side of the breadboard. These connect together anything that is pushed through from the front
into one of those five holes.
On either edge of the board are much longer sections of clip that join together the columns of holes marked
by the blue and red lines on the front of the breadboard. These are generally used for GND (blue) and 5V
(red).
Getting Started
ACTIVITIES
5
Activity No. 1
SERIAL MONITOR DISPLAY
Course Code: CPE 131
Program:
Course Title: Principle of Embedded System
Date Performed:
Section:
Date Submitted:
Name :
Instructor:
1. Objective(s):
The activity aims to create a runnable program using the Arduino programming software. This activity
also provides students with knowledge and skills on how to develop a program using the Arduino
programming software.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:
2.1 Create a program that displays a string output and some mathematical operation.
2.2 Apply the C-programming knowledge in embedded system programming.
3. Discussion:
Serial Library is used to communicate from the Arduino/ Gizduino board back to the computer over the
USB port. Serial data transfer sequence is through one bit data transfer at a time, in which the
information is passed back & forth between the computer and Arduino/ Gizduino board by, essentially,
setting the pin into a high or low status. Just like using the LED lights as an indicator for the output. The
connection of the Arduino/ Gizduino board as shown in Figure 1-1 emphasizes the data transfer physical
procedure from the software going to the Arduino/ Gizduino board.
Creating a program file with Arduino/ Gizduino board is the same as the C language source code.
Reference: http://www.ladyada.net/learn/arduino/lesson4.html
4. Materials and Equipment:
1. Arduino/ Gizduino board
2. Computer
3. USB Cable
4. Power Source
5. Procedure:
1. Open installed Arduino IDE.
2. Select board and serial port in the action bar.
3. Create a new sketch.
4. Copy the source code in Figure 1-2.
5.
6.
7.
8.
// add
Serial.print("a * c = ");
Serial.println(a * c);
// multiply
Serial.print("c / b = ");
Serial.println(c / b);
// divide
Serial.print("b - c = ");
Serial.println(b - c);
// subtract
}
void loop()
here even though its empty
{
}
11.
12.
13.
14.
// we need this to be
7. Data Analysis:
8. Assessment Rubric:
Activity No. 2
LIGHT EMITTING DIODE (LED) DISPLAY
Course Code: CPE 131
Program:
Course Title: Principle of Embedded System
Date Performed:
Section:
Date Submitted:
Name :
Instructor:
1. Objective(s):
The activity aims to create a runnable program using the Arduino programming software that will display
an LED output. This activity also provides students knowledge and skills on how to develop a circuit
using different resistor in controlling the LED using the Arduino programming software.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:
2.1 Create a runnable program that will display a different LED.
2.2 Apply the C-programming knowledge in embedded system programming.
3. Discussion:
Light Emitting Diode
LEDs are one of the good electronic outputs that make a great light indicator output. It is an electronic
device that uses a very little electricity. The most common of all LEDs a 5mm red LED refers to the
diameter of the LED. Other common sizes are 3mm and the large fun 10mm LEDs. This electronic
device cannot be connected directly to a battery or any voltage source because of its voltage necessity.
The polarity of each leg needs to be attached to a resistor to limit or choke the amount of current
flowing to avoid the burn out probability.
Resistors
It is an electronic component that resists the electricity flow, in which the higher the value of the resistor,
the more it can resist the electrical charge and produce less electrical current within the circuitry. To
determine the amount of resistance of each resistor, Figure 2-1 shows the proper way on reading the
resistor color coding values.
Blink Source Code
Blinking is one of the methods in controlling the LED light output of the Arduino/Gizduino board. It is also
the basic programming technique on how to manipulate and embedded a program on the said board.
Figure 2-2 shows the source code in creating a blinking program.
10
5. Procedure:
1. Open Sketch software.
2. Choose example at file menu.
3. Select basic then blink.
4. Write the source code at the data and results.
5. Save the file as Activity 2-A.
6. Attach the Arduino or Gizduino Board with the USB cable.
7. Click the upload button.
8. Simulate the program.
9. Write the binary sketch size and error message at data and results.
10. Change and write the observation as the delay values change using Table 2-1.
11. Create a connection as shown in Figure 2-3.
12
Error Message
13
Delay Values
1. 100
2. 300
3. 500
4. 700
5. 900
Resistor
Value
1. 470
2. 2.2K
3. 10K
8. Assessment Rubric:
14
Activity No. 3
RGB (LED) DISPLAY
Course Code: CPE 131
Program:
Course Title: Principle of Embedded System
Date Performed:
Section:
Date Submitted:
Name :
Instructor:
1. Objective(s):
The activity aims to create a runnable program using the Arduino programming software that will display
an RGB LED output. This activity also provides students with knowledge and skills on how to develop a
circuit using RGB LED controlled by C programming.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:
2.1 Create a runnable program that will display a RGB LED output.
2.2 Apply the C-programming knowledge in embedded system programming.
3. Discussion:
RGB LEDs
It is a type of LED that contains different color combination such as Red, Green and Blue inside a single
LED bulb. A common anode RGB LED is nothing more complicated than three one colour LEDs (one
red, one green, and one blue) housed in a single package. Rather than having 6 leads (a cathode and
anode for each LED) it has only 4 one cathode for each colour, and one common anode. (see the
schematic diagram below) A common anode RGB LED is the most popular type. It is commonly found in
either a 5mm bulb size or as a 5mm pirahna form factor as shown in Figure 3-1.
It is a technique for power controlling. It is also used to control the brightness of each RGB LEDs.
Roughly every 1/500 of a second, the PWM output will produce a pulse. The length of this pulse is
controlled by the 'analogWrite' function. So 'analogWrite(0)' will not produce any pulse at all and
'analogWrite(255)' will produce a pulse that lasts all the way until the next pulse is due, so that the
output is actually on all the time. If the specify value in the analogWrite that is somewhere in between 0
and 255 then it will produce a pulse. If the output pulse is only high for 5% of the time then whatever we
are driving will only receive 5% of full power. However, the output is at 5V for 90% of the time then the
load will get 90% of the power delivered to it.
Reference: www.instructables.com/id/RGB-LED-Tutorial-using-an-Arduino-RGBL/step1/Parts/
4. Materials and Equipment:
1.
2.
3.
4.
5.
6.
7.
8.
5. Procedure:
1. Open Sketch software.
2. Create a circuit and board connection as shown in Figure 3-4.
10/20
Output
18/10
19
PCB Design
7. Data Analysis:
8. Assessment Rubric:
20
Activity No. 4
LED LIGHTS, SHIFT REGISTER AND SERIAL MONITOR
Course Code: CPE 131
Program:
Course Title: Principle of Embedded System
Date Performed:
Section:
Date Submitted:
Name :
Instructor:
1. Objective(s):
The activity aims to create a runnable program using the Arduino programming software that will display
an LED and serial monitor output using Shift Register IC. This activity also provides students with
knowledge and skills on how to develop a circuit using Shift Register IC controlled by C programming
code.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:
2.1 Create a runnable program that will display an LED and serial monitor output.
2.2 Apply the C-programming knowledge in embedded system programming.
3. Discussion:
74HC595 as an "8-bit serial-in, serial or parallel-out shift register with output latches; 3-state." In other
words, it can be used to control 8 outputs at a time while taking only a few pins on the microcontroller. It
can be link multiple registers together to extend to even more output. (Users may also wish to search for
other driver chips with "595" or "596" in their part numbers, there are many. The STP16C596 for
example will drive 16 LED's and eliminate the series resistors with built-in constant current sources.)
This integrated circuit work in a "synchronous serial communication," i.e. it can pulse one pin up and
down thereby communicating a data byte to the register bit by bit. It's by pulsing second pin, the clock
pin, which can delineate between bits. This is in contrast to using the "asynchronous serial
communication" of the Serial.begin() function which relies on the sender and the receiver to be set
independently to an agreed data rate.
Once the whole byte is transmitted to the register the HIGH or LOW messages held in each bit get
parceled out to each of the individual output pins. This is the "parallel output" part, having all the pins do
all at once.
The "serial output" part of this component comes from its extra pin which can pass the serial information
received from the microcontroller out again unchanged. This means that it can transmit 16 bits in a row
(2 bytes) and the first 8 will flow through the first register into the second register and be expressed
there.
21
"3 states" refers to the fact that can set the output pins as either high, low or "high impedance." Unlike
the HIGH and LOW states, it cannot set pins to high impedance state individually. It can only set the
whole chip together. This is a pretty specialized thing to do for example think of a LED array that might
need to be controlled by completely different microcontrollers depending on a specific mode setting built
into a project. Figure 4-1 shows the pin configuration of 74HC595
5. Procedure:
1. Create a Circuit and board connection as shown in Figure 4-3.
10.
11.
12.
13.
14.
15.
16.
17.
18.
28
Case
4800 baud
14400 baud
19200 baud
28800 baud
38400 baud
57600 baud
115200 baud
7. Data Analysis:
8. Assessment Rubric:
29
Activity No. 5
DIGITAL INPUTS
Course Code: CPE 131
Program:
Course Title: Principle of Embedded System
Date Performed:
Section:
Date Submitted:
Name :
Instructor:
1. Objective(s):
The activity aims to create a runnable program using the Arduino programming software that will display
an LED light output controlled by a tactile push switch. This activity also provides students with
knowledge and skills on how to develop a circuit using C-programming codes.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:
2.1 Create a runnable program that will display an LED light output controlled by a switch.
2.2 Apply the C-programming knowledge in embedded system programming.
3. Discussion:
Switches are really simple electronic components. When the user presses a button or flips a lever, it
connects two contacts together so that electricity can flow through the circuit. The little tactile switches
are a kind of switch that has four connections, which can be a little confusing. In reality, there are only
two electrical connections, as inside the switch package pins B and C are connected together, like the A
and D as shown in Figure 5-1.
5. Procedure:
1. Create a circuit connection as shown in Figure 5-2.
31
Case
pinMode(latchPin,INPUT)
pinMode(buttonApin,INPUT_PULLDOWN)
pinMode(buttonBpin,INPUT_PULLDOWN)
pinMode(buttonApin,INPUT_PULLDOWN)
pinMode(buttonBpin,INPUT_PULLDOWN)
digitalWrite(ledPin,LOW)
digitalRead(buttonBpin)==HIGH
Observation
32
Schematic Diagram
7. Data Analysis:
8. Assessment Rubric:
33
Activity No. 6
RGB LED FADER
Course Code: CPE 131
Program:
Course Title: Principle of Embedded System
Date Performed:
Section:
Date Submitted:
Name :
Instructor:
1. Objective(s):
The activity aims to create a runnable program using the Arduino programming software that will display
an RGB LED lights common cathode output. This activity also provides students with knowledge and
skills on how to develop a circuit using C programming source code.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:
2.1 Create a runnable program that will display an RGB LED lights output controlled by a Cprogram.
2.2 Apply the C-programming knowledge in embedded system programming.
3. Discussion:
LEDs (ell-ee-dees) are a particular type of diode that convert electrical energy into light. In fact, LED
stands for Light Emitting Diode. This is reflected in the similarity between the diode and LED schematic
symbols:
In short, LEDs are like tiny lightbulbs. However, LEDs require a lot less power to light up by comparison.
They are also more energy efficient, so they do not tend to get hot like conventional light bulbs do. This
makes them ideal for mobile devices and other low-power applications.
RGB LED in a 5mm diffused epoxy case. - Common Cathode (common ground) as shown in Figure 6-1
8,000mcd- 100,000nhour lifetime as shown in Table 6-1.
Table 6-1 RGB Colors Description
20
Red:
2V ~ 2.4V
mA
Green:
3.2V
3.6V
20
mA
Blue:
3.2V
3.6V
20
mA
34
5. Procedure:
1. Create a Breadboard connection as shown in Figure 6-1.
36
5.
6.
7.
8.
37
Observation
7. Data Analysis:
8. Assessment Rubric:
38
Activity No. 7
ANALOG INPUTS
Course Code: CPE 131
Program:
Course Title: Principle of Embedded System
Date Performed:
Section:
Date Submitted:
Name :
Instructor:
1. Objective(s):
The activity aims to create a runnable program using the Arduino programming software that will display
an EIGHT LED lights output controlled by a Variable resistor and design PCB Circuit and connection.
This activity also provides students with knowledge and skills on how to develop a circuit using analog
input circuit controlled by a C-program.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:
2.1 Create a runnable program and a PCB circuit that will display an EIGHT LED lights output
controlled by a Variable resistor.
2.2 Apply the C-programming knowledge in embedded system programming.
3. Discussion:
Variable Resistors (Pots)
Are often called 'pots' which is short for 'potentiometers'. The Serial Monitor and the pot is somehow,
varying the voltage at A0 and the little test sketch is converting this voltage into a number between 0
and 1023.
2.
3.
4.
5.
6.
7.
41
Case
4800 baud
14400 baud
19200 baud
28800 baud
38400 baud
57600 baud
115200 baud
Case
pinMode(latchPin,INPUT)
pinMode(dataPin,INPUT)
pinMode(clockPin,INPUT)
i--
Observation
42
7. Data Analysis:
8. Assessment Rubric:
43
Activity No. 8
SENSOR AND SOUNDS
Course Code: CPE 131
Program:
Course Title: Principle of Embedded System
Date Performed:
Section:
Date Submitted:
Name :
Instructor:
1. Objective(s):
The activity aims to create a runnable program using the Arduino programming software that will display
an EIGHT LED lights and serial monitor output controlled by a photocell electronic component. This
activity also provides students with knowledge and skills on how to develop a circuit using photocell
electronic component that will transmit a data through the use of C program codes.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:
2.1 Create a runnable program that will display an Eight LED lights and serial monitor output by a
photocell electronic component.
2.2 Apply the C-programming knowledge in embedded system programming.
3. Discussion:
A sensor is a converter that measures a physical quantity and converts it into a signal which can be read
by an observer or by an (today mostly electronic) instrument. For example, a mercury-in-glass
thermometer converts the measured temperature into expansion and contraction of a liquid which can
be read on a calibrated glass tube. A thermocouple converts temperature to an output voltage which can
be read by a voltmeter. For accuracy, most sensors are calibrated against known standards.
Sensors are used in everyday objects such as touch-sensitive elevator buttons (tactile sensor) and
lamps which dim or brighten by touching the base. There are also innumerable applications for sensors
of which most people are never aware. Applications include cars, machines, aerospace, medicine,
manufacturing and robotics.
A sensor is a device, which responds to an input quantity by generating a functionally related output
usually in the form of an electrical or optical signal. A sensor's sensitivity indicates how much the
sensor's output changes when the measured quantity changes. For instance, if the mercury in a
thermometer moves 1 cm when the temperature changes by 1 C, the sensitivity is 1 cm/C (it is
basically the slope Dy/Dx assuming a linear characteristic). Sensors that measure very small changes
must have very high sensitivities. Sensors also have an impact on what they measure; for instance, a
room temperature thermometer inserted into a hot cup of liquid cools the liquid while the liquid heats the
thermometer. Sensors need to be designed to have a small effect on what is measured; making the
44
sensor smaller often improves this and may introduce other advantages. Technological progress allows
more and more sensors to be manufactured on a microscopic scale as microsensors
using MEMS technology. In most cases, a microsensor reaches a significantly higher speed and
sensitivity compared with macroscopic approaches.
A photoresistor or light-dependent resistor (LDR) or photocell is a light-controlled variable resistor.
The resistance of a photoresistor decreases with increasing incident light intensity; in other words, it
exhibits photoconductivity. A photoresistor can be applied in light-sensitive detector circuits, and lightand dark-activated switching circuits.
A photoresistor is made of a high resistance semiconductor. In the dark, a photoresistor can have a
resistance as high as a few megaohms (M), while in the light, a photoresistor can have a resistance as
low as a few hundred ohms. If incident light on a photoresistor exceeds a
certain frequency, photons absorbed by the semiconductor give bound electrons enough energy to jump
into the conduction band. The resulting free electrons (and their hole partners) conduct electricity,
thereby lowering resistance. The resistance range and sensitivity of a photoresistor can substantially
differ among dissimilar devices. Moreover, unique photoresistors may react substantially differently to
photons within certain wavelength bands.
A photoelectric device can be either intrinsic or extrinsic. An intrinsic semiconductor has its own charge
carriers and is not an efficient semiconductor, for example, silicon. In intrinsic devices the only available
electrons are in the valence band, and hence the photon must have enough energy to excite the
electron across the entire bandgap. Extrinsic devices have impurities, also called dopants, and added
whose ground state energy is closer to the conduction band; since the electrons do not have as far to
jump, lower energy photons (that is, longer wavelengths and lower frequencies) are sufficient to trigger
the device. If a sample of silicon has some of its atoms replaced by phosphorus atoms (impurities),
there will be extra electrons available for conduction. This is an example of an extrinsic semiconductor.
Sound
Sound waves are vibrations in the air pressure. The speed of the vibrations (cycles per second or Hertz)
is what makes the pitch of the sound. The higher the frequency of the vibration, the higher the pitch, as
shown in Figure 8-1.
Middle C is usually defined as a frequency of 261 Hz. If it turns a digital output on and off again 261
times every second then that output will be middle C. To hear the output, it one needs to attach
something that will convert the electrical signal into sound waves. This can be done with a loudspeaker
or piezo sounder. Piezo sounders use a special crystal that expands and contracts as an electrical
signal passes through it.
Reference: http://en.wikipedia.org/wiki
4. Materials and Equipment:
1. Arduino/ Gizduino board
2. Computer
3. USB Cable
4. Power Source
5. Bread board
6. 8 LED (any color)
7. Photocell (Light Dependent Resistor)
8. 8 Resistors (270 )
9. 1 Resistor (1k )
10. Piezo Sounder
11. 74HC595 Shift Register
12. IC Socket
13. 2x2 Printed Circuit Board
14. Ferric Chloride
15. Plastic Container
16. Permanent Marker
17. Masking Tape
18. Mini Drill
19. Connecting wires
5. Procedure:
1. Create a Breadboard connection as shown in Figure 8-2.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
47
Observation
Schematic Diagram
48
7. Data Analysis:
8. Assessment Rubric:
49
Activity No. 9
LCD DISPLAY
Course Code: CPE 131
Program:
Course Title: Principle of Embedded System
Date Performed:
Section:
Date Submitted:
Name :
Instructor:
1. Objective(s):
The activity aims to create a runnable program using the Arduino programming software that will display
an LCD output. This activity also provides students with knowledge and skills on how to develop a circuit
using LCD display controlled by a C-program.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:
2.1 Create a runnable program that will display an LCD output.
2.2 Apply the C-programming knowledge in embedded system programming.
3. Discussion:
Liquid Cristal Display (LCD)
Description
Creates a variable of type LiquidCrystal. The display can be controlled using 4 or 8 data lines. If the
former, omit the pin numbers for d0 to d3 and leave those lines unconnected. The RW pin can be tied to
ground instead of connected to a pin on the Arduino; if so, omit it from this function's parameters.
Syntax
LiquidCrystal(rs,
LiquidCrystal(rs,
LiquidCrystal(rs,
LiquidCrystal(rs,
enable, d4,
rw, enable,
enable, d0,
rw, enable,
d5,
d4,
d1,
d0,
d6,
d5,
d2,
d1,
d7)
d6, d7)
d3, d4, d5, d6, d7)
d2, d3, d4, d5, d6, d7)
Parameters
rs: the number of the Arduino pin that is connected to the RS pin on the LCD
rw: the number of the Arduino pin that is connected to the RW pin on the LCD (optional)
enable: the number of the Arduino pin that is connected to the enable pin on the LCD
50
d0, d1, d2, d3, d4, d5, d6, d7: the numbers of the Arduino pins that are connected to the corresponding
data pins on the LCD. d0, d1, d2, and d3 are optional; if omitted, the LCD will be controlled using only
the four data lines (d4, d5, d6, d7).
Example:
#include <LiquidCrystal.h>
LiquidCrystal
lcd(12, 11, 10, 5, 4, 3, 2);
void setup()
{
lcd.begin(16,1);
lcd.print("hello, world!");
}
void loop() {}
4. Materials and Equipment:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
51
5. Procedure:
1. Create a connection as shown at Figure 9-1.
Schematic Diagram
54
7. Data Analysis:
8. Assessment Rubric:
55
Activity No. 10
MOTORS
Course Code: CPE 131
Program:
Course Title: Principle of Embedded System
Date Performed:
Section:
Date Submitted:
Name :
Instructor:
1. Objective(s):
The activity aims to create a runnable program using the Arduino programming software that will
produce a motor movement output. This activity also provides students with knowledge and skills on
how to develop a circuit with motor application that is controlled by a C-program.
2. Intended Learning Outcomes (ILOs):
The students shall be able to:
2.1 Create a runnable program that can control a motor.
2.2 Apply the C-programming knowledge in embedded system programming.
3. Discussion:
Transistor and DC Motor
The small DC motor is likely to use more power than an Arduino digital output can handle directly. If it is
tried to connect the motor straight to an Arduino pin, there is a good chance that it could damage the
Arduino. A small transistor like the PN2222 can be used as a switch that uses just a little current from
the Arduino digital output to control the much bigger current of the motor, as shown in Figure 10-1.
The transistor has three leads. Most of the electricity flows from the Collector to the Emitter, but this will
only happen if a small amount is flowing into the Base connection. This small current is supplied by the
Arduino digital output. The diagram below is called a schematic diagram (Figure 10-2). Like a
breadboard layout, it is a way of showing how the parts of an electronic project are connected together.
Servo Motor
The position of the servo motor is set by the length of a pulse. The servo expects to receive a pulse
roughly every 20 milliseconds. If that pulse is high for 1 millisecond, then the servo angle will be zero, if
it is 1.5 milliseconds, then it will be at its centre position and if it is 2 milliseconds it will be at 180
degrees, as shown in Figure 10-3.
58
ground of the second power supply that is connected to the ground of the Arduino.
Stepper Motor
Stepper motors use a cogged wheel and electro magnets to nudge the wheel round a 'step' at a time, as
shown in Figure 10-5.
5. Procedure:
1. Create a circuit and board connection as shown in Figure 10-6.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
63
64
66
67
68
7. Data Analysis:
8. Assessment Rubric:
69
Appendix
70
Appendix A
/*
Shift Register Example
Turning on the outputs of a 74HC595 using an array
Hardware:
* 74HC595 shift register
* LEDs attached to each of the outputs of the shift register
*/
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
//holders for infromation you're going to pass to shifting
function
byte data;
byte dataArray[10];
void setup() {
//set pins to output because they are addressed in the main
loop
pinMode(latchPin, OUTPUT);
Serial.begin(9600);
//Arduino doesn't seem to have a way to write binary straight
into the code
//so these values are in HEX. Decimal would have been fine,
too.
dataArray[0] = 0xFF; //11111111
dataArray[1] = 0xFE; //11111110
dataArray[2] = 0xFC; //11111100
dataArray[3] = 0xF8; //11111000
dataArray[4] = 0xF0; //11110000
dataArray[5] = 0xE0; //11100000
dataArray[6] = 0xC0; //11000000
71
74
Appendix B
75
Appendix C
76
Appendix D
77
Appendix E
List of Functions for LCD Display
1. begin()
Description
Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the
display. begin() needs to be called before any other LCD library commands.
Syntax
lcd.begin(cols, rows)
Parameters
lcd: a variable of type LiquidCrystal
cols: the number of columns that the display has
rows: the number of rows that the display has
2. clear()
Description
Clears the LCD screen and positions the cursor in the upper-left corner.
Syntax
lcd.clear()
Parameters
lcd: a variable of type LiquidCrystal
3. home()
Description
Positions the cursor in the upper-left of the LCD. That is, use that location in outputting subsequent
text to the display. To also clear the display, use the clear() function instead.
Syntax
78
lcd.home()
Parameters
lcd: a variable of type LiquidCrystal
4. setCursor()
Description
Position the LCD cursor; that is, set the location at which subsequent text written to the LCD will be
displayed.
Syntax
lcd.setCursor(col, row)
Parameters
lcd: a variable of type LiquidCrystal
col: the column at which to position the cursor (with 0 being the first column)
row: the row at which to position the cursor (with 0 being the first row)
5. write()
Description
Write a character to the LCD.
Syntax
lcd.write(data)
Parameters
lcd: a variable of type LiquidCrystal
data: the character to write to the display
Returns
byte
write() will return the number of bytes written, though reading that number is optional
79
Example:
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
void setup()
{
Serial.begin(9600);
}
void loop()
{
if (Serial.available()) {
lcd.write(Serial.read());
}
}
6. print()
Description
Prints text to the LCD.
Syntax
lcd.print(data)
lcd.print(data, BASE)
Parameters
lcd: a variable of type LiquidCrystal
data: the data to print (char, byte, int, long, or string)
BASE (optional): the base in which to print numbers: BIN for binary (base 2), DEC for decimal
(base 10), OCT for octal (base 8), HEX for hexadecimal (base 16).
Returns
byte
print() will return the number of bytes written, though reading that number is optional
80
Example
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);
void setup()
{
lcd.print("hello, world!");
}
void loop() {}
7. cursor()
Description
Display the LCD cursor: an underscore (line) at the position to which the next character will be
written.
Syntax
lcd.cursor()
Parameters
lcd: a variable of type LiquidCrystal
Example
cursor() and noCursor()
8. noCursor()
Description
Hides the LCD cursor.
Syntax
lcd.noCursor()
Parameters
81
82
Example
cursor() and noCursor()
9. blink()
Description
Display the blinking LCD cursor. If used in combination with the cursor() function, the result will
depend on the particular display.
Syntax
lcd.blink()
Parameters
lcd: a variable of type LiquidCrystal
Example
blink() and noBlink()
10. noBlink()
Description
Turns off the blinking LCD cursor.
Syntax
lcd.noBlink()
Parameters
lcd: a variable of type LiquidCrystal
Example
blink() and noBlink()
11. display()
Description
83
Turns on the LCD display, after it's been turned off with noDisplay(). This will restore the text (and
cursor) that was on the display.
84
Syntax
lcd.display()
Parameters
lcd: a variable of type LiquidCrystal
Example
display() and noDisplay()
12. noDisplay()
Description
Turns off the LCD display, without losing the text currently shown on it.
Syntax
lcd.noDisplay()
Parameters
lcd: a variable of type LiquidCrystal
Example
display() and noDisplay()
13. scrollDisplayLeft()
Description
Scrolls the contents of the display (text and cursor) one space to the left.
Syntax
lcd.scrollDisplayLeft()
Parameters
lcd: a variable of type LiquidCrystal
Example
scrollDisplayLeft() and scrollDisplayRight()
85
14. scrollDisplayRight()
Description
Scrolls the contents of the display (text and cursor) one space to the right.
Syntax
lcd.scrollDisplayRight()
Parameters
lcd: a variable of type LiquidCrystal
Example
scrollDisplayLeft() and scrollDisplayRight()
15. autoscroll()
Description
It turns ON automatic LCD scrolling. This causes each character output to the display to push
previous characters over by one space. If the current text direction is left-to-right (the default), the
display scrolls to the left; if the current direction is right-to-left, the display scrolls to the right. This
has the effect of outputting each new character to the same location on the LCD.
Syntax
lcd.autoscroll()
Parameters
lcd: a variable of type LiquidCrystal
16. noAutoscroll()
Description
Turns off automatic scrolling of the LCD.
Syntax
lcd.noAutoscroll()
Parameters
lcd: a variable of type LiquidCrystal
86
17. leftToRight()
Description
Set the direction for text written to the LCD to left-to-right, the default. This means that subsequent
characters written to the display will go from left to right, but does not affect previously-output text.
Syntax
lcd.leftToRight()
Parameters
lcd: a variable of type LiquidCrystal
18. rightToLeft()
Description
Set the direction for text written to the LCD to right-to-left (the default is left-to-right). This means
that subsequent characters written to the display will go from right to left, but does not affect
previously-output text.
Syntax
lcd.rightToLeft()
Parameters
lcd: a variable of type LiquidCrystal
19. rightToLeft()
Description
Set the direction for text written to the LCD to right-to-left (the default is left-to-right). This means
that subsequent characters written to the display will go from right to left, but does not affect
previously-output text.
Syntax
lcd.rightToLeft()
Parameters
lcd: a variable of type LiquidCrystal
87
20. createChar()
Description
Create a custom character (gylph) for use on the LCD. Up to eight characters of 5x8 pixels are
supported (numbered 0 to 7). The appearance of each custom character is specified by an array of
eight bytes, one for each row. The five least significant bits of each byte determine the pixels in that
row. To display a custom character on the screen, write() its number.
NB : When referencing custom character "0", if it is not in a variable, you need to cast it as a byte,
otherwise the compiler throws an error. See the example below.
Syntax
lcd.createChar(num, data)
Parameters
lcd: a variable of type LiquidCrystal
num: which character to create (0 to 7)
data: the character's pixel data
Example
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte smiley[8] = {
B00000,
B10001,
B00000,
B00000,
B10001,
B01110,
B00000,
};
88
void setup() {
lcd.createChar(0, smiley);
lcd.begin(16, 2);
lcd.write(byte(0));
}
void loop() {}
89
Appendix F
Sample for LCD Display
This example sketch shows how to use the leftToRight() and rightToLeft() methods. These methods control
which way text flows from the cursor.
rightToLeft() causes text to flow to the left from the cursor, as if the display is right-justified.
leftToRight() causes text to flow to the right from the cursor, as if the
display is left-justified.
This sketch prints a through l right to left, then m through r left to right, then s through z right to left again.
Hardware Required
Arduino Board
LCD Screen (compatible with Hitachi HD44780 driver)
pin headers to solder to the LCD display pins
10k Potentiometer
breadboard
hook-up wire
Circuit
Before wiring the LCD screen to Arduino it is suggested to solder a pin header strip to the 14 (or 16) pin
count connector of the LCD screen, as you can see in the image above.
To wire your LCD screen to your Arduino, connect the following pins:
Additionally, wire a 10K pot to +5V and GND, with its wiper (output) to LCD screens VO pin (pin3).
90
Code
/*
LiquidCrystal Library - TextDirection
Demonstrates the use a 16x2 LCD display. The LiquidCrystal
library works with all LCD displays that are compatible with the
91
Hitachi HD44780 driver. There are many of them out there, and you
can usually tell them by the 16-pin interface.
This sketch demonstrates how to use leftToRight() and rightToLeft()
to move the cursor.
The circuit:
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
Reference:
void setup() {
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// turn on the cursor:
lcd.cursor();
}
void loop() {
// reverse directions at 'm':
if (thisChar == 'm') {
// go right for the next letter
lcd.rightToLeft();
}
// reverse again at 's':
if (thisChar == 's') {
// go left for the next letter
lcd.leftToRight();
}
// reset at 'z':
if (thisChar > 'z') {
// go to (0,0):
lcd.home();
// start again at 0
thisChar = 'a';
}
// print the character
lcd.write(thisChar);
// wait a second:
delay(1000);
// increment the letter:
thisChar++;
}
93