You are on page 1of 3

11/12/12

bildr Line Sensing. QRE1113 Reflectance Sensor + Arduino

search blog... Home Forum Wiki Code RSS Twitter Facebook

Search Wiki Search Forum Search Blog


Search

Login / Register About

Line Sensing. QRE1113 Reflectance Sensor + Arduino


Monday, June 27 th , 2011

The QRE1113 is a common reflectance sensor often used in robotic line followers. The sensor works by shining an IR LED down and seeing how much of that light bounces back using a phototransistor. Because dark colors will bounce back less of the light, the sensor can be used to tell the difference between white and black areas. So an array of these can be used to help a robot determine where a dark line is on the ground so it can follow it. But they can also be used to determine proximity under an inch. Both Pololu and Sparkfun sell digital and analog models of a QRE1113 breakout board. The analog version is very simple, it just outputs an analog voltage on the signal pin relative to how much light was reflected. And you might think the digital version, especially being called a line sensor by sparkfun, would just output HIGH when it sees a line, and LOW when it does not. But this is not the case. The digital version is designed for times you do not have an analog input on your microcontroller but still need an analog reading of how much light was reflected. It does this by allowing you to charge a capacitor on the board, and then timing how long it takes to discharge. The more light that is reflected, the less time it takes to discharge the capacitor. In my tests, the times ranged between 10 microseconds (10/million) to 2.5 milliseconds, so this is all done very quickly and wont put much of a delay in your code.

Hooking Them Up
Hooking the QRE1113 to your Arduino is very simple. It just needs power (5V), ground, and an analog or digital pin depending on what version you have.

bildr.org/2011/06/qre1113-arduino/

1/3

11/12/12

bildr Line Sensing. QRE1113 Reflectance Sensor + Arduino

Code
The method of reading the values from the analog and digital version is very different, so we have 2 code examples for you. Analog Version Copy Code
/ / C o d ef o rt h eQ R E 1 1 1 3A n a l o gb o a r d / / O u t p u t sv i at h es e r i a lt e r m i n a l-L o w e rn u m b e r sm e a nm o r er e f l e c t e d i n tQ R E 1 1 1 3 _ P i n=0 ;/ / c o n n e c t e dt oa n a l o g0 v o i ds e t u p ( ) { S e r i a l . b e g i n ( 9 6 0 0 ) ; } v o i dl o o p ( ) { i n tQ R E _ V a l u e=a n a l o g R e a d ( Q R E 1 1 1 3 _ P i n ) ; S e r i a l . p r i n t l n ( Q R E _ V a l u e ) ; }

Unless otherwise stated, this code is released under the MIT License Please use, change and share it. Digital Version Copy Code
/ / C o d ef o rt h eQ R E 1 1 1 3D i g i t a lb o a r d / / O u t p u t sv i at h es e r i a lt e r m i n a l-L o w e rn u m b e r sm e a nm o r er e f l e c t e d / / 3 0 0 0o rm o r em e a n sn o t h i n gw a sr e f l e c t e d . i n tQ R E 1 1 1 3 _ P i n=2 ;/ / c o n n e c t e dt od i g i t a l2 v o i ds e t u p ( ) { S e r i a l . b e g i n ( 9 6 0 0 ) ; } v o i dl o o p ( ) {

bildr.org/2011/06/qre1113-arduino/

2/3

11/12/12

bildr Line Sensing. QRE1113 Reflectance Sensor + Arduino

i n tQ R E _ V a l u e=r e a d Q D ( ) ; S e r i a l . p r i n t l n ( Q R E _ V a l u e ) ; } i n tr e a d Q D ( ) { / / R e t u r n sv a l u ef r o mt h eQ R E 1 1 1 3 / / L o w e rn u m b e r sm e a nm o r er e f l e a c i v e / / M o r et h a n3 0 0 0m e a n sn o t h i n gw a sr e f l e c t e d . p i n M o d e (Q R E 1 1 1 3 _ P i n ,O U T P U T) ; d i g i t a l W r i t e (Q R E 1 1 1 3 _ P i n ,H I G H) ; d e l a y M i c r o s e c o n d s ( 1 0 ) ; p i n M o d e (Q R E 1 1 1 3 _ P i n ,I N P U T) ; l o n gt i m e=m i c r o s ( ) ; / / t i m eh o wl o n gt h ei n p u ti sH I G H ,b u tq u i ta f t e r3 m sa sn o t h i n gh a p p e n sa f t e rt h a t w h i l e( d i g i t a l R e a d ( Q R E 1 1 1 3 _ P i n )= =H I G H& &m i c r o s ( )-t i m e<3 0 0 0 ) ; i n td i f f=m i c r o s ( )-t i m e ; r e t u r nd i f f ; }

Unless otherwise stated, this code is released under the MIT License Please use, change and share it.
Tweet 6 Like 18

No Comments

Archives
August 2012 April 2012 March 2012 February 2012 January 2012 October 2011 September 2011 August 2011 July 2011 June 2011 May 2011 April 2011 March 2011 February 2011 January 2011 December 2010 November 2010 October 2010 September 2010

Categories
funded projects Promotions Review Site Tutorials User Contributed Articles User Project

about
Content available under: Attribution-Share Alike 3.0 Unported Proudly powered by WordPress, Free WordPress Themes, and Search Marketing

bildr.org/2011/06/qre1113-arduino/

3/3

You might also like