njs707

I have a 940nm infrared LED emitter, an infrared receiver (phototrans clear, whatever that means), and all of the necessary components for a standalone Arduino... 16 mhz resonator, a few resistors, 9v battery, +5 v regulator, and a 3v LED. What I want to do is use the infrared emitter and receiver together to create an interactive LED. Simply, when I wave an object over the infrared receiver I want the LED to light up, and to stay off when nothing is within a certain distance of the receiver ( preferably 20cm or so). So I believe I have it all hooked up correctly. The infrared LED is hooked up to digital pin 13 to emit a constant infrared light. Right next to it on the breadboard I have the infrared receiver which is hooked up to ground and analog pin 2, to receive the infrared signal bouncing off of something. Finally, I have the regular LED attached to digital pin 12, to emit light when the receiver receives infrared. There is a barrier between the infrared LED and receiver. Here is my code.... I think I just need a better way of stating what the input actually is and communicating that with code.

Well, you haven't declared "val", so we'll assume it is an "int".If you read an analogue pin, unless it is nailed to ground, it will almost certainly read > 0, so that might need some attention too.

Quote

The infrared LED is hooked up to digital pin 13

...via a suitable resistor, I assume?

Quote

I have the regular LED attached to digital pin 12

...ditto.

I think you may be a little optimistic expecting a 20cm range.

"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.I speak for myself, not Arduino.

"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.I speak for myself, not Arduino.

Your best bet would be to flash the LED at 38kHz, and use a 38kHz IR remote receiver to detect it - as johnwasser has pointed, it will give you better immunity to noise.

"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.I speak for myself, not Arduino.

njs707

OK thanks, new question though. I got it to work fairly well by pulsing the infrared LED, but only while everything is attached to the arduino. When I put everything on a breadboard for a standalone, it does not work the same, even though I have a 9v battery hooked up and a +5 voltage regulator??? Why would it not work the same? The only difference is the power? My only thought is that the arduino uses a 16 mhz crystal with 2 capacitors while the stand alone uses a 16 mhz resonator. Could that be it?

OK thanks, new question though. I got it to work fairly well by pulsing the infrared LED, but only while everything is attached to the arduino. When I put everything on a breadboard for a standalone, it does not work the same, even though I have a 9v battery hooked up and a +5 voltage regulator??? Why would it not work the same? The only difference is the power? My only thought is that the arduino uses a 16 mhz crystal with 2 capacitors while the stand alone uses a 16 mhz resonator. Could that be it?

Does the stand-alone unit run a simple sketch like Blink? Is it blinking at the right rate? If so, your standalone system is in pretty good shape.

Could it be that you forgot to connect +5v to the AVCC (Analog VCC) pin? The A/D converter gets a separate voltage input so it can be better isolated from electrical noise. That would keep your analog inputs from working.

Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

njs707

Yes that is definitely connected. I got it to work with my hand above the sensor at about 15 cm when connected to the arduino, but not even when I touch the receiver when on the breadboard. The weird thing is, if I bring the breadboard setup into the pitch black bathroom, my LED will turn on and I can interfere a little with my hand above the sensor? I know the IR led is emitting because I can see it with my phone's camera. Any other suggestions? I am pretty sure everything is set up correctly on the breadboard. The LED does do a simple blink perfectly if I program it to do that. Here is my code btw.... it works beautifully with the arduino... but not at all with the standalone.

Hint: take a reading when the LED is ON, and take a reading when the LED is OFF.

"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.I speak for myself, not Arduino.

Try this code with Serial Monitor running. If the average onVal and average offVal don't change when you put a hand over the sensor you probably have a wiring error. If the values shift as you move toward and away, publish the output and we can advise you what to do with the data.