Qtr Arduino Library

Only available on StudyMode
  • Topic: Personal identification number, Control theory, PID controller
  • Pages : 14 (4111 words )
  • Download(s) : 287
  • Published : June 16, 2012
Open Document
Text Preview
Arduino Library for the Pololu QTR Reflectance Sensors

© 2001–2011 Pololu Corporation

Arduino Library for the Pololu QTR Reflectance Sensors

1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2 2. Library Installation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 3. QTRSensors Methods & Usage Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

http://www.pololu.com/docs/0J19

Page 1 of 12

Arduino Library for the Pololu QTR Reflectance Sensors

© 2001–2011 Pololu Corporation

1. Introduction

QTR-1RC reflectance sensor.

QTR-8A reflectance sensor array.

The Pololu QTR reflectance sensors carry infrared LED and phototransistor pairs that can provide analog measurements of IR reflectance, which makes them great for close-proximity edge detection and line-following applications. The modules come as compact, single-sensor units (QTR-1A [http://www.pololu.com/catalog/product/958] and QTR-1RC [http://www.pololu.com/catalog/product/959]) or as 8-sensor arrays (QTR-8A [http://www.pololu.com/catalog/product/960] and QTR-8RC [http://www.pololu.com/catalog/product/961]) that can be optionally split into a 2-sensor array and a 6-sensor array. The modules are available in two different output formats: the QTR-xA outputs an analog voltage between 0 and Vcc that can be measured by an analog-to-digital converter (ADC), and the QTR-xRC outputs a pulse that can be measured by a digital I/O line (the duration of which provides an analog measurement of reflectance).

QTR-1A reflectance sensor schematic diagram.

QTR-1RC reflectance sensor schematic diagram.

Please see the product pages [http://www.pololu.com/catalog/category/7] for more information on how these sensors work. This document will explain how to install Arduino libraries for the Pololu QTR reflectance sensors, and it will provide sample sketches as well as links to library documentation. The libraries will give you everything you need to interface with

1. Introduction

Page 2 of 12

Arduino Library for the Pololu QTR Reflectance Sensors

© 2001–2011 Pololu Corporation

a QTR-8x reflectance sensor array or multiple QTR-1x reflectance sensors, including advanced features like automatic calibration and, in the case of line detection, calculation of the line’s position.

1. Introduction

Page 3 of 12

Arduino Library for the Pololu QTR Reflectance Sensors

© 2001–2011 Pololu Corporation

2. Library Installation
Download the archive from GitHub, decompress it, and drag the “QTRSensors” folder to your arduino-1.0/ libraries directory.

You should now be able to use these libraries in your sketches by selecting Sketch > Import Library > QTRSensors from your Arduino IDE (or simply type #include at the top of your sketch). Note that you might need to restart your Arduino IDE before it sees the new libraries. Once this is done, you can create a QTRSensorsAnalog object for your QTR-xA sensors and a QTRSensorsRC object for your QTR-xRC sensors: // create an object for three QTR-xA sensors on analog inputs 0, 2, and 6 QTRSensorsAnalog qtra((unsigned char[]) {0, 2, 6}, 3); // create an object for four QTR-xRC sensors on digital pins 0 and 9, and on analog // inputs 1 and 3 (which are being used as digital inputs 15 and 17 in this case) QTRSensorsRC qtrrc((unsigned char[]) {0, 9, 15, 17}, 4);

This library takes care of the differences between the QTR-xA and QTR-xRC sensors internally, providing you with a common interface to both sensors. The only external difference is in the constructors, as you can see in the code sample above. The first argument to the QTRSensorsAnalog constructor is an array of analog input pins (0 – 7) while the first argument to the QTRSensorsRC constructor is an array of digital pins (0 – 19). Note that analog inputs 0 – 5 can be...
tracking img