The Arduino Inventor's Guide (44 page)

BOOK: The Arduino Inventor's Guide
8.96Mb size Format: txt, pdf, ePub

Rather than having to control each of the 40 pixels for each character separately, the HD44780 driver chip interprets data sent over by the Arduino using four data lines and two control lines and converts this into the character to display. To further simplify the interface, the Arduino community has written an LCD library for writing code to the LCD. We’ll look at that in the code.

DRAG RACE TIMER OPERATION

Before we start wiring the electronics, let’s discuss how the sketch will function. We designed this race timer so that when we push a button the servo moves up, opening the starting gate that allows the car to roll down the track. At the same time, the Arduino records the starting time and waits to see when the car reaches the photoresistor at the bottom of the track, which uses the same light-sensor circuit used in the Night-Light in
Project 5
. You’ll embed the light sensor in the center of the track so that when the car passes over it, it will create a shadow that the Arduino can detect. When the Arduino detects the shadow, it will record the stopping time and calculate the total time as the stopping time minus the starting time. If this seems similar to the Reaction Timer from
Project 4
, that’s because it is!

BUILD THE LCD CIRCUIT

You’ll start by building the LCD circuit. The LCD has 16 pins in total, but you’ll use just 12 of them.
Figure 9-6
shows the schematic for the LCD wiring.

FIGURE 9-6:
Schematic diagram of LCD wiring

With 16 pins, the LCD will take up 16 rows on the breadboard, so you’ll have to be careful about positioning with this project. You’ll mount the LCD in the first 16 rows on the right side of the breadboard. Be sure to connect the power and ground from the Arduino to the power and ground rails on the left side of the breadboard.

Note that the pins on the LCD are not labeled. As we walk you through wiring it up, we’ll refer to the pins on the LCD in order, starting with pin 1 at the bottom.

Power the LCD

The LCD has two separate power supplies for the backlight and for the control logic. You’ll need to wire these separately.

Connect pin 1 of the LCD to GND and pin 2 of the LCD to 5 V using the power rails on the breadboard. This provides power for the LCD’s control circuitry and the HD44780 LCD driver chip. Next, connect pin 15 on the LCD to 5 V and pin 16 on the LCD to GND, again using the power rails. These two connections power the LCD’s built-in backlight (see
Figure 9-7
).

FIGURE 9-7:
Connect the power for the LCD and the backlight.

Control the Contrast

You can adjust the contrast on the LCD screen. To do so, you control the voltage on pin 3 of the LCD using a simple voltage divider circuit with a potentiometer, similar to what you did for the Balance Beam in
Project 6
. Recall that a potentiometer is the same thing as a variable resistor: it has three pins, and as you turn the knob the resistance between the center pin and either of the end pins changes. If you connect the top and bottom pins of the potentiometer to 5 V and GND, you have a variable voltage divider where the voltage on the center pin will vary between 5 V and GND depending on how far you turn the knob (see
Figure 9-8
).

FIGURE 9-8:
Potentiometer schematic connected up as a variable voltage divider

Add the potentiometer to the breadboard just below the LCD. Connect the outside pins of the potentiometer to 5 V and GND, and connect the center pin to pin 3 on the LCD for the contrast control.

Now all you need to do is add the data and control wiring for the LCD.

Connect the Data and Control Wiring

You need seven more wires to connect to the LCD, including four data lines and three control lines. Pin 5 on the LCD is the read/write functionality that allows the Arduino to read from and write data to the display. You’re only going to use this read/write connection to send data to the LCD, or write to the device, so you can connect this to ground, known as “tying the pin low.” If you look back at
Table 9-1
, you’ll notice that the
label has a line over
Write
. As we mentioned earlier, this notation is often used in datasheets and documentation to indicate that a low signal will activate this feature. A low input is equivalent to ground, so add a wire to connect pin 5 of the LCD to GND, as shown in
Figure 9-9
.

FIGURE 9-9:
Connect pin 5 of the LCD to GND for the
control.

The final six wires will connect the LCD to the Arduino. Pins 11–14 on the LCD are the four data lines the Arduino will use to send information to the LCD. Connect these to the Arduino pins 10, 11, 12, and 13, as shown in
Figure 9-10
. The wires should go straight across from the Arduino board to the LCD without crossing.

The last two connections are Enable at pin 6 and Register Select at pin 4. The Enable pin is used to signal the data transfer to the LCD, and the Register Select pin determines whether the data represents a character to display or an instruction, like clearing the screen or moving the cursor; this gives you greater control over what’s displayed on the screen. Connect pin 9 on the Arduino to pin 6 on the LCD, and pin 8 on the Arduino to pin 4 on the LCD, as shown in
Figure 9-10
.

FIGURE 9-10:
Final wiring of the LCD circuit

Table 9-2
shows the LCD screen connections to help you make sure you have everything connected correctly.

TABLE 9-2:
LCD pin connections

LCD PIN

CONNECTION

16

GND

15

5 V

14

Arduino pin 13

13

Arduino pin 12

12

Arduino pin 11

11

Arduino pin 10

10

N/A

9

N/A

8

N/A

7

N/A

6

Arduino pin 9

5

GND

4

Arduino pin 8

3

Middle pin of potentiometer

2

5 V

1

GND

Test the LCD

Before you wire up more of the circuit, test it to make sure it’s working as expected so far. Connect your Arduino to your computer.

Other books

Rosethorn by Zavora, Ava
Lois Greiman by The Princess Masquerade
The Gods of Greenwich by Norb Vonnegut
Cold Wind by Nicola Griffith
Kindling by Abigail Colucci
Vodka by Boris Starling
Tyringham Park by Rosemary McLoughlin
Mad About You by Joan Kilby