Embedded Merge

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 93

TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES

PRINCIPLE OF EMBEDDED SYSTEM

LABORATORY ACTIVITY 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

Figure A. Device Detection


3

Figure B. Update Driver Software

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.

Figure 1-1 Hardware Connection


6

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.

Figure 1-2 String sample source code


Compile the program.
Save the program as Activity 1-1.
Simulate the program.
Write the output at the data and results.
7

9. Create a new sketch.


10. Copy the source code below.
/* * Math is fun! * */
int a = 5;
int b = 10;
int c = 20;
void setup()
sketch starts
{
Serial.begin(9600);
at 9600 bps

// run once, when the


// set up Serial library

Serial.println("Mathematical Operation: ");


Serial.print("a = ");
Serial.println(a);
Serial.print("b = ");
Serial.println(b);
Serial.print("c = ");
Serial.println(c);
Serial.print("a + b = ");
Serial.println(a + b);

// 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

Compile the program.


Save the file as Activity 1-2.
Simulate the program.
Write the output at the data and results.
8

6. Data and Results:

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

Figure 2-1 Resistor Color Coding

Figure 2-2 Blink Program


11

4. Materials and Equipment:


1.
2.
3.
4.
5.
6.
7.
8.
9.

Arduino/ Gizduino board


Computer
USB Cable
Power Source
Bread board
LED
Resistors (470, 2.2K, and 10K)
74HC595 Shift Register
Connecting wires

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.

Figure 2-3 Bread board interface

12. Write the output at Table 2-2.


13. Create a connection as shown in Figure 2-4.

12

Figure 2-4 Blinking Connection


14. Modify the int led values as using the data in Table 2-3.
15. Simulate the program.
16. Fill-out Table 2-3.
6. Data and Results:
Source Code (Procedure 4)

Binary Sketch size:

Error Message

13

Delay Values
1. 100
2. 300
3. 500
4. 700
5. 900
Resistor
Value
1. 470
2. 2.2K
3. 10K

Table 2-1 Delay


Observation

Table 2-2 LED Output


Output

Table 2-3 Blinking Output


int led Value
Observation
1. 13
2. 7
3. 10
4. 100
5. 30
7. Data Analysis:

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.

Figure 3-1 RGB LED Pin-out


15

Current Limiting Resistors (270 ohm) (red-purple-brown)


Most LEDs are designed to work with a voltage between 1.5v and 3v. As most microcontrollers
(including the Arduino) operate on 5 volts a current limiting resistor is required.
Consult your LEDs datasheet for maximum ratings but we like to use 270 ohm resistors. This limits the
current to ~20mA, well within most LEDs and microcontroller ratings. Figure 3-1 shows the test
schematic for RGB LED.

Pulse Width Modulation (PWM)

Figure 3-1 RGB Test Schematic

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.

Arduino/ Gizduino board


Computer
USB Cable
Power Source
Bread board
RGB LED
Resistors (270 , 470, 500, and 1K)
Connecting wires
16

5. Procedure:
1. Open Sketch software.
2. Create a circuit and board connection as shown in Figure 3-4.

Figure 3-4. RGB Breadboard Connection


17

3. Copy the source code at Figure 3-5.

Figure 3-5 RGB LED Source Code


4. Simulate the program.
5. Determine the output at Table 3-1.
6. Draw the PWM graph at the data and results for the given signals below
a. 1/20
b. 10/20
c. 18/20
7. Draw a PCB design at the space provided.
18

6. Data and Results:


Table 3-1 Color Settings
Color Settings
1. 255,0,0
2. 0,255,0
3. 0,0,255
4. 255,255,0
5. 80,0,80
6. 0,255,255
7. 0x4B,0x0,0x82
8. 0x3A,0xDF,0x00
9. 0x24,0x3B,0x0B
10. 0x00,0xFF,0x00
1/20

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

Figure 4-1 595 Pin Configuration


22

Shift registers hold an eight memory location as shown in Figure 4-2.

Figure 4-2 Pin Configuration and Pulse


4. Materials and Equipment:
1. Arduino/ Gizduino board
2. Computer
3. USB Cable
4. Power Source
5. Bread board
6. 8 LED
7. 8 Resistors (270 )
8. Connecting wires
23

5. Procedure:
1. Create a Circuit and board connection as shown in Figure 4-3.

Figure 4-3 8 LED Lights Circuit


2. Open Sketch software.
3. Copy the source code at Figure 4-4
24

Figure 4-4 8 LED Lights Code


4. Simulate the program.
5. Fill-up Table 4-1.
6. Save the program as Activity 4-1.
25

7. Create a new file.


8. Copy the program at Figure 4-5.

Figure 4-5 Shift Register Brightness Source Code


9. Simulate the program.
26

10.
11.
12.
13.
14.
15.
16.
17.
18.

Fill-out Table 4-2.


Save the program as Activity 4-2.
Create a new file.
Copy the program at Appendix A.
Save the program as Activity 4-3.
Simulate the program.
Draw the sequential output at the data and results.
Create a new file.
Copy the program at Figure 4-6.

Figure 4-6 Serial Monitor Code


19. Determine the output at COM4.
20. Write the COM4 output at the data and results
21. Fill-out Table 4-3.
27

6. Data and Results:


Case
pinMode(latchPin,INPUT)
pinMode(dataPin,INPUT)
pinMode(clockPin,INPUT)
led=1
i=1
i>8
i-delay(100)
delay(1000)
delay(1500)
Both
digitalWrite(latchPin,High)
Both
digitalWrite(latchPin,Low)

Table 4-1. Display Modification


Output
Observation

Table 4-2. Brightness Modification


Case
Output
Observation
setBrightness(400), delay(1000)
setBrightness(300), delay(1000)
setBrightness(200), delay(1000)
setBrightness(100), delay(1000)
setBrightness(50), delay(1000)
Sequential Output

28

Case
4800 baud
14400 baud
19200 baud
28800 baud
38400 baud
57600 baud
115200 baud

Table 4-3. Baud Rate


COM4 Output
Observation

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.

Figure 5-1 Tactile Switch


30

4. Materials and Equipment:


1.
2.
3.
4.
5.
6.
7.
8.
9.

Arduino/ Gizduino board


Computer
USB Cable
Power Source
Bread board
2 Tactile push switch
8 LED Lights
8 Resistors (270 )
Connecting wires

5. Procedure:
1. Create a circuit connection as shown in Figure 5-2.

Figure 5-2 Breadboard Connection

31

2. Open Sketch software.


3. Copy the program in Figure 5-3

Figure 5-3 Source Code


4.
5.
6.
7.

Fill-out Table 5-1.


Save the program as Activity 5-1.
Draw a schematic diagram for the circuit at the data and results
Write a runnable program at the data and result using while function.

6. Data and Results:


Table 5-1. Display Modification
Output

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

While function Source Code

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

Figure 6-1 RGB Pin Configuration


Reference:
www.chromationsystems.com/store/index.php?main_page=product_info&products_id=182
4. Materials and Equipment:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.

Arduino/ Gizduino board


Computer
USB Cable
Power Source
Bread board
RGB LED (Common Cathode)
3 Tactile Push Switches
8 Resistors (270 )
2x2 Printed Circuit Board
Ferric Chloride
Plastic Container
Permanent Marker
Masking Tape
Mini Drill
Connecting wires
35

5. Procedure:
1. Create a Breadboard connection as shown in Figure 6-1.

Figure 6-1 RGB and Switches Breadboard Connection


2. Draw a schematic diagram at the data and results.
3. Open Sketch software.
4. Copy the program in Figure 6-2.

36

5.
6.
7.
8.

Figure 6-2 Source Code


Simulate the program.
Save the file as Activity 6-1.
Fill-out Table 6-1 at the data and results.
Design a PCB layout for Figure 6-1.

37

6. Data and Results:


Schematic Diagram

Table 6-1. Display Modification


Case
Output
if (digitalRead(redSwitchPin)==HIGH)
red-if(red<255)red=0
analogWrite(redLEDPin,blue)
analogWrite(redLEDPin,green)
delay(100)
delay(90)
delay(80)
delay(70)
delay(60)
delay(50)
delay(20)

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.

Figure 7-1 Variable Resistor (Pots)


Pot has a circular 'track' that acts as a resistor; in this case it is a 10 k resistor. However, the difference
with a pot is that there is also a middle connection called the 'slider'. This connection is rotated when
turning the pot. So if it is connected to one end of the pot to 5V and the other is to the GND, then the
voltage at the slider will vary between 0 and 5V.
39

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. 10K Variable resistor (pot)
8. Potentiometer
9. 8 Resistors (270 )
10. 74HC595 Shift Register
11. IC Socket
12. 2x2 Printed Circuit Board
13. Ferric Chloride
14. Plastic Container
15. Permanent Marker
16. Masking Tape
17. Mini Drill
18. Connecting wires
5. Procedure:
1. Create a bread board layout as shown in Figure 7-2.

Figure 7-2 Bread Board Connection


40

2.
3.
4.
5.
6.
7.

Copy the program in Appendix B


Simulate the program.
Save file as Activity 7-1.
Write the COM4 output at the data and results
Fill-out Table 7-1.
Create a new program as shown in Figure 7-3.

8. Fill-up Table 7-2.

Figure 7-3 Source Code

41

6. Data and Results:

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--

Table 7-1. Baud Rate


COM4 Output
Observation

Table 7-2. Display Modification


Output

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.

Figure 8-1 Piezo Sounder


45

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.

Figure 8-2 Breadboard Connection


46

2.
3.
4.
5.
6.
7.
8.
9.
10.
11.

Remove and replace the pot by a photocell.


Open Sketch software.
Copy the source code at Appendix C
Upload the program.
Save the file as Activity 8-1.
Fill-out Table 8-1.
Design a PCB circuit for Figure 8-1.
Draw a schematic diagram at the data and results.
Create a PCB and Arduino/Gizduino board connection.
Create a new breadboard circuit connection as shown in Figure 8-3.

Figure 8-3. Breadboard connection using Piezo Sounder


12.
13.
14.
15.
16.
17.

Copy the source code at Appendix D


Upload the program.
Save the file as Activity 8-2.
Create a new file.
Save the file as Activity 8-3.
Copy the Source code at Figure 8-4.

47

Figure 8-4 Loop Sound Source Code


18. Upload the program.
19. Answer the question at the data and results.
6. Data and Results:
Case
pinMode(latchPin,INPUT)
pinMode(dataPin,INPUT)
pinMode(clockPin,INPUT)
i-int lightpin= 5;
int latchpin=6;
int clockpin=4;
int datapin=0;

Table 8-1. Display Modification


Output

Observation

Schematic Diagram

Is there an output sound produced by the piezo sounder? ______

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.

Arduino/ Gizduino board


Computer
USB Cable
Power Source
Bread board
LCD Display (16x2 Characters)
10K Variable Resistor
1K Resistor
Photocell
TMP36 Temperature Sensor
Connecting wires

51

5. Procedure:
1. Create a connection as shown at Figure 9-1.

Figure 9-1 LCD Breadboard Connection


2. Open Sketch software.
3. Copy the program at Figure 9-2.
52

Figure 9-2 LCD Source Code


4.
5.
6.
7.
8.

Upload the program.


Draw the LCD output at the data and results
Save the file as Activity 9-1.
Write a temperature program that will compute and display an output using a unit in Celsius.
Draw a schematic diagram for Figure 9-1.
53

6. Data and Results:


LCD Output

Program Source Code

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.

Figure 10-1 Transistor


56

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.

Figure 10-2 Motor Connection Schematic Diagram


The pin D3 of the Arduino is connected to the resistor. Just like when using an LED, this limits the
current flowing into the transistor through the base. There is a diode connected across the connections
of the motor. Diodes only allow electricity to flow in one direction (the direction of their arrow).
57

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.

Figure 10-3 Servo Motor Cycle


The end points of the servo can vary and many servos only turn through about 170 degrees.
L293D
This is a very useful chip. It can actually control two motors independently. Most of the pins on the right
hand side of the chip are for controlling a second motor. As shown in Figure 10-4.

58

Figure 10-4 L293 Pin Configuration


A second motor would be attached between OUT3 and OUT4. Three more control pins are needed to
control the EN2 that is connected to a PWM enabled output pin on the Arduino IN3 and IN4 are
connected to digital outputs on the Arduino. The L293D has two +V pins (8 and 16). The pin '+Vmotor
(8) provides the power for the motors, and +V (16) for the chip's logic. Connect both of these to the
Arduino 5V pin. However, if there are more powerful motor, or a higher voltage motor, it would provide
the motor with a separate power supply using pin 8 connected to the positive power supply and the
59

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.

Figure 10-5 Stepper Motor


By energizing the coils in the right order, the motor is driven round. The number of steps that the stepper
motor has in a 360 degree rotation is actually the number of teeth on the cog. This motor has 48 steps,
but then the motor also incorporates a reduction gearbox of 1:16 that means that it needs 16 x 48 = 768
steps. This connection is only provided if a different type of drive circuit that does not allow the current in
each coil to be reversed. Having a center connection to each coil means that it can both energize the left
or right side of the coil, and get the effect of reversing the current flow without having to use a circuit that
can reverse the current. Since, L293D is very good at reversing the current, there no need this for
common connection, the supply current can either direct go to the whole of each of the coils.
60

4. Materials and Equipment:


1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.

Arduino/ Gizduino board


Computer
USB Cable
Power Source
Bread board
Connecting wires
1 Small 6V DC Motor
1 PN2222 Transistor
1 1N4001 diode
1 Resistor (270)
1 Servo Motor
10k Variable Resistor
1 Capacitor (100 F)
1 L293D IC
1 Tactile Push Switch
1 5V Stepper Motor

5. Procedure:
1. Create a circuit and board connection as shown in Figure 10-6.

Figure 10-6 DC Motor Board Connection


61

2. Open Sketch software.


3. Copy the source code at Figure 10-7.

Figure 10-7 DC Motor Source Code


62

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.

Save the file as Activity 10-1.


Compile the program.
Write the COM4 output at the data and results.
Reverse the connection.
Compile the program.
Write the COM4 output at the data and results.
Create a new circuit and board connection as shown in Figure 10-8.
Create a new program
Copy the program at Figure 10-9.
Save the file as Activity 10-2.
Compile the program.
Write the COM4 output at the data and results.
Reverse the connection.
Compile the program.
Write the COM4 output at the data and results.
Create a new circuit and board connection as shown in Figure 10-10.
Create a new program
Copy the program at Figure 10-11.
Save the file as Activity 10-3.
Compile the program.
Write the COM4 output at the data and results.
Reverse the connection.
Compile the program.
Write the COM4 output at the data and results.
Create a new circuit and board connection as shown in Figure 10-12.
Create a new program
Copy the program at Figure 10-13.
Save the file as Activity 10-4.
Compile the program.
Write the COM4 output at the data and results.
Reverse the connection.
Compile the program.
Write the COM4 output at the data and results.

63

Figure 10-8 Servo Motor Connections

64

Figure 10-9A Sweep Movement

Figure 10-9B Knob Movement

Figure 10-9 Servo Motor Code

Figure 10-10 DC Reverse Board Connection


65

Figure 10-11 Source Code for Bi-directional Movement

Figure 10-12 Stepper Motor Board Connection

66

Figure 10-13 Stepper Motor Code


6. Data and Results:

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

dataArray[7] = 0x80; //10000000


dataArray[8] = 0x00; //00000000
dataArray[9] = 0xE0; //11100000
//function that blinks all the LEDs
//gets passed the number of blinks and the pause time
blinkAll_2Bytes(2,500);
}
void loop() {
for (int j = 0; j < 10; j++) {
//load the light sequence you want from array
data = dataArray[j];
//ground latchPin and hold low for as long as you are
transmitting
digitalWrite(latchPin, 0);
//move 'em out
shiftOut(dataPin, clockPin, data);
//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite(latchPin, 1);
delay(300);
}
}

// the heart of the program


void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
// This shifts 8 bits out MSB first,
//on the rising edge of the clock,
//clock idles low
//internal function setup
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
72

//clear everything out just in case to


//prepare shift register for bit shifting
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
//for each bit in the byte myDataOut
//NOTICE THAT WE ARE COUNTING DOWN in our for loop
//This means that %00000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i=7; i>=0; i--) {
digitalWrite(myClockPin, 0);
//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000
// and proceeds to set pinState to 1.
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
//Sets the pin to HIGH or LOW depending on pinState
digitalWrite(myDataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite(myClockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite(myDataPin, 0);
}
//stop shifting
digitalWrite(myClockPin, 0);
}

//blinks the whole register based on the number of times you


want to
//blink "n" and the pause between them "d"
//starts with a moment of darkness to make sure the first blink
73

//has its full visual effect.


void blinkAll_2Bytes(int n, int d) {
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, 0);
shiftOut(dataPin, clockPin, 0);
digitalWrite(latchPin, 1);
delay(200);
for (int x = 0; x < n; x++) {
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, 255);
shiftOut(dataPin, clockPin, 255);
digitalWrite(latchPin, 1);
delay(d);
digitalWrite(latchPin, 0);
shiftOut(dataPin, clockPin, 0);
shiftOut(dataPin, clockPin, 0);
digitalWrite(latchPin, 1);
delay(d);
}
}

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

lcd: a variable of type LiquidCrystal

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

LiquidCrystal - Text Direction (leftToRight() and rightToLeft()

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:

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

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:

Library originally added 18 Apr 2008 by David A. Mellis


library modified 5 Jul 2009 by Limor Fried (http://www.ladyada.net)
example added 9 Jul 2009 by Tom Igoe
modified 22 Nov 2010 by Tom Igoe
This example code is in the public domain.
http://arduino.cc/en/Tutorial/LiquidCrystalTextDirection
*/
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int thisChar = 'a';
92

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

You might also like