You are on page 1of 46

Faculty Of Engineering

Mechanical Engineering

ME 425
Visual Output

Dr. Laith Sawaqed


UNDERGRADUATE PROGRAM
Fall Semester
2016
Introduction:
Digital Output:

Digital output causes the voltage on a pin to be either high


(5 volts) or low (0 volts). Use the digitalWrite(outputPin,
value) function to turn something on or off. The function
has two parameters: outputPin is the pin to control, and
value is either HIGH (5 volts) or LOW (0 volts). For the
pin voltage to respond to this command, the pin must have
been set in output mode using the pinMode(outputPin,
OUTPUT) command. The sketch in Recipe 7.1 provides an
example of how to use digital output.

Faculty Of Engineering 2
Mechanical Engineering
Introduction:
Analog Output:

The analogWrite function is not truly analog, although it can behave


like analog, as you will see. analogWrite uses a technique called Pulse
Width Modulation (PWM) that emulates an analog signal using digital
pulses.
PWM works by varying the proportion of the pulses on time to off
time, as shown in Figure 7-1. Low-level output is emulated by
producing pulses that are on for only a short period of time. Higher
level output is emulated with pulses that are on more than they are off.
When the pulses are repeated quickly enough (almost 500 times per
second on Arduino), the pulsing cannot be detected by human senses,
and the output from things such as LEDs looks like it is being smoothly
varied as the pulse rate is changed.

Faculty Of Engineering 3
Mechanical Engineering
Introduction:

Faculty Of Engineering 4
Mechanical Engineering
Adjusting the Brightness of an
LED:
Problem:
You want to control the intensity of one or more LEDs
from your sketch.

Solution:
Connect each LED to an analog (PWM) output. Use the
wiring shown in Figure 7-2. The sketch will fade the
LED(s) from off to maximum intensity and back to off,
with each cycle taking around five seconds:

Faculty Of Engineering 5
Mechanical Engineering
Adjusting the Brightness of an
LED:

Faculty Of Engineering 6
Mechanical Engineering
Adjusting the Brightness of an
LED:

Faculty Of Engineering 7
Mechanical Engineering
Driving High-Power LEDs:
Problem:
You need to switch or control the intensity of LEDs that
need more power than the Arduino pins can provide.
Arduino chips can only handle current up to 40 mA per pin.

Solution:
Use a transistor to switch on and off the current flowing
through the LEDs. Connect the LED as shown in Figure 7-
4. You can use the same code as shown in the previous
recipes (just make sure the pins connected to the transistor
base match the pin number used in your sketch).

Faculty Of Engineering 8
Mechanical Engineering
Driving High-Power LEDs:

Faculty Of Engineering 9
Mechanical Engineering
Adjusting the Color of an LED:
Problem:
You want to control the color of an RGB LED under
program control.

Solution:
RGB LEDs have red, green, and blue elements in a single
package, with either the anodes connected together (known
as common anode) or the cathodes connected together
(known as common cathode). Use the wiring in Figure 7-6
for common anode (the anodes are connected to +5 volts
and the cathodes are connected to pins). Use Figure 7-2 if
your RGB LEDs are common cathode.
Faculty Of Engineering 10
Mechanical Engineering
Adjusting the Color of an LED:

Faculty Of Engineering 11
Mechanical Engineering
Adjusting the Color of an LED:

Color wheel:

Faculty Of Engineering 12
Mechanical Engineering
Adjusting the Color of an LED:

Faculty Of Engineering 13
Mechanical Engineering
Adjusting the Color of an LED:

Faculty Of Engineering 14
Mechanical Engineering
Adjusting the Color of an LED:

Faculty Of Engineering 15
Mechanical Engineering
Adjusting the Color of an LED:

Faculty Of Engineering 16
Mechanical Engineering
Sequencing Multiple LEDs:
Creating a Bar Graph:
Problem:
You want an LED bar graph that lights LEDs in proportion
to a value in your sketch or a value read from a sensor.

Solution
You can connect the LEDs as shown in Figure 7-2 (using
additional pins if you want more LEDs). Figure 7-7 shows
six LEDs connected on consecutive pins.

Faculty Of Engineering 17
Mechanical Engineering
Sequencing Multiple LEDs:
Creating a Bar Graph:

Faculty Of Engineering 18
Mechanical Engineering
Sequencing Multiple LEDs:
Creating a Bar Graph:

Faculty Of Engineering 19
Mechanical Engineering
Sequencing Multiple LEDs:
Creating a Bar Graph:

Faculty Of Engineering 20
Mechanical Engineering
Sequencing Multiple LEDs:
Creating a Bar Graph:

Faculty Of Engineering 21
Mechanical Engineering
Sequencing Multiple LEDs: Making a
Chase Sequence (Knight Rider):
Problem:
You want to light LEDs in a chasing lights sequence (as
seen on the TV show Knight Rider).

Solution:
You can use the same connection as shown in Figure 7-7:

Faculty Of Engineering 22
Mechanical Engineering
Sequencing Multiple LEDs: Making a
Chase Sequence (Knight Rider):

Faculty Of Engineering 23
Mechanical Engineering
Controlling an LED Matrix
Using Multiplexing:
Problem:
You have a matrix of LEDs and want to minimize the
number of Arduino pins needed to turn LEDs on and off.

Solution:
This sketch uses an LED matrix of 64 LEDs, with anodes
connected in rows and cathodes in columns (as in the
Jameco 2132349). Dual-color LED displays may be easier
to obtain, and you can drive just one of the colors if that is
all you need (Figure 7-8 shows the connections):

Faculty Of Engineering 24
Mechanical Engineering
Controlling an LED Matrix
Using Multiplexing:

Faculty Of Engineering 25
Mechanical Engineering
Controlling an LED Matrix
Using Multiplexing:

Faculty Of Engineering 26
Mechanical Engineering
Controlling an LED Matrix
Using Multiplexing:

Faculty Of Engineering 27
Mechanical Engineering
Controlling an LED Matrix
Using Multiplexing:

Faculty Of Engineering 28
Mechanical Engineering
Displaying Images on an LED
Matrix:
Problem:
You want to display one or more images on an LED
matrix, perhaps creating an animation effect by quickly
alternating multiple images.

Solution:
This Solution can use the same wiring as in Recipe 7.7. The
sketch creates the effect of a heart beating by briefly
lighting LEDs arranged in the shape of a heart. A small
heart followed by a larger heart is flashed for each
heartbeat (the images look like Figure 7-9):

Faculty Of Engineering 29
Mechanical Engineering
Displaying Images on an LED
Matrix:

Faculty Of Engineering 30
Mechanical Engineering
Displaying Images on an LED
Matrix:

Faculty Of Engineering 31
Mechanical Engineering
Displaying Images on an LED
Matrix:

Faculty Of Engineering 32
Mechanical Engineering
Displaying Images on an LED
Matrix:

Faculty Of Engineering 33
Mechanical Engineering
Displaying Images on an LED
Matrix:

Faculty Of Engineering 34
Mechanical Engineering
Driving a 7-Segment LED
Display:
Problem:
You want to display numerals using a 7-segment numeric
display.

Solution:
The following sketch displays numerals from 0 to 9 on a
single-digit, 7-segment display. Figure 7-12 shows the
connections. The output is produced by turning on
combinations of segments that represent the numerals:

Faculty Of Engineering 35
Mechanical Engineering
Driving a 7-Segment LED
Display:

Faculty Of Engineering 36
Mechanical Engineering
Driving a 7-Segment LED
Display:

Faculty Of Engineering 37
Mechanical Engineering
Driving a 7-Segment LED
Display:

Faculty Of Engineering 38
Mechanical Engineering
Driving a 7-Segment LED
Display:

Faculty Of Engineering 39
Mechanical Engineering
Driving a 7-Segment LED
Display:

Faculty Of Engineering 40
Mechanical Engineering
Driving Multidigit, 7-Segment
LED Displays: Multiplexing:
Problem:
You want to display numbers using a 7-segment display
that shows two or more digits.

Solution:
Multidigit, 7-segment displays usually use multiplexing. In
earlier recipes, multiplexed rows and columns of LEDs
were connected together to form an array; here,
corresponding segments from each digit are connected
together (see Figure 7-13):

Faculty Of Engineering 41
Mechanical Engineering
Driving Multidigit, 7-Segment
LED Displays: Multiplexing:

Faculty Of Engineering 42
Mechanical Engineering
Driving Multidigit, 7-Segment
LED Displays: Multiplexing:

Faculty Of Engineering 43
Mechanical Engineering
Driving Multidigit, 7-Segment
LED Displays: Multiplexing:

Faculty Of Engineering 44
Mechanical Engineering
Driving Multidigit, 7-Segment
LED Displays: Multiplexing:

Faculty Of Engineering 45
Mechanical Engineering
Driving Multidigit, 7-Segment
LED Displays: Multiplexing:

Faculty Of Engineering 46
Mechanical Engineering

You might also like