Hardware Reference
In-Depth Information
NOTE Youcanwatchademovideoofthesweepingdistancesensoronline:
www.exploringarduino.com/content/ch4 .Youcanalsofindthisvideoonthe
Wileywebsiteshownatthebeginningofthischapter.
Start by hot-gluing your distance sensor to the top of a servo motor, as shown
in Figure 4-13. I like to use hot glue because it holds well and is fairly easy to
remove if you need to. However, you could also use super glue, putty, or tape
to get the job done.
Figure 4-13: IR distance sensor mounted to the servo
Next, hook your servo up to your Arduino, using the 5V regulator to power
it, just as you did before. The IR distance sensor replaces the potentiometer and
plugs into analog pin 0. Four LEDs plug into pins 3, 5, 6, and 11 through 1kΩ
resistors. The Arduino Uno has six total PWM pins, but pins 9 and 10 cannot
create PWM signals (using analogWrite ) when you are using the servo library.
This is because the servo library uses the same hardware timer as the one used
to control PWM on those two pins. Hence, the other four PWM pins were chosen.
(If you want to do this project with more LEDs, either use the Arduino Mega
or implement a software PWM solution, something this topic does not cover.)
Follow the wiring diagram in Figure 4-14 to confirm that you have everything
wired up correctly. I chose to use blue LEDs, but you can use any color you want.
After you have it all wired up, consider taping it down, as shown in Figure 4-13.
Search WWH ::




Custom Search