Would the Photon Shield Shield fix my temperature reading problems?

Please forgive me in advance for my lack of hardware knowledge. I am a software developer that is just getting started in hardware development.

I have previously built a BBQ thermometer using an Arduino uno. It was a typical project that seems to be common in that community. I used a Thermoworks TX-1001X-OP thermometer connected to a 10k resistor. With this I was easily able to get accurate temperature readings.

When I moved this to the Photon I quickly learned that it is not possible to use this same circuit as the photon operates with 3.3v vs the Arduino 5v (??? Correct me if I am wrong here)

Would the shield shield correct my woes I have with the photon currently? I’m looking for the simplest solution as I have previously mentioned, I am very new to hardware development. Another option I have looked at is a thermocouple amplifier such as this one https://www.adafruit.com/product/1778

If I’m not mistaken that’s a simple ‘thermistor’. Basically a resistor that changes its value depending on its temperature. If you hook this up in series, the voltage will divide over the resistors relative to their values, a so-called ‘voltage divider’. Equal value resistors will receive 1/2 of the voltage each. A 1k and 9k resistor will receive 1/10 and 9/10 of the voltage respectively.
Your current arduino setup assumes a starting voltages of 5V whereas the Photon uses 3.3V. Hence, those calculations won’t be correct without modification. Additionally, the Photon measures with higher accuracy, resulting in 4096 steps rather than 1024 on an arduino. This will also need to be taken into consideration.

You’ll most likely find both these numbers in an equation in your arduino code. If you modify them to their new values, you should be good to go. Give it a shot, and let us know if it work, and if not, where you struggle :wink:

2 Likes

Here is roughly the circuit that I am working with. I am using a 2.5mm MONO audio connector, not a stereo connector.

And this is the code I am currently using (hacked up code I found from another project awhile back)

#include "math.h"

#define PROBE1 1
#define SMOOTH TRUE

// Measure actual board voltage, from 3v3* to GND with voltage multimeter, it's rarely exactly 3.3
const float VREF = 3.38;

// What resistor did you use from 3v3* to between the analog pin and positive pin of thermistor?
// Measure it with multimeter
const int RESISTOR = 9970;

// ADC chip cycles is 4096 - 1
const int ADC_REF = 4095;

// Global vars in case we want to set them on the fly
double A, B, C;

int aval;


void setup() {
    // Start serial at 9600 baud
    Serial.begin(9600);
    
    // 732 constants
    A = 2.3067434E-4;
    B = 2.3696596E-4;
    C = 1.2636414E-7;
    
    Particle.variable("reading", aval);
}

void loop() {
    double bbqTemp;
    
    //Input = thermistor_temp(analogRead(PROBE1));
    bbqTemp = thermistor_temp(PROBE1);
    
    Spark.publish("Reading", String(analogRead(PROBE1)));
    Spark.publish("Temperature", String(bbqTemp));   

    delay(2000);
}

double thermistor_temp(int pin) { //Function to do theristor calculations
    double R, T;

    // read in smoothly
    aval = analogRead(pin);

    // What was the voltage that the pin saw? 
    // Calculate based on known ADC value and multimeter measured voltage from 3v3* to GND
    // float casting is required as aval divided by ADC may result in a fraction
    float Vout = ((float) aval / (float) ADC_REF) * VREF;
    
    // Calculate the original resistance
    R = (RESISTOR * VREF / Vout) - RESISTOR;
    
    // calculate log10(R)
    R = log(R);

    // Calculate temperature in Celsius
    T = (1 / (A + B * R + C * R * R * R)) - 273.15;
    
    // return degrees Celcius
  return (T);
    
}

The readings I am receiving are roughly in the 45 - 55 degree celcius range. Much too high for what should be closer to room temperature (23 - 27).

Any idea what I am doing wrong, where my code looks sour?

Did you verify that your constants work for Particle's 12bit analogRead() return (i.e. 0-4095 versus your Arduino's 0-1023)?

you can try to substitute this:

aval = analogRead(pin);

with this:

aval = map(analogRead(pin), 0, 1023);

for a quick check of reasonableness....

if that makes sense, refactor your constants for the better resolution....

I guess you’d need to write it this way

aval = map(analogRead(pin), 0, 4095, 0, 1023);

which would easier be done via

aval = analogRead(pin) >> 2;

But this suggests that the 12bit was already taken in consideration

// ADC chip cycles is 4096 - 1
const int ADC_REF = 4095;

Going back to my original post title… would the Photon Shield allow me to reuse my code / circuit from my Arduino? I’m starting to bang my head against the wall with the problems I’m currently running into, if the Shield would resolve my issues then I would be a very happy camper :smile:

All the software changes were good and required, but I think you also have a hardware problem. Because the ADC on the ST32F microcontroller in a Photon is not buffered the way it is on an Atmel micro in an Arduino, lots of times you need a simple op-amp buffer to fix impedance problems.

Have you tried adding a op-amp as a voltage follower between the resistor/probe and the ADC input pin? This is a $1 solution.

The Photon Shield will do nothing to fix this in my opinion.

2 Likes

I just tested a temp sensor today, LM335A, which I had been using in a big ioio project. It is remarkably accurate run from the photon 3.3v power supply.

This is the formula, to get degrees F from 4095 analog in range.

=(((analog pin/ 4095 *330)-273.15)*9/5)+32

=(((A1 / 4095 x 330)-273.15)*9/5)+32 (fixing the missing x)

Also, to add, I found the shield shield shield was more trouble than it was worth, in my application. 5v inputs latch high or low, unless adding external pullup / pulldown resistors, which could be as easily treated with voltage dividers without the cost of the shield. I had purchased some shields to handle 5v relays, but relay boards are easily driven with 5.xv vin to vin on the relay board, and 3.3v as digital write to the reciving pins on the relay board. This has been tested with up to 4 relays on at once.