Analogue Serial Output 1023 but multi-meter shows voltage change

Hello all,

I am struggling with reading data via analogue inputs of Arduino Uno connected with a basic temperature sensor.

Board Model: XC-4410 Duinotech Uno R3
Temperature Sensor: MCP9700 TO92

Sketch:


int tempPin = A2;
int tempReading;

void setup() {
analogReference(EXTERNAL);
Serial.begin(9600);
}

void loop() {

tempReading = analogRead(tempPin);
Serial.println(tempReading);

float voltage = (tempReading) * (3300 / 1024);

float temperatureC = ((voltage - 500) / 10);

Serial.println(temperatureC);

delay(2500);
}


Connections:

Board powered via USB (however, I have tried using a 12VDC power supply but same issue)
Sensor: VDD to 3.3V, VOUT to Analog Pin 2 and GND to ground

PROBLEM:

The problem is that no matter what analog pin I use and even if I disconnect the temperature sensor completely, the serial output reads 1023 as voltage output from Pin A2. Fluctuating the temperature has no affect on the readings. However, when the temperature sensor is connected, I used a multi-meter and it shows that as temperature changes, the voltage changes accordingly. So this tells me that temperature sensor is working but serial output is not.

What I have already tried:

  • The board is not shorted and is working fine (checked all analogue connections including AREF with multi-meter's continuity test)
  • Tried 12VDC power supply along with USB connection to read the serial output (but no luck)
  • Tried removing and inputting the analogue command analogReference(EXTERNAL); (but no luck)
  • Tried using a different Arduino board like DUE and EtherMega (but no luck)
  • Tried copying and pasting example code from GITHUB, Arduino Forums and other websites (but no luck)
  • Tried ALL the analog pins from A0 to A5 (but same result)

Questions I have:

  • Is the program correct for Arduino Uno?
  • Do I need any type of resistor to make it work?
  • What I am doing wrong?

All help is much appreciated guys and gals. By the way my experience and status with electronics and Arduino is "noob". I am a mechanical engineer trying to learn.

Cheers,
Muhammad

The MCP9700 is very simple. Apply a voltage to it, and it outputs an analog voltage according to the temperature.
Did you read the datasheet ? You can use it with 5V.

Did you read the reference of the analogReference ?
The line "analogReference(EXTERNAL);" sets the reference voltage to the AREF pin. But since you have nothing applied to that pin, there is no reference voltage.
Please remove that line.

In the 'c' language, you have to tell the compiler what to do.
The variable 'tempReading' is an integer. The '3300' and '1024' are integers. The means that the calculation is done with integers and after that it is converted to a float and stored in the variable 'voltage'.
I suggest to convert 'tempReading' to a float and calculate everything with float. Note that "3300.0" is a float number and "3300" is an integer number.

  float voltage = float(tempReading) * 3300.0 / 1024.0;
  float temperatureC = (voltage - 500.0) / 10.0;

Since you have tried so many things. If this can not make it work, is there something that was always the same ? Did you always use the same computer, the same Arduino board, the same USB cable ? Try to change everything.

First of all, thank you for your comment. I appreciate it.

Koepel:
The MCP9700 is very simple. Apply a voltage to it, and it outputs an analog voltage according to the temperature.
Did you read the datasheet ? You can use it with 5V.

Datasheet says that it can be used with voltages between 2.3V to 5.5V, so I am guessing whether I use 5V or 3.3V, both should be okay. The reason I am using 3.3V instead of 5V line is because according to many forums/website, specifically "Make Use Of", advised to use 3.3V line because 5V is generating too much noise whereas 3.3V is much more stable.

Koepel:
Did you read the reference of the analogReference ?
The line "analogReference(EXTERNAL);" sets the reference voltage to the AREF pin. But since you have nothing applied to that pin, there is no reference voltage.
Please remove that line.

Yes I did read the reference page you mentioned and the reason this code is included is because this line is required to use 3.3V line, otherwise program interprets it as 5V line. Again, this is from the forum/website. I didn't physically check it with a multi-meter, but I will now.

Koepel:
In the 'c' language, you have to tell the compiler what to do.
The variable 'tempReading' is an integer. The '3300' and '1024' are integers. The means that the calculation is done with integers and after that it is converted to a float and stored in the variable 'voltage'.
I suggest to convert 'tempReading' to a float and calculate everything with float. Note that "3300.0" is a float number and "3300" is an integer number.

Okay I will take your advise on this one but as you know this won't solve the problem since it's using the voltage serial output.

Koepel:
Since you have tried so many things. If this can not make it work, is there something that was always the same ? Did you always use the same computer, the same Arduino board, the same USB cable ? Try to change everything.

Computer and USB cable, I haven't tried but I have tried other Arduino boards like Due, EtherMega, EtherTen and getting a Leonardo board from my friend on Monday. The reason I don't suspect computer and USB because I am using the same to program my other sketches and they work fine with digital pins.

The essence of the problem, I believe, is ANALOGUE OUTPUT. Sensor is working fine and with a multi-meter it shows voltage changes and everything. It's only when I look at the serial output window, I am getting garbage. Also, another thing to note is that when I disconnect the temp sensor, it still shows garbage output of 1023. But when I check with my multi-meter, there is no short :frowning:

Any more ideas or comments?

In the tutorials at Adafruit they sometimes set the EXTERNAL analog reference and connect the 3.3V to AREF.
The reason is that the 3.3V comes from a voltage regulator which is a lot more stable than the 5V from the USB connector.
I don't know if you have connected 3.3V to AREF.

That is something for later. You have to make it work first.

Do you use a breadboard ? Breadboards have often bad contacts. You can place it on another location on the breadboard.

Remove everything that is not needed. Remove the wire from 3.3V to AREF (if you have that wire). Remove the EXTERNAL analog reference from the sketch. Just output the value from analogRead() to the serial monitor.
If you don't see a good value, remove the temperature sensor and put a wire to A2 and connect that with 5V and GND. If that still does not change things, then your board is bad.

Your sketch uses A2. Are you sure you have connected the sensor to the A2 pin ?

When nothing is connected to a digital or analog input, the value can be anything. You can not measure something with a multimeter at an open input. You can measure the voltage of the sensor and if that voltage gets to A2.

Please show the new (bare minimum) sketch, so we can check if it is okay. You could make a photo to check the wiring.

Thanks again Koepel.

Koepel:
In the tutorials at Adafruit they sometimes set the EXTERNAL analog reference and connect the 3.3V to AREF.
The reason is that the 3.3V comes from a voltage regulator which is a lot more stable than the 5V from the USB connector.
I don't know if you have connected 3.3V to AREF.

No I haven't connected a wire from 3.3V to AREF, according to documentation, that's why we use the analogreference external command, i thought?

Koepel:
Do you use a breadboard ? Breadboards have often bad contacts. You can place it on another location on the breadboard.

No, unfortunately I don't have a breadboard, they are actual soldered connections.

Koepel:
Remove everything that is not needed. Remove the wire from 3.3V to AREF (if you have that wire). Remove the EXTERNAL analog reference from the sketch. Just output the value from analogRead() to the serial monitor.
If you don't see a good value, remove the temperature sensor and put a wire to A2 and connect that with 5V and GND. If that still does not change things, then your board is bad.

Ok will try that but on Monday, I have few other things to take care of today.

Koepel:
Your sketch uses A2. Are you sure you have connected the sensor to the A2 pin ?

Yes I always change the pin number when I de-solder and re-solder.

Koepel:
When nothing is connected to a digital or analog input, the value can be anything. You can not measure something with a multimeter at an open input. You can measure the voltage of the sensor and if that voltage gets to A2.

Yes you are right, I will try to measure the voltage while the sensor is connected.

Koepel:
Please show the new (bare minimum) sketch, so we can check if it is okay. You could make a photo to check the wiring.

Will do but earliest will be Monday.

Cheers,
Muhammad

Hi all,

Right the problem has been solved. Not really sure how but here are the following things I have done:

  1. There was a wire connected to 3.3V to IOREF, I thought it was AREF but realised AREF was on the other side with the digital pins. Now there are no wires connecting nothing.
  2. I removed the analogReference(EXTERNAL) from my sketch. I am still not sure whether I would be needing this or not but will find out in future.
  3. Simply I connected 3.3V, GND and A2 and voila, it works.
  4. Now I have moved to PT100 and still able to make it work :slight_smile: But not sure how to do the calculations since it is a thermistor.

I am still not getting the correct readings but the A2 pin readings change according to temperature change, so that's a relief.

Thank you Koepel, I followed your troubleshooting steps to make it work.

Cheers,
Muhammad

There are a number of examples with a PT100.
Perhaps you can start with this one: Make an Arduino Temperature Sensor (Thermistor Tutorial)

A PT100 resistor has specific values for the curve of the temperature and the resistance. With those values and a formula the temperature can be calculated.

When a PT100 with a resistor are used, the output voltage changes if the 5V changes. When the Arduino uses the default reference of 5V, then the result will still be okay, since the value of analogRead() will be the same if the 5V changes.

That means with a PT100 you have better results if you do not use EXTERNAL reference, but keep the default as it is.