Project Description

Description:

This tutorial explains how to control a LED from PC using Arduino ethernet shield. The Arduino ethernet shield is use WIZnet W5100 ethernet chip.

143

This shield is also has a micro SD card socket to interfacing with a micro SD card. Arduino communicates with both W5100 and micro SD card using the SPI bus. This is on digital pins 13 (SCK), 12 (MISO), 11 (MOSI), 10 (SS for the W5100), and 4 (SS for the micro SD card). To make a program using this shield is very easy, because there is a library from Arduino both for ethernet and SD.

144

To begin make code for control LED, we must add SPI library and Ethernet library.

To make a LED can be controlled from PC, we will program the Arduino as a server. The arduino server will wait for the connection from cilent. The client will sends command to the Arduino via port 23 of TCP port numbers. For making Arduino as a server we need 3 parameter: MAC address, IP address, and port number.

we must make server object and string variable called commandStr for storing command from client.

we initialize digital pin 2 as an output for LED and also initialize the ethernet and the server. The serial port here is used for debugging only.

In the loop function, we monitoring the client. If there is a client connected and send command to Arduino, we read every character that the client sends and store that command in commandStr variable until new line character.

If the command has received, then we need process that command. I am define 3 command that the PC will send to the Arduino: “led=0″ for turn off the LED, “led=1″ for turn on the LED, and led=? for querying the status of LED.

Demo: