Go Down

Topic: IR detector/emitter (Read 1 time) previous topic - next topic



I need help with the basic IR detector/emitter circuit.
I have been trying to test my infrared emitter and detector if it works, I also tried to use a different pair but it's still not working.

Basically, The connection is suppose to function like this - IR detector to control the LED output based on the analog sensor reading input.
The desired result - As hand moves closer to the IR detector, the LED gets brighter.

Please see attached file, it's my connection using Fritzing.
- IR detector is substituted with LDR icon.
- IR emitter is substituted with LED icon.

If you cant see my connection, Its the same as here: http://www.reconnsworld.com/ir_ultrasonic_basicirdetectemit.html

Here is the code I used:

ANALOG I/O: LED Fading with InfraRed Proximity Sensor Input
By Keywon Chung, 2007-07-23
Based on:

int value = 0;                            // variable to keep the actual value coming from the sensor
int irPin = 2;                            // input pin: IR sensor connected to analog pin 2
int ledPin = 13;                           // output pin: light connected to digital pin 9

void setup()
  pinMode(ledPin, OUTPUT);                // declare ledPin as an OUTPUT pin

void loop()
  value = analogRead(irPin);              // read the value from the sensor (0-1024, actual 150-700)
  value = (value-150)/2;                  // calibrate 150-700 down to 0-255
  if (value < 0) {
    value = 0;
  if (value > 255) {
    value = 255;

  //digitalWrite(ledPin, HIGH);           
  analogWrite(ledPin, value);             // sets the value (range from 0 to 255)
  //delay(1000);                          // waits for x milli seconds to see the dimming effect

Got the code from: http://keywon.com/wiki/index.php?title=Project_002

I watched videos on youtube, regarding the same thing, and one of em used the same codes and it worked.

Please help! I've been at it for a week already..


If you have a logic probe, what do you see at the o/p of your detector circuit?
No technical PMs.
The last thing you did is where you should start looking.


Code: [Select]

int irPin = 2;    // input pin: IR sensor connected to analog pin 2

Analog pin 2 is pin 16
You can't analogRead from digital pin 2, which is the one you're setting.
You also haven't declared the analog pin as INPUT
Code: [Select]

analogWrite(ledPin, value);   

You can't analogWrite to digital pin 13, only to pins 3, 5, 6, 9, 10 and 11.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131