compiles code conditionally. In our case, it will compile the Celsius-to-
Fahrenheit formula in line 17 only if the constant
CELSIUS
has not been set.
Upload the sketch, and it will output the current temperature to the serial
port every five seconds. Its output looks as follows:
27.15 C
26.66 C
27.15 C
What we need now is a program running on your PC that reads this output
and Tweets a message as soon as the temperature is greater than 32 degrees
Celsius (90 degrees Fahrenheit). We could use any programming language
that is capable of reading from a serial port and that supports Twitter, but
because Processing
2
has excellent support for Twitter and the serial port, we’ll
use it for this project.
The Arduino and the Internet of Things (IoT)
Today for most people the Internet is a network of computers that can be used for
looking up entertaining, useful, or interesting information. In recent years the nature
of the Internet has changed tremendously. More and more autonomous and automated
devices have joined the Internet. For many people it’s normal already to use a
smartphone to surf the web, and in a not-too-distant future, devices such as toasters
and refrigerators will be part of the Internet, too. This is the Internet of Things, where
everyday objects are able to send and receive data over a network connection.
With the advent of cheap open-source hardware and sensors, web services for pub-
lishing sensor data have become popular over the past few years. Such services allow
you to publish, read, and analyze sensor data. People from all over the world publish
data from their weather stations, environmental sensors, and so on, and they make
it available for free on the Internet.
These web services offer even more functions today and make it easy to turn an
Arduino into a full-blown member of the Internet of Things—that is, you can integrate
your Arduino with Google Mail, Facebook, eBay, and so on.
Popular services are Xively
a
and Temboo.
b
In principle, they all work the same: you
register an account, and you get back an API key. Then you can use this key to
authenticate against the service and upload sensor data or use other functions of
their API. Usually, these services also offer special Arduino libraries that help you to
build your applications.
a.
http://xively.com
b.
https://www.temboo.com/
2.
https://processing.org/
Chapter 10. Networking with Arduino • 166
report erratum • discuss
www.it-ebooks.info