Pages: [1]   Go Down
Author Topic: IR detector/emitter  (Read 444 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 4
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

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:
http://www.arduino.cc/en/Tutorial/Fading
http://www.arduino.cc/en/Tutorial/Button
*/

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..


* IR_detector_emitter.fzz (4.43 KB - downloaded 6 times.)
Logged

Offline Offline
Edison Member
*
Karma: 56
Posts: 2189
The last thing you did is where you should start looking.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you have a logic probe, what do you see at the o/p of your detector circuit?
Logged

London
Offline Offline
Edison Member
*
Karma: 23
Posts: 1077
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


Code:
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:
analogWrite(ledPin, value);   
You can't analogWrite to digital pin 13, only to pins 3, 5, 6, 9, 10 and 11.
Logged

Pages: [1]   Go Up
Jump to: