The internet meter is an analog panel meter that can display different values from the internet
such as
stock prices, the number of unread messages in your in box, the temperature of a remote location
or, in the case of the one here, the number of unread items in your Google Reader account.
As you can see,
I'm way behind.
Anyway, this is a great project for someone that has the basics of Arduino down
but is interested in learning what they can do with the Ethernet Shield.
Let's take a look at what we need.
At the core is your basic Arduino,
which will connect to the internet
with an Ethernet Shield.
Of course we need a meter
this one is a zero one miliamp DC ammeter.
And hopefully
you have some resistors and hookup wire laying around.
You also need access to a web server with PHP
you can use your local computer or a remote server.
The server is going to get the data we want from the internet
and tell your meter what level to display.
If you're not familiar with PHP, don't worry about too much, there's a huge community of developers
that'll help you get started.
Assembling the hardware is easy.
Attach the Ethernet Shield.
Connected negative terminal of the meter to the ground
and the positive lead to a resistor.
The value of the resister you use depends on what meter you're using.
For a zero to one miliamp meter, like the one I have here,
use a 4.7K resistor.
The resistor connects to a PWM pin on the Arduino.
The PWM pins are marked with an asterisk on the Ethernet Shield.
PWM stands for "Pulse Width Modulation."
It's a way of pulsing these pins between high and low at set intervals.
Changing the interval how we'll move the needle on our meter.
Let's try that now to test our hookups.
To change the pulse width we used the Arduino function analogWrite() with the first
parameter being the pin and the second one being the value between 0 and 255.
I've hooked up my meter to pin 6.
And let's give it value of 128.
That should put the needle right in the middle.
So now that we have our meter working, we need to take a look at how to use the Ethernet Shield.
The best way to learn is by looking at the example that's included with the Arduino
development environment.
In Arduino, go to File... Examples... Ethernet... and choose WebClient.
This example makes a search request to Google's trusty servers and returns the result in
the serial monitor.
You may need to adjust your own IP and even Google's server IP.
You can do a ping to look those up.
Plug in your ethernet cable and upload the example sketch to your board.
In the serial monitor, you should see a plaintext response from Google appear.
If not, try troubleshooting this first before moving on.
The formus at Arduino.cc are very helpful for trouble shooting these
types of problems.
Now let's make a very simple PHP file to put on our server.
It's just one line of code that says to respond to the ANSI character corresponding to the
value of 191.
Sending the response as an ANSI character will help us to keep the code simple on the Arduino.
If we were to send the numbers, "one nine one,"
our Arduino would have to interpret that string
into an integer before it could evaluate it.
Drop that file with a .PHP extension in your web server folder and let's open up the
URL in a browser to check.
If you see an upside down question mark, you know you've got it right.
If not, you'll have to troubleshoot your PHP server set up.
Now let's modify the WebClient example to get the character from our server.
Change the IP of the server from Google's to your own.
You can use ping to determine your server's IP.
Now let's change the request line to the correct path on our web server.
We can leave off the "HTTP/1.0"
On the end so that we don't get any of the headers.
Now let's look at how to handle the response.
Instead of printing the character c to the serial monitor,
Let's use its value to analogWrite() to our meter pin.
I'm also going to flush the buffer so we're ignoring any other data our server might send.
Now let's upload this to the board.
If we were able to make it successful connection to get our byte,
our panel meter should be at the 75% mark since the value 191
is about 75% of 255.
If you don't get 75% on your meter, I would troubleshoot by putting the server's
output back to the serial monitor to see what's going on.
Instead of stopping here,
add a delay of maybe a minute or two and move the code to connect to the server down into
this loop.
Now our Arduino will poll the server on this interval.
Now all you have to do is have your PHP script get the data you need, evaluate it, and spit
an ANSI byte from 0 to 255
for wherever you want the needle to point.
Here's some basic code for connecting to a GMail account
and getting the number of unread messages. So I've uploaded that code to my server and it seems
like my meter's showing that I have zero unread messages in my inbox.
Hm.
Anyway, that's the Internet Meter. You can extend this in so many different ways with a
little bit of PHP work.
You can have a meter show you how many different people have checked into your favorite local
bar on foursquare.
If you do think of a great way to extend it, feel free to comment below.