Hi all,
I am using, trying to use the simple IR distance tutorial. [/Arduino Playground - PanasonicIrSensor]
It's not working and here's what I am not getting. I had a basic stamp board nearby, and tried the same method of bit banging, a 38kHz pulsetrain on it. That one works like a champ, I can wave my hand over the IR LED and the output changes very easily. I put it on a little breadboard and then I hook it up to the Arduino Uno I have and the output never changes, meaning the sensor never sees the IR signal. I was wondering if maybe there was something with passing the variable back from the subroutine, so I tried the attached rewrite, but nothing changes.
I have tried changing from pins 4 and 5 per the demo to other pins with no effect. I also changed the digitalread to a analogread, but the analog value hovers around 1023. I am using the recommended parallax circuit as well, with 220 Ohm resistor for the detector and a 1K for the IR LED. I have also switched around the IR LED, in case the long leg isn't the anode. I have taken apart the circuit a couple times too. I also have used it in the dark, thinking maybe I am having IR soak from something else. Of course the Parallax circuit hasn't had those issues and it is right next to this one. Anyone have any ideas? This should be simple but I think I have spent about 3-4 hours and it's not getting better.
Thanks.
[///define pins. I used pins 4 and 5
#define irLedPin 3 // IR Led on this pin
#define irSensorPin 5 // IR sensor on this pin
//int irRead(int readPin, int triggerPin); //function prototype
void setup()
{
pinMode(irSensorPin, INPUT);
pinMode(irLedPin, OUTPUT);
delay (3000); // time to start serial window.
Serial.begin(9600);
// prints title with ending line break
Serial.println("Program Starting");
// wait for the long string to be sent
delay(100);
}
void loop()
{
delay (100);
// Serial.println(irRead(irSensorPin, irLedPin)); //display the results
// delay(10); //wait for the string to be sent
int halfPeriod = 3; //one period at 38.5khZ is aproximately 26 microseconds
int cycles = 70; //26 microseconds * 38 is more or less 1 millisecond
int i;
for (i=0; i <=cycles; i++)
{
digitalWrite(irLedPin, HIGH);
delayMicroseconds(halfPeriod);
digitalWrite(irLedPin, LOW);
delayMicroseconds(halfPeriod - 1); // - 1 to make up for digitaWrite overhead
}
int state = digitalRead(irSensorPin);
Serial.println(state); //display the results
}
/******************************************************************************
* This function can be used with a panasonic pna4602m ir sensor
* it returns a zero if something is detected by the sensor, and a 1 otherwise
* The function bit bangs a 38.5khZ waveform to an IR led connected to the
* triggerPin for 1 millisecond, and then reads the IR sensor pin to see if
* the reflected IR has been detected
******************************************************************************/
]