Hello sir / madam ,
I am Akshay Sunna , currently intern at B/S/H India , I’m facing some technical issues with the output given by the IR receiver/emitter , I made a basic object detection system , everytime a object passed through their line of sight it raises a count , so it was working fine but if left idle at some point in time , a false count is being increased , I wanna talk related to this , kindly help me with this issue.
Just to make sure, i’ve kept it in a closed cupboard with no external interference and wiring is correct and code is also working , i.e.
const int irEmitterPin = 3;
const int irReceiverPin = 4;
int objectDetectionCount = 0;
bool objectPresent = false;
void setup() {
pinMode(irEmitterPin, OUTPUT);
pinMode(irReceiverPin, INPUT);
Serial.begin(9600);
Serial.println(“IR Proximity Sensor Test”);
}
void loop() {
// Turn on the IR Emitter (Infrared LED)
digitalWrite(irEmitterPin, HIGH);
delay(10); // Give some time for the emitter to stabilize its output
// Read the IR Receiver (Infrared Photodiode)
int irReceiverValue = digitalRead(irReceiverPin);
// Check if the IR Receiver detects the emitted IR signal (presence detected)
if (irReceiverValue == HIGH && !objectPresent) {
// Object detected (signal not received)
objectDetectionCount++;
Serial.print("Object detected. Count: ");
Serial.println(objectDetectionCount);
objectPresent = true;
}
// Check if the IR Receiver doesn’t detect the emitted IR signal (no presence)
if (irReceiverValue == LOW) {
objectPresent = false;
}
// Turn off the IR Emitter to save power
digitalWrite(irEmitterPin, LOW);
// Add a small delay to control the sensing rate
delay(100);
}
What type of infrared receiver/transmitter do you use? Is it a SeeedStudio product?
Yes the Grove IR Emitter/receiver that come as two separate components
Grove - Infrared Receiver | Seeed Studio Wiki
In this document, you can use the example here to test if it works, and if it does, we’ll move on
so like the thing is , it is working fine for upto 40cm distance , but after 40cm i.e. distance b/w sensors > 40cm its generating a false count i.e. detecting object even if there isnt any.