Reading very low voltages with analog pin

Hello,

I am relatively new to Arduino. My project basically revolves around creating a light pattern controlled from an Arduino nano. In order to initiate the pattern I have connected a wire to one of the analog pins that can either have a voltage of .15 V or .31 V (essentially a logic wire for servo). However when reading in the voltage on the analog pin the value is 0 V and occasionally jumps to 696 (2.25 V). changing the input signal for .15 to .31 V has no impact on the voltage read in which is displayed in the serial monitor. Does anyone have any suggestions or has ever encountered a similar problem?

Thanks!

1:

a wire that can either have a voltage of .15 V or .31 V

Did you check that voltage (using a DMM)?

2:
Insert a line with Serial.println(val); after val=analogRead etc. to see if val has the expected value.

3:
Divide by 1024 to get voltage, not 1023. AnalogRead() always gives one of 1024 possible values, not 1023.

Edit: 4: I don't know, would pinMode(analogPin, INPUT); in setup() make a diference?

5: Is your Arduino running on 3.3 volt?

6: Change voltage = val * (3.3 / 1023); to voltage = 3.3 * val /1024; ! I think it's doing integer arithmetic now...

You will probably not get a good voltage reading from the typical servo control wire using a DMM or the Arduino's ADC sampling every second, since it carries PWM signal...often about 50 Hz with 1 to 2 ms pulses. For more on that topic, see the "Control Signal" part of this: Servo Trigger Hookup Guide - SparkFun Learn

But in general, for voltages of that range...

Use the 1.1v internal reference. analogReference() - Arduino Reference

It is not very accurate, but it is stable (which may or may not be a good thing...) and of a more appropriate "size" for your input range.

If you really need "accurate," include some math so your Serial output matches what you measure with your DMM (find the equation of the straight line that passes through your two known points).

And check your connections.

PS: 1023 vs 1024 has been endlessly debated (google Arduino 1023 1024), but if you calibrate your output as suggested, neither of those numbers will need to be used. And if you don't need "accurate," then either one will do.

PPS: if you tell more about your "essentially a logic wire for a servo" signal, then maybe better help will appear...

DaveEvans:
PS: 1023 vs 1024 has been endlessly debated

The debate is over. Finished. Done. But there is half a bit to add.
See: Gammon Forum : Electronics : Microprocessors : ADC conversion on the Arduino (analogRead).

Koepel:
The debate is over. Finished. Done.

Not yet. There are still people believing in The Only Right Divisor oblivious to the fact neither is correct. It does not matter because the difference is less than the ADC inaccuracy.

For OP: you don't want to convert the value to float. Floats are slow, tricky and there is rarely a good reason to use them. Just measure voltage in LSBs instead of volts.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.