While Interfacing an Arduino with Linear Sensor Array(TSL1401)
1.) When the arduino-uno reads analog input from the linear sensor(TSL1401) how does the Arduino determine the threshold between 0 and 1? What should be done in the coding to get precise '0' and '1' for white and black color detection??
2.) Are the readings of individual pixels getting stored as bits.?
I have only had a quick look at the datasheet for that device. It looks like the output should be read by one of the Arduino analog inputs. If so that will produce a value between 0 and 1023 depending on the voltage produced by the sensor. It is up to you to decide how to interpret that range of values.
If you have some code please post it for a more useful response.
The absolute values will depend on lighting conditions and the quality of your "white" and "black" pigments. Keep track of the highest and lowest values you read and set the threshold at the average of those two values. Treat values below the threshold as BLACK and values above the threshold as WHITE.
What should be done in the coding to get precise '0' and '1' for white and black color detection??
Absolutely nothing you can do in the coding to change this.
However you can use a comparator for the input and set the threshold level with a pot. There is even one built into the arduino if you want to use that.
the readings from the sensor are random series of numbers
Line 23 of your code contains the problem - well according to my crystal ball that is.
Grumpy_Mike:
Or indeed the old version, or the schematic.
Or indeed the old version of the code either.
vaish:
Thank you all
Now the problem is that my sensor randomly reads only once later on i get only '0's.
This is a problem on line 32 of your code. But this is another prediction based on random guesswork as it's the only method we currently have at our disposal.
for(int i=0; i<128;i++) //for 128 Cycles Generate Clock and SI
{
CLK_Pulse(); //Set Clock Pulse
if(i == 0) // During the first pulse
{
SI_Pulse(); //Set SI function
}
else if(i != 0)
{
digitalWrite(SI,LOW); //Set SI complete Low
}
Send a clock pulse and then send a start integration?
Is that what the timing diagram shows?
(BTW, if the counter isn't zero, there's no need to test it again. Also, the pulse functions ensure that the line is low before they exit, so there's no need to belt-and-brace it)
Edit: In fact, I'd move the start integration outside the loop altogether.
Edit edit: I found the datasheet for the sensor - the minimum clock frequency is 5kHz - your software is providing only about 800Hz (1000us delay, 100us clock pulse, 100us analogue conversion). It might be better to use the processor's comparator and do the thresholding with that and skip the analogRead altogether.
vaish:
i have enclosed my code even in the previous post..
You have not made any changes to that after being told the clock rate was too slow for the sensor. So you need to change that and if you are still having problems post your new code with the changes in and say what it does wrong.
Personally I am still waiting for a schematic.