Monitor your home remotely using the Arduino WiFi Shield

A few days ago, I posted an article about the Arduino WiFi shield, and I promised I will make another article showing a practical application, and of course using open-source software & hardware. So here it is ! In this article, I will show you how to monitor some data in your home using precisely this Arduino WiFi shield. Along with the Arduino Uno board, the final system will form an autonomous solution to monitor one or several sensors in your home. You could for example be interested in monitoring some contact sensors that are installed on your doors, and you want to know if the door has been opened or not. To emulate one of these sensors, I will simply use a small push button in this tutorial, but the principle is exactly the same.

Hardware requirements

The first thing you will need is an Arduino board. As usual, I used the Arduino UNO board for this tutorial, but any other official Arduino board should be fine as well. The second most important element in this tutorial is the Arduino WiFi shield. You will also need a small push button to emulate the sensor you want to measure, and a 10K ohms resistor.

Because we are using the WiFi shield, you will also need to have a wireless network running in your home, with WEP or WPA2 personal authentification. Don’t worry, I will show you how to do it in both cases.

Software requirements

Appart from the latest version of the Arduino IDE, you don’t need much software for this tutorial.

Hardware configuration

The hardware configuration is pretty simple. First, you have to plug the WiFi shield into your Arduino board. Then, you have to connect the resistor and the push button to the Arduino shield using a pull-down configuration: this means that if the button is not pressed, the input will be “pulled” to the ground. At the end, the button will be connected on pin number 2. Why number 2 ? This is because this is an interrupt pin, we will why we need that later. This is the schematic of this configuration:


Without this, the input could actually have a random state and we would trigger a “door has been opened” action even if nothing actually happened. The result should look like this:


Testing individual parts

Let’s now really dive into this project and test every part separately. First, let’s see if your Arduino board can connect to your local wireless network. For this, it is really easy, you can just use the official Arduino sketch for WPA networks which you can find here. If you have a network with WEP protection, you can find the corresponding tutorial here. Just modify your wireless network name, set the right password, and then upload the sketch to the shield with the Arduino IDE. Open the serial monitor, and you should see this:

Screen Shot 2013-03-15 at 9.59.28 PM

See this IP address ? This is the address of your shield. For now, just write it down, we’ll use it later. By the way, the “link” LED should turn green when the shield is connected. Sometimes it takes a while, so be patient :)

Finally, let’s test the push button. We want to detect the state of the button, so we will use the function digitalRead(). Here is the sketch to test the button:

Now upload the sketch, and open the serial monitor. You should see a lot of zeros, which is logical because the pin number 2 is connected to the ground. Then, just push the button, and if you see ones like on the following screenshot, it is all good.

Screen Shot 2013-03-15 at 10.01.36 PM

Putting it all together

It’s now time to combine everything we’ve learned so far, and read out remotely the value of of this push button. Actually, we will do something slightly different: we will check if the button changed it’s state (which mean for example that the front door of your flat has been opened), and put a message on a server if this happened. And the server of course, it will be the Arduino board with the WiFi shield.

First of all, we need to check if the button changed state. We could do as we did before, and use the digitalRead() function. But there is a problem with that function: what we will do is check the status of the button, which is fast, and then if something connects to the server running on our Arduino board, it will answer to this connection and reply with the state of the button. Sounds good to you ? Well … imagine now if the door is actually opened and closed again during the time the board is answering to the incoming connection: the board will completely miss it, and a thief for example is entering your home without you knowing it !

That’s why I spoke about using pin 2 before: it is actually one of the interrupt pin of the Arduino board. What this means is that on this pin, you can attach an interrupt with the attachInterrupt() function. This will call a special function if at any time the state of this pin change, in our case going from low to high:

Here, the function setDoorStatus will set a variable to indicate that the door has been opened. That  was for the sensor part, now we have to actually make our board answer with the status of the sensor if something (in this case, your computer) access the board. After connecting the shield to the wireless network, the next step is to see if there is some incoming connection. This is done by doing:

If this is the case, we start building a very simple HTML page by calling the println() function of client:

Then, we check the status of the variable door_opened, and print some information accordingly:

Finally, we finish the HTML page with:

And then we stop the connection:

These are the important parts of the code, as usual you can find the full code in our GitHub repository. Now, just upload the final code into the board, and wait until the “link” LED turns green on the board. Now, remember when I told you to write down the shield’s IP address ? This is where you will need it. Just open your favorite browser, and type down this IP into the URL field. This is what you should see:

Screen Shot 2013-03-15 at 10.10.00 PM

Now, press the button, and return to the page. The message should have changed to this:

Screen Shot 2013-03-15 at 10.10.45 PM

Which means our systems works ! You can now monitor what’s going on in your home directly from your computer. Of course, there would be some more adjustments to do so you can monitor it from anywhere in the world (right now it is limited to your own network), but you get the idea.

You can also find the corresponding video on Youtube:

Here is a summary of all the components you will need for this project:

Have fun with this projects, as always, don’t hesitate to comment, modify it, and even more important share !

Do you want to know more about building your own home automation systems? Then join our mailing list today by entering your email below.

  • Pingback: London Arduino #3 | Londuino()

  • Frans van Enschot

    Hi Marco,
    i have used your program, and it workt.
    but i have still a few questions.
    when i load the program below then it works only a short time, and also the lines somtimes missing characters.
    what do i wrong?
    hopefully can you help me.

    grtz frans

    WiFi Web Server

    A simple web server that shows the value of the analog input pins.
    using a WiFi shield.

    This example is written for a network using WPA encryption. For
    WEP or WPA, change the Wifi.begin() call accordingly.

    * WiFi shield attached
    * Analog inputs attached to pins A0 through A5 (optional)

    created 13 July 2010
    by dlf (Metodo2 srl)
    modified 31 May 2012
    by Tom Igoe



    char ssid[] = “Ziggo446F8″; // your network SSID (name)
    char pass[] = “KCk7KuczEW76″; // your network password
    int keyIndex = 0; // your network key Index number (needed only for WEP)

    int status = WL_IDLE_STATUS;

    WiFiServer server(80);

    void setup() {
    //Initialize serial and wait for port to open:
    while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only

    // check for the presence of the shield:
    if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println(“WiFi shield not present”);
    // don’t continue:

    // attempt to connect to Wifi network:
    while ( status != WL_CONNECTED) {
    Serial.print(“Attempting to connect to SSID: “);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    // you’re connected now, so print out the status:

    void loop() {
    // listen for incoming clients
    WiFiClient client = server.available();
    if (client) {
    Serial.println(“new client”);
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
    if (client.available()) {
    char c = client.read();
    // if you’ve gotten to the end of the line (received a newline
    // character) and the line is blank, the http request has ended,
    // so you can send a reply
    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”); // the connection will be closed after completion of the response
    client.println(“Refresh: 5″); // refresh the page automatically every 5 sec
    // output the value of each analog input pin
    for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
    int sensorReading = analogRead(analogChannel);
    client.print("analog input ");
    client.print(" is ");
    if (c == ‘\n’) {
    // you’re starting a new line
    currentLineIsBlank = true;
    else if (c != ‘\r’) {
    // you’ve gotten a character on the current line
    currentLineIsBlank = false;
    // give the web browser time to receive the data

    // close the connection:
    Serial.println(“client disonnected”);

    void printWifiStatus() {
    // print the SSID of the network you’re attached to:
    Serial.print(“SSID: “);

    // print your WiFi shield’s IP address:
    IPAddress ip = WiFi.localIP();
    Serial.print(“IP Address: “);

    // print the received signal strength:
    long rssi = WiFi.RSSI();
    Serial.print(“signal strength (RSSI):”);
    Serial.println(” dBm”);

    • Marco Schwartz

      Hi Frans, thanks for using my code ! I don’t know for sure if this is the reason, but it seems you don’t create the right HTML tags when the server answer, like :

      client.println(“< !DOCTYPE HTML>“);

      and :


      Try by really taking the original code and just changing the part related to the printing of the analog inputs values (and the WiFi SSID/pass of course)

      Let me know if you need additional help !

  • http://puiucristian.com Puiu


    Do you know if the wifi shield can act as a client and server at the same time?

    I mean that it listen for new clients in the loop, but if something triggers it (like the door being open) it opens a webpage to send some data .

  • Hoyt

    can you suggest a way to monitor your home from your office instead of monitor your home within your home?

    • http://www.marcoschwartz.com Marco Schwartz

      Hi Hoyt, thanks for your comment. This will be the subject of an upcoming article, as there are some tweaks to do on the router in your home. I will keep you updated !

      • Husni

        Great work and thanks for the info.. I’m also interested in how to do all that outside my home. I would greatly appreciate if you can keep me updated as well.. great work!!

    • James Heires

      I know your post was submitted 2 years ago, but I’m also interested in a remote monitoring solution. My idea is to extend Marco’s solution by modifying the HTML so that it sends a text message (or email), which should get the message from the local network to my (remotely monitored) email or text message via cell phone.

  • http://www.sequoia.fi/blog/2012/06/04/sequoia-and-tecnotree cosmetic surgery prices abroad

    Hello! I just would like to give an enormous thumbs up for the great info you might have here on this post.

    I will likely be coming again to your blog for extra soon.

    • http://www.marcoschwartz.com Marco Schwartz

      Thanks for your comment Oliver ! More articles related to connected open home automation systems are coming !

  • edwards

    I am having trouble with the html part i think everything works up until i try to open my ip address in the web browser. The search doesn’t find the page. The board is connected to my network, I confirmed this by pinging it. I’m not sure how to fix this. Any help is appreciated.
    Thank You

    • http://www.marcoschwartz.com Marco Schwartz

      Hi Edwards,

      I think you configured your Arduino board correctly (as the ping works), check in the preferences of your router if the port of the Arduino WiFi server (80) is not blocked for the IP of the Arduino Wifi shield.

      • edwards

        I can’t access the preferences, I don’t know the password and my boss that does is out of town. Couldn’t I just change the port and fix the problem if port 80 is blocked?

      • pxj

        I am also having the same problem.. I couldn’t find anything like you have mentioned above.

        • http://www.marcoschwartz.com Marco Schwartz

          It mainly depends on your router (and unfortunately there are nearly as many router interfaces as router models …) but if you are having problems to access your system from the outside world you can definitely check out http://www.yaler.org/ that might solve your problem.

      • Alessandro

        I have the same problem and both my arduino and browser are within the same network….anyone has a solution for this problem?

  • http://yusufokto.com yusuf

    hi marco,
    your code inspire my project :) , can wifi shield transfer file .jpg from sdcard arduino to leptop via wifi? are you have some sketch like my project?

    thanks for advice :)

  • Lucas

    Hey Marco

    First of all, thanks for the tut.
    I have a request. I wanner do something similer for my project. Its very simple. I wanner be able to connect to a webserver with the wifi shield, and send 0 & 1 bits. I dont need all the hardware and so on.
    What should i do??

    • http://www.marcoschwartz.com Marco Schwartz

      Hey Lucas,

      You can just use HTTP to send 0 & 1’s to a distant webserver. You can have a look at the official WiFi client tutorial of Arduino:


  • Arne

    I just would like to thank you for your code and video. It was really helpfull for my project :)


  • Pingback: Monitor your home remotely using the Arduino WiFi Shield - Arduino collector blog()

  • Alex

    Hello i used your code and loaded it to my arduino wifi shield but when i put in the browse my ip direction there only appears “page not available” because it cannot be connected with the server can you help me please thank you

    • http://www.marcoschwartz.com Marco Schwartz

      Hello Alex,

      Make sure first that your shield respond to a simple ping ip_of_the_shield in your terminal.

  • Arvin

    Hi, I’m interested with controlling the arduino in any part of world. I just want to ask if it is possible and can you give some insights on how to do it? thanks

  • omvaghela

    i used your program but if i want to use this without my local ip(i want to use my static ip) what should i do?
    (i dont want to use teleduino or nearbus.net or etc. sites)
    Can i do it with my arduino and ethernet shield or i have to use raspberry pi?

  • Eugene

    Hi ,Marco.I am fun of your prolific job that you enjoy to do.I count that I can ask you to assist me with next.I tried to install an Ethernet shield from Arduino on Windows you use Mac right.I browsed the internet and could not find a tutorial how to install it on Windows to use wifi capabilities with the Arduino.Thank you in advance,Eugene.

    • http://www.marcoschwartz.com Marco Schwartz

      Hello Eugene, I’ll have a new book about the Arduino Ethernet shield soon!

  • Pingback: Arduino uno & ModBus & Master SCADA - Castitas()

  • Pingback: Monitor your home remotely using the Arduino WiFi Shield | hotfish()

  • Pingback: Monitor your home remotely using the Arduino WiFi Shield | The Online Video School()

  • Pingback: Monitor your home remotely using the Arduino WiFi Shield | i Video Tutorial()

  • UuDam

    Hi Marco, how do you maintain the wifi signal at all time when you are away? I found that my wifi signal on the wifi shied drop every 15 min or so. thanks.

  • Pingback: Monitor your home remotely using the Arduino WiFi Shield | e Online Course()

  • Ricky Rick

    Great tutorial. Very well displayed and written. I have a quick question how would the code you provided change when using a eithernet shield instead of wifi shield. I am not the best when it comes to coding.

    • http://www.marcoschwartz.com/ Marco Schwartz

      Thanks! Should work nearly out of the box, as both libraries are very similar. Just check the Ethernet examples to get some inspiration.

  • Yau Kally

    Hello,may I know if I connect the whole device by external charger, can it be completely wireless to act as an individual sensing and data transmitting device?

    • http://www.marcoschwartz.com/ Marco Schwartz

      Sure, if you connect it to an external power source it will work completely independently.

  • Abhinav Swaminathan

    I have an arduino mega 2560 board and a Arduino Wifi shield. The Basic Arduino programs involving Wifi shield are working properly with my board and shield.

    I am trying to create a login page with password for providing access to the actual program page using html in the program. I use Arduino IDE 1.0.5.
    Kindly guide me and provide me a code which i can include in my WiFi shield program so as to create a login page before viewing the actual program which is being executed by the arduino board. This is for security reason as i dont want everyone having the IP address displayed by my board to access my program and my page.

    Thank You

    • http://www.marcoschwartz.com/ Marco Schwartz

      Hell Abhinav, for custom help on code we have a dedicated service: http://hardwaremonkeys.com/

  • agilan raghunathan

    hello abhinav , I am also trying to create a login page with password using my arduino and Ethernet shield , could you please guide me through. Kindly reply to me as soon as possible

  • Eu Hue Ling

    Do you have any project about Arduino Erthernet shield?