Interfacing with a digital IR reflectance sensor


i acquired pololu qtr-1rc sensors (digital sensors), , need readings them. tried using pololu libraries pins in library don't mesh arduino mega pins. decided try other way:
<from pololu>
the typical sequence reading sensor is:

set i/o line output , drive high
allow @ least 10 10 nf capacitor charge
make i/o line input (high impedance)
measure time capacitor discharge waiting i/o line go low

the time takes capacitor discharge value need read.
i need fleshing out how going work arduino mega...here's code have far:

-----------------------------------------------
int sensorpin = 37;
int time = 0;
//to hold time took cap discharge
void setup() {

serial.begin(9600);
// printing time took cap discharge me
}

void loop() {

pinmode(sensorpin, output);
digitalwrite(sensorpin, high);
delaymicroseconds(10);
pinmode(sensorpin, input);

//my question here need set digital i/o pin low though switched input effect need?
digitalwrite(sensorpin, low);

// stuck on how count time elapsed of i/o pin going high low. know need digitalread(); , possibly millis(); or micros();, though not know how put together.
(pseudo-code){
while(!digitalread(sensorpin) == "high") {
time++;
or
micros(); ?
}
}
serial.print(time);


}

thoughts? sorry if bit hard understand, first post, , clarify again if needed tomorrow morning (getting late).

i found tutorial on you...
http://www.pololu.com/docs/0j13/1

sensorpin = 37?... sounds using ic's pin instead of digital pin numbers given arduino (1..13)

quote
my question here need set digital i/o pin low though switched input effect need?

->no

for next bit, need keep time when make output low, when low read.

there lots of ways of doing this, i'm not going spoil creativity :)


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Interfacing with a digital IR reflectance sensor


arduino

Comments

Popular posts from this blog

CAN'T INSTALL MAMBELFISH 1.5 FROM DIRECTORY - Joomla! Forum - community, help and support

error: expected initializer before 'void'

CPU load monitoring using GPIO and leds - Raspberry Pi Forums