Go Down

Topic: Help with AnalogReadSerial (Getting a more accurate result) (Read 277 times) previous topic - next topic

jamesdacombe

Hi,

I have been using the AnalogReadSerial to get the input from a photodiode. The problem is that it only gives you a value between 0-1024 and I need the value to be something closer to 0-100,000 or more. Does anyone know of a way to do this, or if I need a different piece of code. This is what the code is currently, any help would be appreciated:

Code: [Select]
// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue0 = analogRead(A0);
  int sensorValue1 = analogRead(A1);
  int sensorValue2 = analogRead(A2);
  
  // print out the value you read:
  Serial.println(sensorValue0);
  Serial.println(sensorValue1);
  Serial.println(sensorValue2);

  delay(1);        // delay in between reads for stability
}


Thanks,
James

AWOL

Have you come across the C multiplication operator, written '*' ?
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

jamesdacombe

Have you come across the C multiplication operator, written '*' ?
No, I have only just started to work with C and Arduino.

Would you be able to point me in the correct direction,

Thanks

slipstick

You can't get a more accurate result than 0 - 1023 with the 10 bit ADC in most Arduinos. You could multiply it by 100 so you had 0 - 102300 but the last 2 digits would only ever be 00 so it's no more accurate.

If you really need to measure to an accuracy of better than 1 part in 100,000 (though I can't imagine why) then you need an ADC with more than 16 bits. No Arduino has one of those as standard.

Steve

jamesdacombe

You can't get a more accurate result than 0 - 1023 with the 10 bit ADC in most Arduinos. You could multiply it by 100 so you had 0 - 102300 but the last 2 digits would only ever be 00 so it's no more accurate.

If you really need to measure to an accuracy of better than 1 part in 100,000 (though I can't imagine why) then you need an ADC with more than 16 bits. No Arduino has one of those as standard.

Steve
Thank you very much, do you know of any boards that do offer this?

Thanks

slipstick

How fast do you need to read your device? Sample rate or samples / second. There are add-on modules around with up to 24 bit ADCs but if you want fast sampling you'll need a lot of processing power and storage.

Steve

jamesdacombe

How fast do you need to read your device? Sample rate or samples / second. There are add-on modules around with up to 24 bit ADCs but if you want fast sampling you'll need a lot of processing power and storage.

Steve
Just as fast as it can be, the faster the better. I know it sounds like a lot but it's for a medical imaging prototype using machine learning and we need really accurate data and lots of it.

What would you recommend for this?

Thanks,
James

AWOL

Quote
it's for a medical imaging prototype
So, we have "fast", "imaging" and "at least 17 bits of analogue resolution"
("As fast as it can be" is about as useless a "specification" as I've seen in a while)

None ideally suited to the Arduino world.

What are you trying to do?
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

slipstick

Sorry, engineering type here. When I ask for sample rate I'm expecting numbers not "the faster the better". There must be a minimum sample rate (in samples per second) that would be acceptable for your project and if you don't know what it is you have some more work to do on your specification.

But as AWOL says I suspect Arduinos are not what you need. A PC with a decent specification might do the job.

Steve

Koepel

What is the accuracy of the photodiode ?
Which photodiode is it ?
What is your project ?

If you want to measure the lux, then you better buy a sensor with digital interface.
The cheapest BH1750 costs less than 1 dollar and is easy to use. Its overal accuracy is 20%. Other lux sensors are better and cost a little more. Some lux sensor can even measure milli-lux.

Andym535

Do you mean accuracy or precision? 10bits of precision is better than the accuracy of most sensors which might be +- 1 or 2%

Go Up