Fig. D: The antique voltmeter, attached to the Aruino microcontroller.
slowly than the pulse rate. For example, you can
pulse width modulate a dimming effect for an LED
because the human eye can’t detect on-off transitions faster than about 30Hz.
Analog voltmeters are slow to react to changing
voltages, so PWM will also work well for our antique
display. To drive the meter, I would connect its positive terminal to an output pin of the microcontroller
and its negative pin to ground. Then I could control
its reading by pulse width modulating the micro’s
1: 1 Scaling
The meter’s display reads from 0 to 150, and the
AQI runs from 0 up to 500. But the EPA regards air
that measures 150 as “unhealthy for all individuals,”
so I decided to set my meter up to show the raw
AQI, without any scaling. If I see the needle pegged
at the high end, I’ll know I just shouldn’t breathe.
Parsing the AirNow Page
The next step was to get the data from AirNow’s
website into some form that the microcontroller
could read. The microcontroller can easily read in
short strings and convert the ASCII into binary, but
it would be tough to parse through all of the text on
a web page and find the right string. So I decided to
write a program on my own server that would parse
the AirNow page, extract just the current AQI reading for New York, and save it someplace where the
microcontroller could read it. The microcontroller
could then request a TCP connection via the serial-to-Ethernet converter and read in the data.
AirNow’s page is formatted well for extracting the
data (Figure C). The AQI number is shown clearly in
text, and if you remove all of the HTML tags from
the page source, it always appears on a line by
itself following the line “AQI observed at hh:mm AM/PM:”.
I wrote a short PHP script to read the page, strip
out the HTML, and find those two lines. When it did,
it returned the AQI value by itself like so:
< AQI: 43>
On my server, a cron job runs the PHP script periodically and writes the value returned into a file that’s
accessible via Hypertext Transport Protocol (HTTP).
The next step was to connect the microcontroller
to the serial-to-Ethernet converter and then to the
net. I used the Xport device from Lantronix, which