I try to connect arduino uno r4 minima to a thermocouple but I don't understand how to read the value nor to operate with registers. Is there any chance to do it with libraries or in a simpler manner instead of using registers? Is someone could provide a code it would be very helpful.
Typically a thermocouple produces a small voltage relative to the temperature its measuring. Can you link to the thermocouple you have or are considering?
You will need a thermocouple amplifier module, such as those that Adafruit sells.
The amplifier must be compatible with the type of thermocouple used.
You will need a Maxim MAX31855K breakout board. I purchased mine from an eBay seller.
The below code is my "prove out code" for the 31855 board.
/*
Basic TypeK 16 bit read
Rev 04a
2019-11-12; verified with M0 tested at RT and -30 (with freeze spray)
*/
#include <SPI.h>
// *** Type K declarations ***************************************************
// ***************************************************************************
#define TypeK_RESOLUTION 0.25
const int TypeK_CS_Pin = 9;
const int SDCard_CS_Pin = 10;
bool TypeK_Error = false;
SPISettings TypeKsettings(1000000, MSBFIRST, SPI_MODE0);
// *** setup() ***************************************************************
// ***************************************************************************
void setup() {
SerialUSB.begin(115200);
delay (2000);
pinMode (TypeK_CS_Pin, OUTPUT);
digitalWrite(TypeK_CS_Pin, HIGH);
SPI.begin();
}
void loop() {
SerialUSB.print((ReadTemperature()>>2)*0.25);
SerialUSB.print(" TypeK_Error ");
SerialUSB.println(TypeK_Error);
delay (4000);
}
// *** Functions *********************************************************
// ***********************************************************************
int16_t ReadTemperature(void)
{
int16_t _rawData = 0;
digitalWrite(TypeK_CS_Pin, LOW); //stop measurement/conversion
delayMicroseconds(10);
digitalWrite(TypeK_CS_Pin, HIGH); //start measurement/conversion
delay(200);
digitalWrite(TypeK_CS_Pin, LOW); //set CS low to enable SPI interface for MAX31855
SPI.beginTransaction(SPISettings(5000000UL, MSBFIRST, SPI_MODE0));
_rawData = SPI.transfer16(0x0000); // TypeK is read only, doesn't matter what is sent in SPI.transfer16(0x000)
digitalWrite(TypeK_CS_Pin, HIGH); //deselect Type K
SPI.endTransaction();
return _rawData;
} // --- ReadRawData ----
/*
int16_t -32,768 to 32,767
to read all 32 bits......
for (uint8_t i = 0; i < 2; i++) //read 32-bits via hardware SPI, in order MSB->LSB (D31..D0 bit)
{
_rawData = (_rawData << 16) | SPI.transfer16(0x0000); // TypeK is read only, doesn't matter what is sent in SPI.transfer16(0x000)
}
digitalWrite(TypeK_CS_Pin, HIGH); //deselect Type K
_rawData = _rawData >> 18; //clear D17..D0 bits
if(_rawData & 0b10000000000000000) TypeK_Error = true;
*/
I've seen that arduino uno r4 has its own opamp, the pins are A1 and A2 and i want to connect to it a type N thermocouple, the reason is that i want to do as much as possible samples per second.
More specific, i have to log temperature and pressure with a pressure transducer and a thermocouple, I connected the pressure transducer to a hx711 with a sample rate of 94 Hz and i want to log the temperature in the "same" instant so I have a reliable log.
How can I do it exploiting the internal OPAMP?
No to the internal opamp.
Thermocouples output about 21µV per deg C. The opamp does not have the specs to deal with this low a voltage.
In addition, the thermocouple will have two junctions, one where you are trying to measure and one where the thermocouple connects to your circuit. This is the N tc material to copper.
Consider 94 hz is kinda slow. SPI interfaces are very fast. Take a look at the MAX31855N spec and see how fast it can take measurements.
Perhaps you can use a NTC.
Most people use an instrumentation amplifier plus other components, not an op amp, to measure the voltage from a thermocouple.
It is best to do some research before wiring things up.
I think most people use a thermocouple amplifier, it's much simpler.
Hi @nicksprin
The issue is that thermocouples only provide a relative output voltage in the microvolt range. Instrumentation amplifiers can measure this, however to generate any meaningful absolute temperature reading also requires what's know as "cold junction compensation".
Nowadays thermocouple amplifiers provide this compensation by measuring the ambient temperature, however in the past this compensation was provided by connecting two thermocouples together and placing one of them in a bucket of ice to provide a 0°C reference, hence "cold junction".
Which contains an instrumentation amplifier.
The Max31855 breakout board from Adafruit use a chip that is specific for K type thermocouples. The Max31856 supports multiple types including N type. Because both a source measurement and a cold junction measurement are required, followed by 2 lookup and interpolation operations to get the temperature value, you will get a sampling rate of maybe 10Hz.
Still, unless you have a good amount of experience with thermocouple applications and instrumentation amplifiers, (not to mention PCB design and fabrication, and all the other stuff that comes with trying to roll your own solution) then by far your most feasible approach is going to be use the Max31856 breakout board and live with the sampling rate. It gets you the functionality you need out of the box for a low price point.
If I only use only the hot junction is a big problem if the room temperature is not changing so much? (between 25 and 28 °C) I don't need an absolute measurement but I just want to compare different measurements done in "small" amount of time (a couple of hours).
Is there any other way to increase the sample rate? I've just seen that is very good if I obtain 3 samples per second with this instrumentation.
If is not the case what are the application cases of an OPAMP? I know they amplify low tensions...
That's slow for electronics but fast for temperature (and usually for pressure). The temperature isn't going to change (significantly) in 1/94th of a second and pressure doesn't change that fast either unless you are reading soundwaves or something like that.
It's also 338,400 samples per hour so you could end-up with a ton of data to store & analyze depending how long your measurement runs.
Thermocouples have advantages & disadvantages. The tiny voltage makes them finicky but they are rugged and principal on which they work is "infallible physics". It may be better & easier with a solid state temperature sensor. If you have high temperatures like a kitchen oven or kiln, a thermocouple is the way to go. For temperatures that are too high for a thermocouple some kind of IR temperature sensor is probably best.
Why not buy the Adafruit module and get some experience with real world measurements?
Then you will be in a much better position to do whatever it is you really want to do, and ask informed questions.
Please take a few moments to describe the actual project.
First as mentioned a thermocouple outputs a very small milli-volt output based on temperature. Like all thermocouples the Type N thermocouple has a chart we work from.
Note the thermocouples are not quite linear. Another issue you face is what we call CJC (Cold Junction Compensation). You want to read up on especially CJC as it's very important if you expect accurate measurements.
If you can use a Type K thermocouple the MAX6675 makes things easy. A simple Google of MAX6675 will get you a dozen hits. Inexpensive and solves CJC for you.
Ron
The datasheet specifies the conversion time for continuous mode conversions after the first conversion (which is slower) as 80ms. Then you have some overhead for handling the interrupt plus whatever code you execute between reads. The "stock" Adafruit library is probably sampling in one shot mode which will be slower.
Ok, I'm sorry for the not so informed questions. The project is a closed box in which a chemical reaction takes place inside. The box is equipped with an integrated type N thermocouple and a pressure transducer. I need to log pressure and temperature during the reaction (approx 1 min) in order to extrapolate some information. The box can be sealed and it is made by metal, the reaction is exotermic, temperature range should be from room temp (25°C) to around 550°C, the pressure from 1 to 8 bars. My idea (I cannot change the instrumentation) was to connect all the instruments to arduino and print the samples on serial
" millis | Temperature | Pressure
xxxxx | xxxxxxx | xxxxxxx
"
so i can copy and paste it in a txt file and elaborate it with MatLab.
As the reaction is very fast in the first seconds my fear is that I'll miss the point where the temperature and the pressure is the maximum one. The second problem is that i want the temperature and pressure sample at the "same" time (let's say with not so much delay).
The opamp is for general signals (tensions) in the "volts" range. A thermocouple requires a special high performance amplifier for low signals.
Consider a bolt or screw. Not every size will work for all applications.
Hi @nicksprin
Here are some type-N thermocouple compatible amplifiers: