Remote LED control with Arduino and the Ethernet Shield



The process of building an Arduino device that can be controlled over the Internet Inorder to achieve truly global control over the Internet, the Arduino+Ethernet shield is set up as a Web-client that receives commands from the Web-server.T





Wiring Diagram:



Hardware Components:


Ethernet shield(W5500)


In order to achieve truly global control over the Internet, the Arduino+Ethernet shield is set up as a Web-client that receives commands from the Web-server. Here, a command represents the status of LEDs – on or off; potentially, it can be some other desirable manipulation of I/O ports. A user can connect to the Web-server using any device capable of web-browsing (a desktop, laptop computer or a smartphone) and change the LED status (i.e. the command) with a click of a button. This change is then sent to the Arduino.

The status of 8 LEDs is stored in the MySQL database on the server; PHP scripts facilitate communication between Arduino and the database.

Hardware Setup:

The hardware set-up is rather straightforward. Arduino is first stacked with the Ethernet shield, which uses digital pins 10 through 13 for communication + pin 4 for the optional SD card reader. In order to avoid problems stemming from the lack of available I/O pins, we use a shift register to control the LEDs. With only 3 pins, the set-up depicted here allows one to control 8 outputs (more can be added by simply connecting additional shift registers). Pin 2 serves as the data pin, pins 3 and 5 are clock and latch inputs, respectively. Additional LED on pin 6 is used to indicate that the connection to the server has been established successfully. Just for fun, I made the controlled LEDs red and yellow, and the connection status LED green. The only one thing left is to connect Ethernet cable to the shield and power it up. The hardware part is now complete. All that’s left to do is writing the code – first for the Arduino itself and then for the Web-interface.

Ethernet shield is configured using DHCP, so Arduino has dynamic IP assigned by the router. The coding of this part is straightforward and closely follows Ethernet-shield example for simple web-client.

In order to communicate with the SQL database, each Arduino is pre-programmed with unique identifiers: device ID (1 character, ‘a’ for Arduino), device serial number (8 bit, ex. 00000001), and unique password for the MySQL database (8 characters). These values are stored in EEPROM and are read using function in the set-up part of the code. Database name is constructed as “db_” + deviceID + deviceSN. For example, the first Arduino reads LED values from the database named “db_a00000001”. Password and device properties (ID and SN) are then sent using GET request to the (read more below) Response by the PHP-script has form “LEDxxxxxxxx” (for example, “LED00000001” or “LED10101010”). The code looks for letters “LED” in the response and then reads out all eight LED values. The entire main part is enclosed into the infinite loop which takes care of sending requests and analysing the response.

Download the sketch from the Below Link:

Assembled Set-up:






Please Login to comment
Notify of