Hardware Reference
In-Depth Information
Attach the Ethernet shield to your Arduino, and connect the shield's Ethernet
port to an available Ethernet port on your home router using an Ethernet cable.
This should be an ordinary Ethernet crossover cable (nearly all cables will be
labeled as “crossover” on the sheathing). Connect the USB cable to your com-
puter and Arduino for programming. If your router is not near the computer
that you want to use for programming, program it first, and then connect it to
the router. However, some of the examples depend on debugging information
shown via the serial monitor. If you want your system to operate without a
serial connection, you might want to connect it to an LCD for displaying the IP
address, which you will otherwise be displaying via the serial terminal later
in the chapter. You can use your knowledge from Chapter 10, “Liquid Crystal
Displays,” to print information to the LCD instead of the serial terminal if you
want; that is not covered in this chapter.
ControllingYourArduinofromtheWeb
First, you configure your Arduino to act as a web server. Using some HTML
forms, and the integrated Ethernet libraries, you have your Arduino automati-
cally connect to the network and serve a web page that you can access to control
some of its I/O pins. You expose buttons to the web interface for toggling the
colors in an RGB LED and controlling a speaker's frequency. The program that
you write for this purpose is extensible, allowing you to add control of additional
devices as you become more comfortable working with the Arduino.
SettingUptheI/OControlHardware
First, set up some test hardware connected to your Arduino server so that you
can control it from the web. For this example, you connect an RGB LED and a
piezo or ordinary speaker. Wire it up as shown in Figure 14-2. Recall that Pins
4, 10, 11, 12, and 13 are used for communication with the Ethernet chip and SD
card, so you cannot use those pins for general I/O. You connect your RGB LED
to pins 5, 6, and 7. The speaker connects to pin 3.
DesigningaSimpleWebPage
It's useful to design a simple web page separately from the Arduino before try-
ing to get the Arduino to serve it up so that you can ensure that it looks the way
you want. Your web page will have simple buttons for toggling each LED, and
will have a slider for adjusting the frequency at which a speaker is playing. It
will use HTML form elements to render these components, and it will use the
HTTP GET protocol to send commands from the browser to the server. As you
design the website, it won't actually be hooked up to a server, so interacting
with it will not elicit any action from the Arduino, or anything else.
 
Search WWH ::




Custom Search