Let's Make Robots!

grrr reflectance sensors

 

 

Ok i have these on my chess robot but dont remember what i had to do to get them to work. It is the pololu digital line sensor http://www.pololu.com/catalog/product/959. Im using a arduino and 4 1.2v batteries. Here is my code. Please i forgot how to use these. 

 

 

int sensor= 4;

int x;

void setup(){ 

  pinMode (sensor, INPUT);

   digitalWrite(sensor, HIGH);

   delay(15);

Serial.begin(9600);

}

 

void loop(){

  x= digitalRead(sensor);

  Serial.println(x);

}

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
  1. #include <PololuQTRSensors.h>  
  2.   
  3. // create an object for your type of sensor (RC or Analog)  
  4. // in this example we have three sensors on analog inputs 0 - 2, a.k.a. digital pins 14 - 16  
  5. PololuQTRSensorsRC qtr((char[]) {14, 15, 16}, 3);   --------------------ERROR HERE ********
  6. // PololuQTRSensorsA qtr((char[]) {0, 1, 2}, 3);  
  7.   
  8. void setup()  
  9. {  
  10.   // optional: wait for some input from the user, such as  a button press  
  11.   
  12.   // then start calibration phase and move the sensors over both  
  13.   // reflectance extremes they will encounter in your application:  
  14.   int i;  
  15.   for (i = 0; i < 250; i++)  // make the calibration take about 5 seconds  
  16.   {  
  17.     qtr.calibrate();  
  18.     delay(20);  
  19.   }  
  20.   
  21.   // optional: signal that the calibration phase is now over and wait for further  
  22.   // input from the user, such as a button press  
  23. }  
 
 
the error is in the conversion from char to unsigned char it says 

Try this out: 

int sensor= 4;

int x;

void setup(){ 

  Serial.begin(9600);

}

 

void loop(){

  pinMode (sensor, OUTPUT);

  digitalWrite(sensor, HIGH);

  delayMicroseconds(15);

  pinMode (sensor, INPUT);

  digitalWrite(sensor, LOW);

  delayMicroseconds(800);                          //Adjust this value to tweak the threshold

  x= digitalRead(sensor);

  Serial.println(x);

}