Go Down

Topic: HELP with Infrared emitter + sensor problems (Read 9 times) previous topic - next topic

njs707

OK so I copy and pasted the code and tried it.  It did not look like the numbers where affected by my hand motions.  Here is my setup attached between a breadboard and arduino....

                                         GND ____ - Yellow LED + ____ pin 13

                                         GND ____ - IR LED + ____ 100 ohm resistor ____ pin 12

                                         GND ____ - IR Receiver + 10k ohm resistor ____ A0


Should be that simple right?

njs707

Here is my question..... this code...



void setup()

{
 
  pinMode(13,OUTPUT);
  pinMode(12,OUTPUT);
  Serial.begin(9600);
 
}

void loop()

{
  int receiverVal = analogRead(A0);
  digitalWrite(12,HIGH);
  delay(.5);
  digitalWrite(12,LOW);
  delay(.5);
  Serial.println(receiverVal);
 
  if ( receiverVal > 50)
  {
  digitalWrite(13,HIGH);
  }
  else
  {
  digitalWrite(13,LOW);
  }
 
}

.... works perfectly when my LEDs are plugged into the arduino.. but it does not work at all when hooked up to a 9v battery through a 5 voltage regulator on a breadboard... the blink application works but not this code for IR sensing.  The only things different between the arduino and my standalone are power source, ( 5v from 9v battery  vs.   usb from computer from wall ); and timing ( 16mhz resonator    vs.   16 mhz crystal ).

What the heck could be wrong.  The standalone is virtually the exact same, I have quadroooopal checked where everything is hooked up.  Why would it work on the arduino and not on my standalone?  PS. I am trying them in the exact same lighting conditions in the exact same spot, so nothing is different.

njs707

PPS.... Concerning the previous post... The standalone, when brought into complete darkness like my bathroom, does turn the LED on, but it sort of has the opposite effect, when I bring my hand closer the LED turns off???? Whyyyyyyy?  This also proves that the receiver on the standalone IS receiving input, plus the LED works and the IR LED works based on my cameraphone's ability to see infrared.  :( :( :( PLEASE HELP

njs707

K last post on my part until someone replies I promise!  So new and strange development... On my standalone, when I touch the positive side of the receiver with my hand, or touch a bare wire attached to the positive side of the  receiver, the LED turns on when I wave my hand above the sensor????? So, I know it can work but why only when I'm touch the positive terminal of the  receiver?? any thoughts??

johnwasser


OK so I copy and pasted the code and tried it.  It did not look like the numbers where affected by my hand motions.  Here is my setup attached between a breadboard and arduino....

                                        GND ____ - Yellow LED + ____ pin 13
                                        GND ____ - IR LED + ____ 100 ohm resistor ____ pin 12
                                        GND ____ - IR Receiver + 10k ohm resistor ____ A0

Should be that simple right?


I believe you need to provide a source of power for the IR Phototransistor to work.  Try this schematic:

http://sites.google.com/site/therobotronics/arduino/connect-a-phototransistor-to-arduino
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

njs707

Ok, tried that but it seems weird to connect an analog pin to ground and the collector 2 5v.  So I'm clear... this is how I would set this up using the atmega328 on a breadboard...


VCC ____ - Receiver + _____ A0 pin  __________________
                                                                               |
                            + _____ 10k ohm ____ ground ______|

    ... or what??


This is what I am using...   http://www.instructables.com/image/F4M09OIF6S98GAG/IR-Detector-Circuit.jpg

AWOL

Code: [Select]
delay(.5);
What makes you think you can delay 500 microseconds like that?
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

johnwasser


VCC ____ - Receiver + _____ A0 pin  __________________
                                                                               |
                            + _____ 10k ohm ____ ground ______|

Don't connect A0 to Ground.  The diagram is a bit confusing because it uses the same type of line to show the edge of the Arduino and the connections TO the Arduino.  The resistor and Arduino are connected to a common ground.  The A0 input is only connected to the junction between the phototransistor emitter and the load resistor.



http://www.instructables.com/image/F4M09OIF6S98GAG/IR-Detector-Circuit.jpg

That example uses a digital input with the internal pull-up resistor enabled.  Current through the phototransistor drags the signal down enough to register as a 0.  The analog inputs don't have the option of internal pull-up resistors (as far as I know) so you need to provide the +5v source.  Current through the phototransistor and resistor raises the voltage across the resistor and this voltage is measured by A0.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

njs707

What should I be pulsing the IR LED at?

digitalWrite(13,HIGH);
delay( x );
digitalWrite(13,LOW);
delay( x );

what is a good value or range of values for x?   

johnwasser

I did not put delays into the code I provided and I do not recommend you change the code randomly without understanding exactly why you are doing it.  Perhaps you can explain exactly WHY you want to 'pulse' the IR LED?

If you are at a strange house and you want to see what light switch does what you flip the switch on and off, perhaps a few times, and look for any light changes.  If you look out the window, close your eyes, start flipping the switch madly up and down, then put it back in the initial position and look again you will not sense any light changes, no matter how quickly and how long you flip the switch up and down.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

njs707

oh, I guess I misunderstood something I read about having the IR emitter pulsed so the receiver can take it in. 



" We write an Arduino sketch to make this LED flash 38,000 times per second so it can be detected by the PNA4602M. "  I've read similar statements like this from different sources.  It is flashed at 38 khz because that is what the receiver looks for, so it takes light with different frequencies out of the equation....  is this wrong or idk? haha. sounds right. maybe.  Anyway that is why I am pulsing it.

This statement was taken from a powerpoint found online here....   web.cecs.pdx.edu/eas199/C/notes/1/1_IR_object_detection.ppt 


please help. let me know if this is wrong and why, or visa versa

johnwasser

If you had a three-terminal IR Remote Control receiver, they have a bandpass filter to select lights pulsed at 38-40KHz.  They also have an analog comparator to get an on/off output.  You hook them up to +5v and Ground and the output signal turns ON if you hit the sensor with 38-40KHz modulated IR.  If that's the kind of sensor you had you wouldn't be hooking it up to an analog input.

You have a bare IR phototransistor.  It does not have a bandpass filter or comparator.
Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

njs707

ok so I tried your code john and experimented with different CompareThreshold values and determined it works the best at 250. Here is the problem, it only works in the dark.  When a light is on there is too much IR being emitted from the light and causes the LED to always be on.  Not sure how to get around that...

const int IRLED = 12;
const int LED = 13;
const int IRInput = A0;
const int SampleSize = 10;
const int CompareThreshold = 17;

void setup()
{
  pinMode(13,OUTPUT);
  pinMode(12,OUTPUT);
  Serial.begin(9600);
}

void loop()
{
  int onVal = 0;
  int offVal = 0;

  // Take 10 samples with the light ON and OFF
  for (int i=0; i<SampleSize; i++)
  {
    digitalWrite(IRLED, HIGH);
    onVal += analogRead(IRInput);
    digitalWrite(IRLED, LOW);
    offVal += analogRead(IRInput);
  }
 
  Serial.print("average onVal=");
  Serial.print(onVal/SampleSize);
  Serial.print(", average offVal=");
  Serial.println(offVal/SampleSize);


  if ((offVal - onVal) > CompareThreshold)  // Value to be determined experimantally
  {
    digitalWrite(LED,HIGH);
  }
  else
  {
    digitalWrite(LED,LOW);
  }

}

njs707

Please do not forget to look at my previous post as well as this one....

but one more dumb question... If the IR receiver reads a 0, does that mean it is reading no infrared light or it is reading the max it can handle?  Because When I ran this code...  It read zeros when my light was on, and really high numbers when the light was off(almost in complete darkness), so that must mean a higher number means a lower amount of infrared being read right??


const int IRInput = A0;
void setup()
{
  Serial.begin(9600);
}
void loop()
{
  int onVal = analogRead(A0);
  Serial.println(onVal);
}
 

johnwasser

The phototransistor should conduct more electricity when light hits it.  If it is hooked up as in the diagram I referenced:

+5v ----- (c)Phototransistor(e) ----- [A0] ----- Resistor ----- Ground

the voltage across the resistor should go UP as the light increases.  I don't understand why you are getting the opposite effect unless you have wired it differently.  you are getting the opposite effect then I think the wiring is done differently.

Try different values fro the resistor to see what effect that has on the output.

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Go Up