Using Code Libraries

With this project, we start doing something new: using code libraries.

A library is a chunk of code that is specifically written to do a common task. Sensor code libraries give makers the means to access the functions of a sensor (as well as other electronic components) fairly confidently, because the code has been tested by the author and updated by people who use it.

Many sensors, including the DHT-22, have their own sensor code libraries, found on repositories like GitHub. The DHT-22’s library was written and placed on GitHub by Ben Adams for hobbyists to use in building microprocessor-based gadgets that include this sensor. This saves everyone the trouble of duplicating his effort. (We’ve also forked a DHT-22 code library from Ben Adams’s repository, containing updates that will enable the sensor to work with the autumn 2011 Arduino 1.0 code update.)

Before you tear your hair out writing a sensor code library from scratch, search around to see if one already exists. You’ll be glad you did. If you do end up writing an original code library, consider sharing it with fellow makers on a site like GitHub.

Get Environmental Monitoring with Arduino now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.