Serial monitor gives values only 20 to 120

I am using a simple 2 phototransistor to obtain light intensity readings from Arduino Uno.
My code seems correct.
Yet the values I get range only between 20 and 120 (20 darkness, 120 light).
Why are the numbers in the serial monitor so restricted?

int sensorValue = 0;
void setup()
{
  pinMode(A0, INPUT);
  Serial.begin(9600);
}
void loop()
{
  sensorValue = analogRead(A0);
  Serial.println(sensorValue);
  delay(100);  
}

Well, if we knew what your circuit configuration is ..

and links to the data sheet

we might be able to offer more help.
Meanwhile - the signal you are measuring is too small.

Its the standard voltage divider. Here is the actual picture. I have tried 2 different photodiodes and still the range is 20 to 120. Even if I plug the A0 pin into ground its 120 and if I plug into 5V its 20.

I did see that you tried to use code tags; unfortunately it did not quite work out :wink:

I've fixed it.

Code tags for a block of code consist of 3 backticks (```) on their own line before the code and 3 backticks (```) on their own line after the code.

1 Like

Try a 10k or 100k resistor see if it makes a difference . Also try reversing the photo transistor.

Oh. It sounds hopeless. The problem is elsewhere. Try another analog pin. The range should be 0 to 1023 assuming a Uno etc.

What is the AREF pin connected to ?? Seems to be unconnected in the picture.

Once that you have verified that the analog input is working correctly, make sure that the photodiode is installed in the correct orientation.

Simplest working circuit:

Capture

Its so weird, I bought a brand new board, Uno R3, and with exactly the same sketch and the same wiring setup the numbers range from low single digits to >1000. The old boards I guess do not work? The numbers on old board are exactly between 20 and 120, with very little variability in-between. Thanks all for writing to me and trying to help.

It sounds like that board is a member of the Crispy Critters family or at least a cozen. Try the other channels with the resistor from A? to +5 and Ground and see what the readings are. It should be close to the new board, if not you have a fried analog section. Test the digital they may be bad as well. What did you connect to this board, A relay, motor or something like that? Do you have a resistor in the 50K range, try that.

Not only are those wrong they are also upside down. A0 should read around 1023 when connected to Vcc, and around zero when connected to ground.
Its safest to make connections to Vcc or ground through a 10k resistor.
Try the other analog inputs.

1 Like