[solved] analogread( ) retuerns "12" always - Leonardo

Hi everyone,

I made a voltage divider with a thermocouple for temperature sensing.
I used the pin “A0” for the voltage input. (ADC input)

The ADC value from the “A0” was supposed to be got by “analogread()”
However, the return value from “analogread()” was “12” always.

I did:

#1
I checked the voltage on “A0” by the voltage meter.
It was about 2.4V. so the “analogread()” would have returned about an integer value “4xx”
but not… :frowning:

#2
I have tried to add a statement “pinmode(A0,INPUT)” but the result was the same.
(Besides, this statement could be used for digital input!?)

#3
I have tried “analogread(0)” and “analogread(18)”

Anyone can give me some tips or suggestions?
Thanks

int THSensorADC = 0;

void setup() {
  // put your setup code here, to run once:
   Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  THSensorADC=analogRead(A0);
  Serial.print (THSensorADC);

  delay(1000); 
}

BOARD.png

OP's pictures

I made a voltage divider with a thermocouple for temperature sensing.

Probably not a thermocouple, as that would act similarly to a short circuit. Or if you did use a thermocouple, you need a thermocouple amplifier.

Post a link to the sensing element that you actually used.

PS: don’t bother with Fritzing diagams. They are usually misleading and often wrong.

jremington:
Probably not a thermocouple, as that would act similarly to a short circuit. Or if you did use a thermocouple, you need a thermocouple amplifier.

Post a link to the sensing element that you actually used.

PS: don't bother with Fritzing diagams. They are usually misleading and often wrong.

Hi jremington,

I'm not sure the real name of the sensing element and the official spec. I got the part from a recycle circuit.
It could be a "Thermistor". sorry for made you confused.

The resistance value is about 10k ohm at 25 temperature celsius.

That's a 10k thermistor then. You think to try another analog pin? Perhaps you fried A0?

MarkT:
That's a 10k thermistor then. You think to try another analog pin? Perhaps you fried A0?

Hi,
I have tested A0~A5. The results are similar.(the ADC value fluctuated between 12~17)

" fried "!? ok, I'm going to find another Arduino board and test it again.

Thanks

Do you have a multimeter ? To measure the resistance of the thermistor.
Put it into hot and cold water and see what happens with the resistance.

A thermistor is also called a NTC. Each thermistor type has a specific curve for the temperature.

It is possible to damage the analog section of the microcontroller. Or there is something wrong with the AREF pin.

A thermistor is complex. For example this blog shows what is needed: Arduino and Thermistors – The Secret to Accurate Room Temperature

If you want to measure the room temperature or water temperature, then I suggest a DS18B20. You need two libraries (OneWire and DallasTemperture) and then you have the temperature accurate to ±0.5°C.

Your sketch is okay. To use a function correctly, see the examples in the reference.
The analogRead(A0) is used without pinMode(..., INPUT). A digital pin is always set with pinMode(...).

What really happens is that both the digital part and the analog part are active on that pin at the same time. The digital part is already set as input.
For the simple basic Arduino boards, you don't have to call pinMode(..., INPUT) when that pin is used as a digital input. But it is good practice to do that, it makes clear what that pin is doing.

Koepel:
Do you have a multimeter ? To measure the resistance of the thermistor.
Put it into hot and cold water and see what happens with the resistance.

Hi Koepel,

Thanks for your suggestions and link

#1.I have measured the voltage on A0 by the multimeter. It's about 2.4v(ambient temperature)

#2.I tested it on another Arduino Board (an UNO, not a Leonardo).
The analogReadis() value was resemble.
It stood at about "450" in the beginning.
When I put it in hot water, there was a rapid increase to over 700. After that, I pull it out of the hot water and the value backed to 450 gradually!!

Since the circuit and code work correctly on the UNO, I would like to test it on another "Leonardo"
As MarkT said "Perhaps you fried A0"

Moreover, I'm looking for any discussion about "Leonardo ADC" on the internet

Thanks!!

For the Arduino Uno, the analog section is a seperate section on the ATmega328P chip. So it is possible to damage a single analog input, but it is also possible to damage the complete analog section, while the rest of the chip still works.

I assume it is the same for the Leonardo.
There is nothing special for the Leonardo ADC. When it is broken, then it is broken.

You could check the Leonardo board with a magnifier. Check the analog pcb traces and the AREF pcb trace. If a analog input is really damaged, then you should get rid of the board because other things could be damaged as well.

Hi everyone,

I re-test the circuit and the firmware on another Leonardo and Uno.
The ADC got the value correctly.

So I believed that this issue is caused by damaged I/O. (as MarkT and Koepel mentioned)

Thanks!!