This is a specific example of connecting a reflectance sensor from pololu:
http://www.pololu.com/catalog/product/958
to an Arduino Uno.
I’m using this for a sumobot line sensor.
1st get the library from pololu:
http://www.pololu.com/docs/0J20
Put the individual library folders in your Libraries subdirectory for Arduino.
next, connect wires as follows:
+5v -> vin
gnd -> gnd
A5 -> out
then, open op the arduino app, connect to your board and upload this code, this code is for 2 sensors, it will work fine for 1:
#include
PololuQTRSensorsRC qtr((unsigned char[]) {18,19}, 2, 2000, 255); //declares two line sensors on pins 18 and 19 this corresponds to analog pins 4 and 5
unsigned int sensors[2]; //creates thew variable
//setup is required.
void setup() {
// initialize serial communication:
Serial.begin(9600);
}
//THE MAIN PROGRAM LOOP
void loop(){
qtr.read(sensors);
delay(20);
//sends the info to serial so you can view it in the serial monitor.
Serial.print(sensors[0]);
Serial.print(" ");
Serial.println(sensors[1]);
}
upload the code to the board.
In the Arduino app goto tools->Serial Monitor. Here you should be able to see the results of the reflectance sensor.
Now in order to code it for a White line you have to determine what value you want it to react to, so give it some tests.
oince you set your linethreshold variable you can start doing comparisons like this:
if (sensors[0] > linethreshold){ stuff to do }