Monitor Home Remotely Using The Arduino Wifi Shield: Hardware Requirements
Monitor Home Remotely Using The Arduino Wifi Shield: Hardware Requirements
Hardware requirements
Arduino UNO board
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.
Software Requirements
Apart from the latest version of the Arduino IDE, is needed
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. This
is because this is an interrupt pin, we will why we need that later. This is the schematic of this
configuration:
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. 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:
See this IP 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.
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:
// Push button pin
int pushButton = 2;
// Setup
void setup() {
Serial.begin(9600);
}
// Main loop
void loop() {
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.
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:
if (door_status == false){
client.print("Everything is ok");
}
else {
client.print("Alert ! The door has been opened");
}
Finally, we finish the HTML page with:
client.println("
");
client.println("");
And then we stop the connection:
client.stop();
Serial.println("client disonnected");
These are the important parts of the code. 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:
Now, press the button, and return to the page. The message should have changed to this:
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.