Help with voltage conversion on the MCP3002

I’m a beginner in programming in Arduino, so I need help coding my project. I am using an NTC sensor to read the temperature and through a conditioning circuit the temperature is converted into a voltage of 0 to 5 volts.
Basically, I need the MCP3002 to read the voltage and send it to the Arduino. In the Arduino the voltage read by the MCP3002 is converted to temperature, however, the return value is:

I’m using this code as a base:

// MCP3002 - Example code using Arduino UNO.
// March 17,2013
// Wiring
//    Pin 10 to /CS
//    Pin 11 to Din
//    Pin 12 to Dout
//    Pin 13 to CLK
//
// Do a conversion on both channels and write results to serial port.
//
// Include the SPI library:
#include <SPI.h>
// Set pin 10 as the slave select for A/D converter
const int slaveSelect = 10;

void setup()
{
 // Initialize serial port for com to host
 Serial.begin (9600);
 // Set the slave select pin as an output
 pinMode (slaveSelect, OUTPUT);
 // Initialize SPI
 SPI.begin();
 SPI.setBitOrder (MSBFIRST);
 
}

void loop()
{
 // Going to be doing a conversion on both channels (ch0,ch1)
  byte conversionMSB,conversionLSB;
 word chA,chB;
 float T1;
 digitalWrite (slaveSelect,LOW);
 
 // Communication with the device starts when /CS line brought low.
 // The first '1' bit transmitted is the start bit.
 // The next 3 bits define
 //    Single Ended Input / Differential Input
 //    Ch0 / Ch1 if single ended input or polarity if differential
 //    MSBF / LSBF (Most/Least Significan Bit First)
 // The returned value is ten bits long so if the bit pattern transmitted
 // is placed correctly, the two most significant bits will be sent back
 // with the first transfer. the rest on the second transfer.
 conversionMSB = SPI.transfer (0x60);
 conversionLSB = SPI.transfer (0);
 
chA = word (conversionMSB,conversionLSB);
T1= (chA+0.4855)/0.1552;                                    // Equation that converts the voltage to degrees
 
 
 digitalWrite (slaveSelect,HIGH);
  Serial.print("Voltage: ");
  Serial.print (chA,DEC); 
  Serial.print(" Temperature: ");
  Serial.print (T1,DEC); 
  

 // Do the same conversion but with the second channel.
 digitalWrite (slaveSelect,LOW);
 conversionMSB = SPI.transfer (0x70);
 conversionLSB = SPI.transfer (0);
 chB = word (conversionMSB,conversionLSB);
 digitalWrite (slaveSelect,HIGH);
 Serial.println (chB,DEC);
 delay (100);

 digitalWrite(8, HIGH); 

 
}

I know the Arduino has an analog input, but one of the conditions of this project is to use an external A/D for the conversion.
Thank you for your help!

Does 645 sound reasonable for the a/d data? If so, this line:

T1= (chA+0.4855)/0.1552;

Is the problem as adding .4855 to a 10 bit analog value is completely nonsensical. What is the relationship between raw analog counts and temperature?

Converting A/D values to voltage only makes sense if you are trying to make a voltmeter.

Convert A/D value directly to temperature using a Steinhart-Hart formula.
Many thermistor examples on this site.

Not sure why you use an external 10-bit ratiometric A/D, while most Arduino's already have a buildin 10-bit ratiometric A/D.
Leo..

Not sure why you use an external 10-bit ratiometric A/D, while most Arduino's already have a buildin 10-bit ratiometric A/D.

Because, as the OP says, it is homework:-

but one of the conditions of this project is to use an external A/D for the conversion.

I don't see 'homework' mentioned anywhere, but ok, OP wants to use an external A/D.
Same difference though.
Get that 10-bit A/D value, and use it like in all the common thermistor examples.
Leo..

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Have you tried putting a potentiometer on the ADC input and adjusting the input to see if your reading changes?

Thanks.. Tom... :slight_smile:

I don't see 'homework' mentioned anywhere, but ok, OP wants to use an external A/D.

No the OP is required to use an external A/D, he doesn’t want to use one he is required to use one. He says

but one of the conditions of this project is to use an external A/D for the conversion.

Who sets these requirements if it is not the person wanting the project to be done. What is the point in setting this requirement if it is not educational? There are no other advantages in using an external one.