Hardware Reference
In-Depth Information
waves are created, and the device calculates the time taken for those waves to
return to the device. This results in surprisingly accurate results and is good
for distances up to four meters away.
Figure 11-3: HC-SR04 Ultrasonic Sensor
The sensor has four pins: one for the power, one for the ground, one to issue a
pulse, and the i nal pin to read the distance. The result is not in a binary format;
this pin will not output text or data in a serial fashion. Instead, the pulse length
is proportional to the time taken to receive a result. Fortunately, the Arduino
can handle this with a single command.
To allow the user to read the data easily, an LCD screen will be used. This
setup could easily be used with a serial device, but that doesn't make sense. The
serial port displays text and so does an alphanumeric LCD screen. Only LCD
screens are signii cantly more user-friendly.
This example uses a SainSmart LCD Keypad shield. This shield contains
a 16 x 2 LCD screen with a nice blue backlight. It contains all the electronics
necessary to use an LCD screen: power, the backlight control, all connected to
the Arduino on digital pins. It uses four data pins, and therefore will use 4-bit
commands. The example is not specii c to this shield, but if you use a different
screen, make sure your code and wiring rel ects the necessary changes.
Hardware
The SainSmart LCD Keypad shield is a fairly large device. A normal 16 x 2
LCD screen is about as long as an Arduino Uno, and this shield covers the Uno
completely, making it difi cult to add additional peripherals. For this reason,
the Arduino Mega2560 was chosen. It is longer than the Uno, and even with the
shield present, there are still a large amount of I/O pins available. The HC-SR04
ultrasonic distance sensor is a small device, and by chance, is exactly as wide as
 
Search WWH ::




Custom Search