I update the circuit and code. I also deleted the image of the circuit so as not to mislead others.
Please see my updated circuit and code.
Thanks to:
Old post:
I am creating an Arudino UNO IR detector project that will serve as a motion detector.
I've attached an image.
I have three questions.
-? RESISTOR - What is the function of the resistor with respect to the IR LED and IR DETECTOR ?
(I've always attached a resistor to and LED to protect the LED.)
-? Should I use something more than a 220 ohm?
-? A0 Input. I am using A0 for detection and I've seen some circuits that use something like pin 2. What is the fastest way to get IR detection.
The IR LED (and all LEDs) operate by a current passng through them, the series resistor limits the current. Applying a voltage across the LED will allow an uncontrolled current through it.
An IR LED has a typical volt drop of ~1.7 V. With an Arduino power supply of 5V and assuming the output voltage is also 5V, the current through the 220R is (5-1.7)/220 = 15mA nominally. I would expect this to be fine for your unspecified LED. 10mA to 20mA is fine for most LEDs.
Thank you for the post. I need the detection to be immediate.
My code is not working well:
const int analogInPin = A0; // Analog input pin that the receiver is attached to
int sensorValue = 0; // value read from the receiver
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
//initialize the indicator LED:
pinMode(13, OUTPUT);
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// print the results to the serial monitor:
Serial.print("\nsensor = ");
Serial.print(sensorValue);
//the threshold found fron analog In Out program was when object is detected, the sensor value is below 100
//set the threshold whihc you get
//the threshold varies for different sets of emitter-receiver pairs
if(sensorValue < 100){ //checks if object is there or not
digitalWrite(13, HIGH);
Serial.print("\nObject Detected");
}
else{
digitalWrite(13, LOW);
Serial.print("\nNo object in Front");
}
// delay(500);
}
I cannot advise on the code - not my area of expertise.
Hmm, immediate. What less than a nanosecond or a picosecond? I guess you mean 'immediate' in human determination terms; so tens or hundreds of microsconds.
I have just had a quick look at your circuit:
The IR LED is conencted across +5V and GND, so will be emit when the power is applied. There is no timing associated with its operation.
I am suspicious that the amount of voltage generated by the IR detector will not be enough to be detected.
Can you measure the voltage across the detector with a voltmeter; both with it illuminated and not (could use finger,say, to cover it rather than power the transmitter on/off).
As a test point the LED directly at the detector with close to zero gap. You will not get better coupling than this.
The IR detector is a current source (assuming that it is a photodiode) and will generate current, not voltage.
The usual method of detecting current is with a transconductance amplifier (Transimpedance amplifier - Wikipedia)
Thank you for the post! I got the circuit to work and I really like circuit . My son is an EE he will be able to help with it. I originally did not follow a good design I found on the internet. Makersportal.com was very helpful. Infrared Obstacle Detector for Less Than $1 — Maker Portal
I will re-post my solution after I do some more testing.
I was not powering the IR detector,
Now the question is to use pin 2 to supply voltage or 5v/3.3v to the IR detector.
//https://makersportal.com/blog/2018/1/17/infrared-obstacle-detector-for-less-than-1
//https://makersportal.com/shop
//Photodiode to digital pin 2 optional
int led=13; //LED to digital pin 7
int senRead=0; //Readings from sensor to analog pin 0
int limit = 1000; // play with system to find this limit (10K ohm resistor used)
void setup()
{
pinMode(led,OUTPUT);
digitalWrite(led,LOW); // LED initially off
Serial.begin(9600);
}
int val = 0;
void loop()
{
val=analogRead(senRead); //photodiode reading
Serial.println(val);
if(val <= limit) // NO OBSTICLE
{
digitalWrite(led,LOW); // LED OFF
delay(20);
}
else if(val > limit) // OBSTICLE DETECTED
{
digitalWrite(led,HIGH); //LED ON
delay(20);
}
}
Good that you got the circuit to work :slight_smile
Wht did you change?
I saw that in the maker Portal schematic that the IR detector was biased through 1Meg resistor.
The maker circuit does show the IR LED continuosly powered i.e. from the 5V supply via 47R resistor = lots of current, 70mA nom. The change being the reflecting from the detected object - I was unaware of this previously.
I added a 220 ohm to the IR LED and a 10K Ohm to the IR PHOTODIODE.
I also provide 5VDC from the Arduino 5V.
I will put 3 IR LED/ PHOTODIODE at 0cm 100cm and 110cm along a PVC pipe and drop a ball to simulate Galileo's discovery the the FINAL VELOCITY of a falling object is double its MEAN.
I'm a teacher / developer.
The project has a lot of industry applications as well.