Analog read IR sensor. Billiards project

Hi

I’m new to using Arduino but with a bit of electronics and programming capability. Working on my first Arduino project and i’m stuck, after 3 hours+ of trying to find an answer, resorting to asking here.

Project is to do with a billiards game. A snooker ball rolls down a gutter inside the table (little ambient light which is helpful). I need to measure if it is a red ball or a white ball (only two possible colours). I am using an arduino mega and an IR grey sensor (DFRobot Gravity:Analog Grayscale Sensor V). Other IR sensors have too short a range or are high/low output only. Ball rolls under the sensor. White ball sends back a stronger IR signal, reflecting more light than a red ball. I have got that part working fine, at least in my test rig.

Problem I have is its only registering the white ball signal when it rolls very slowly past the sensor. If it goes even remotely quickly then it misses it. So, i am guessing its sampling too slowly. All the forum advice i can find discusses very high sampling rates about what is technically feasible, but by my calculations, i “just” need to take 100 samples a second to ensure i capture a signal from it passing the sensor. That should be easy for it, right?? I would guess its taking a few reads per second at the mo. Any idea why so few? I am guessing its something too simple going wrong for me to find an answer online, or maybe a limitation of the sensor, which i doubt.

void loop()
{

int sensorValue = analogRead(A3);

myArray[Arraycount] = sensorValue;

if (Arraycount > 4) {
Arraycount = 0;

}

if (sensorValue < aaaa) {
myGLCD.print("White “, 110, 30);
delay(1000);
myGLCD.print(” ", 110, 30);
}

zzzz = (myArray[0] + myArray[1] + myArray[2] + myArray[3] + myArray[4])/5;
aaaa = zzzz - 10;

Arraycount = Arraycount + 1;

}

Actually, I think it could be the photocell on the sensor. Apparently these can take 10 microseconds to adjust with a high contrast in signal strength. My small change in light strength could be taking too long for the sensor maybe?

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.. :slight_smile: