The output from the sensor comes from pin 1, which should be wired to pin 2 on the Arduino board.
The supply voltage, which comes into the sensor on pin 2, comes through a 100-ohm resistor. There is a line from the +5v pin on the Arduino board to the resistor, and the resistor is connected to pin 2 on the IR sensor.
The IR sensor is grounded through pin 3. A 0.1uF capacitor is connected between pins 2 and 3 on the sensor.
The LED is connected as such:
positive pin(long one) connected to +5v
short pin connected to a 150 ohm resistor in series with the arduino gnd pin.
int ldrPin = 2; //digital 2
int readLDR = 0;
void setup() {
// put your setup code here, to run once:
pinMode(ldrPin, INPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
readLDR = digitalRead(ldrPin);
Serial.println(readLDR);
}
Now the issue is, the console gives me a 1 all the time, even when i disconnect the LED from +5v.
What am i doing wrong here?
You have a sensor which expects a 36KHz modulated signal. Your LED is producing a completely unmodulated signal. You may be better off replacing the sensor with a simple IR photodiode.
As has been said, the sensor needs to see IR modulated at 36KHz.
You could connect your LED to +5V and thru a 220ohm resistor to an Arduino pin.
Then set that pin as an OUTPUT and use the tone() function to modulate that LED at 36000Hz
e.g.
#define LED_PIN 5
tone( LED_PIN, 36000, 100 ); // turn LED on at 36000Hz for 100mS
delay(2); // delay a bit for sensor to read the IR
readLDR = digitalRead(ldrPin);
Serial.println(readLDR);
Yours,
TonyWilk
P.S. Later you will probably need to drive the LED at higher current using a transistor so it will work at longer distances.
TonyWilk:
Hi,
As has been said, the sensor needs to see IR modulated at 36KHz.
You could connect your LED to +5V and thru a 220ohm resistor to an Arduino pin.
Then set that pin as an OUTPUT and use the tone() function to modulate that LED at 36000Hz
e.g.
#define LED_PIN 5
tone( LED_PIN, 36000, 100 ); // turn LED on at 36000Hz for 100mS
delay(2); // delay a bit for sensor to read the IR
readLDR = digitalRead(ldrPin);
Serial.println(readLDR);
Yours,
TonyWilk
P.S. Later you will probably need to drive the LED at higher current using a transistor so it will work at longer distances.
Yes, works great, just the solution i needed!!
Having a small issue though. that is, i'm now using analogRead to determine the input difference between IR and no IR however when there is no IR, the analog input reads a value of about 80 constant, but when there is IR it reads various inputs changing from about 90 to 120 but nothing constant and very small changes so it's hard to be sure there is input.
mhmart:
i'm now using analogRead to determine the input difference between IR and no IR
That's not right, the output of the detector should be high and pulse low when it detects 36KHz IR.
You should be using digitalRead() as you did originally.
If you do connect the sensor to the right pin and then read it with analogRead(), you should get big values like 1000 when there is no IR.
If you still have problems, you'll have to post your circuit and a picture of your setup.