How are the threshold values determined by Arduino?

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.?

Please help........................................

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.

...R

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.

Can you please help with some coding knowledge on how to interpret that range of values i read from sensor(Linear Array Sensor TSL1401)??

I don’t know where i have struck up because i don’t get constant series readings at all… the readings from the sensor are random series of numbers :blush:

Any firmware or hardware support ?? :cold_sweat: :cold_sweat:

analogInput returns a value between 0 and 1023 inclusive. It is directly related to the reference voltage (usually 5v). So 1023 represents 5v.

If you want 1 or 0 you'd use digitalRead, but this would probably be the wrong method to use in this application.

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:
Line 23 of your code contains the problem - well according to my crystal ball that is.

I'm guessing at line 27. I wonder if we'll ever find out which of us is closest :slight_smile:

vaish:
Can you please help with some coding knowledge on how to interpret that range of values i read from sensor(Linear Array Sensor TSL1401)??

I thought I had given some help in Reply #1.

But you seem to have ignored that so it is hard to know how else to help?

If you did not understand something, please let me know.

...R

Thank you all :slight_smile:
and thank you Mr.Robin for your kind response ..

Now somehow i managed to set a threshold and get some readings from my sensor(TSL1401)..

Now the problem is that my sensor randomly reads only once later on i get only '0's.

I have just set the clock and SI in the loop that runs for 128 cycles as given in the datasheet nothing else apart from that..

vaish:
Now somehow i managed to set a threshold and get some readings from my sensor(TSL1401)..

How can we help when you have not posted the new version of your code?

...R

Robin2:
How can we help when you have not posted the new version of your code?

Or indeed the old version, or the schematic.

Grumpy_Mike:
Or indeed the old version, or the schematic.

Or indeed the old version of the code either.

vaish:
Thank you all :slight_smile:
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.

Here is my simple code that hangs up after reading once. :slight_smile:

My application is to detect a line or character… Presently i have an arduino uno+taos tsl1401 sensor and working on it…

Please my guide me out … As am a fresher am struggling a lot to proceed with my application…

LSA_1401.txt (2.24 KB)

  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.

You have said my code provides 800Hz..
Can you please tell me how did formulate that??
Coz its been a month that am trying to figure it out.. :cry:

Look at the figures in brackets that were provided after the 800 figure.

Help please........... i have enclosed my code even in the previous post..

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.