Arduino can gather and display all sorts of data from its sensors (or what ever you connect to it), but the real power from the data comes when you can monitor it over network.
There are 2 ways you can connect Arduino to your home network: over Wi-Fi, or through a network (UTP) cable. The simplest way of achieving any of the two is by using Arduino “shields”.
Wikipedia: Arduino and Arduino-compatible boards make use of shields—printed circuit expansion boards that plug into the normally supplied Arduino pin-headers. Shields can provide motor controls, GPS, ethernet, LCD, or breadboarding (prototyping). A number of shields can also be made DIY.
So, using simple words, a shield is a sort of expansion for the Arduino which is plugged into the Arduino. It is usually the same size as the Arduino, and stacks on top of it.
More information about mentioned shields can be found on the official Arduino webpage: WiFi Shield, Ethernet shield
In this article I will cover the basics on connecting Arduino to your home network and creating a web page on which it displays data from the light sensor. I will be using an Ethernet shield due to its lower price and my paranoid mind not believing a non-wire approach.
So for this project you will need:
– Ethernet Shield (I bought one like this over eBay, price about 7-8$)
– Light sensor (same as used in the first article)
– 3 x jumper wire
– network cable (any type)
Stacking Ethernet shield on Arduino and connecting the sensor
1. Stack the Ethernet shield on Arduino so that the end pins connect (you can’t miss it)
2. Connect the “female” end of jumper wires to the sensor, in my case: green wire to GND, purple wire to VCC, yellow wire to SIG
3. Connect the “male” end of jumper wire to the Ethernet Shield stacked on top of Arduino accordingly: green wire to GND, purple wire to 5V, yellow wire to A0 analog input port.
4. Connect USB and network (ethernet) cable – USB goes into Arduino, and network cable into the Shield stacked on top of Arduino.
If everything is ok, Shield LEDs and ethernet port will light up.
Writing the code
For the purpose of assigning the IP address for Arduino (as all devices connecting to a network have an IP address), find out what is your networks IP address range. You can do so by going into Command Prompt in Windows and in the command line write “ipconfig”. Its output will tell you what is the range of your network.
This is a standard output of the command “ipconfig” in Windows. Here you see that my IPv4 Address is 192.168.0.11, so for Arduino I can pick any address between 192.168.0.2 (192.168.0.1 – is my default gateway so this address is reserved) and 192.168.0.254 that isn’t 192.168.0.11 (which is the address of my computer). So, for example I will pick the address 192.168.0.16 (completely random).
Be advised: If you have more devices on your network (like smartphones, laptops, etc) you might end up picking an address that is being used, so just use an address far in the range like 192.168.0.154 or something like that.
Now that we know what IP address we will appoint to our Arduino, let’s write the code:
If you did everything according to this instructions, when you open your browser and enter the IP address of Arduino (in my case 192.168.0.16), you should get this webpage as a result which will refresh every 5 seconds with new data.
While it being not much of an advantage if you open it from your computer, this gives you the possibility to view this data from any device connected to your local network. And with the idea that Arduino doesn’t have to be powered through USB port on your computer, but rather from an separate power source (which I will describe in the next article), you can place it where you want to measure something and access its data from any computer or smartphone in your network.