I am working on a web server project for work. I have a web server setup with an Arduino Meg2560 with Ethernet. I also have a 16 relay board connected to Ethernet with its own IP. I wanted to see if there is a way I can make calls to the relay board via IP from the Arduino Webserver. For example Relay 1 on the relay board can be turned on by typing but this opens the web GUI on the board. I need to do the same thing but without opening the webpage or web GUI. enter image description here

    #include <SPI.h>
    #include <Ethernet.h>

    // MAC address from Ethernet shield sticker under board
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    IPAddress ip(192, 168, 1, 177); // IP address
    EthernetServer server(80);  // Server Port 80

    void setup()
      Ethernet.begin(mac, ip);  

    void loop()
EthernetClient client = server.available();  // try to get client

if (client) {  // got client?
    boolean currentLineIsBlank = true;
    while (client.connected()) {
        if (client.available()) {   // client data available to read
            char c = client.read(); // read 1 byte (character) from client
            // last line of client request is blank and ends with \n
            // respond to client only after last line received
            if (c == '\n' && currentLineIsBlank) {
                // send a standard http response header
                client.println("HTTP/1.1 200 OK");
                client.println("Content-Type: text/html");
                client.println("Connection: close");
                // send web page
                client.println("<!DOCTYPE html>");
                client.println("<title>Arduino Web Page</title>");
                client.println("<h1>Hello from Arduino!</h1>");
                client.println("<p>A web page from the Arduino server</p>");
            // every line of text received from the client ends with \r\n
            if (c == '\n') {
                // last character on line of received text
                // starting new line with next character read
                currentLineIsBlank = true;
            else if (c != '\r') {
                // a text character was received from client
                currentLineIsBlank = false;
        } // end if (client.available())
    } // end while (client.connected())
    delay(1);      // give the web browser time to receive the data
    client.stop(); // close the connection
} // end if (client)


  • I have my web server working and ready to go on my Arduino I just need help adding code to it for calling my relay board. Thank you
    – Kevin
    Commented Jul 17, 2015 at 16:53
  • Which model of relay board is this? I don't see any need for server in arduino as you already have one in the relay module.
    – user.dz
    Commented Jul 17, 2015 at 21:50
  • So what if it "opens a GUI" when you send a GET request to that URL. That doesn't mean you have to DO anything with that GUI data - you can just ignore it completely. Just send the GET request then close the connection.
    – Majenko
    Commented Jul 17, 2015 at 21:56

1 Answer 1


Documentation on the controller you are using is pretty scant, but it looks like you just need to make a GET request to the URI corresponding to the action you need to take. : Relay-01 OFF : Relay-01 ON : Relay-02 OFF : Relay-02 ON : Relay-03 OFF : Relay-03 ON : Relay-8 OFF : Relay-8 ON : Enter : Exit : Next Page : Next Page

For example If I wanted to turn off relay 3, I would simple make a GET request to and close the connection. Example code:

IPAddress server(192,168,1,4);
EthernetClient client;
client.connect(server, 80);
client.println("GET /30000/04 HTTP/1.1");
client.println("Connection: close");
  • How do I add that to the Arduino web server I think that is exacly what I am needing to add I would like to just have a link for now say Relay 1 On and it do the Get /30000/01 to turn it on. I added my web server Sketch to the main question. Thank you
    – Kevin
    Commented Jul 18, 2015 at 7:04
  • Thank you Jake I was able to get the GET code to work. I am new to the Arduino so it took me awhile to figure out what the code is doing.
    – Kevin
    Commented Jul 19, 2015 at 7:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.