Help needed with adding thermistor

Hi All.

I’m a complete noob with cayenne, and have only produced a few limited projects using other platforms.

I’m trying to produce a BBQ temp probe using a D1 mini and a high temp thermistor, but i’ve struck my first issue. I’ve managed to upload the Cayenne-MQTT-ESP sketch to my D1 and can see it in the dashboard, but i’m unable to add my thermistor.
I select add new, sensor, temperature, thermistor but i am unable to select device from the drop down as it is greyed out and the add sensor button is greyed out.

have I missed something obvious or have I misunderstood the adding of sensors completely.

regards

Lee

welcome to the cayenne community @lee.brock17.
have you added the temperature sensor code to Cayenne-MQTT-ESP sketch?

Thanks for the reply.

I did some reading up last night to try and help myself, and realised that I’m unable to add the thermistor in the dashboard and should instead add it to my sketch.

I’m now at the point where i have added the thermistor code to my sketch, but am unable to compile my sketch and being a noob its all going over my head. My code is below.

void setup()

{
// put your setup code here, to run once:
// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling.

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <ESP8266WiFi.h>
#include <CayenneMQTTESP8266.h>
#include <CayenneTemperature.h>

// WiFi network info.
char ssid = “TEST”;
char wifiPassword = “TEST”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username = “";
char password[] = "
";
char clientID[] = "
***************************”;

unsigned long lastMillis = 0;

Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop() {
// put your main code here, to run repeatedly:
/*
Cayenne Thermistor Example
This sketch shows how to send temperature data to a Thermistor Sensor in the Cayenne Dashboard.
The Cayenne Library is required to run this sketch. If you have not already done so you can install it from the Arduino IDE Library Manager.
Steps:
1. In the Cayenne Dashboard add a new Thermistor widget.
2. Set the widget to Value Display.
3. Select Virtual Pins and a virtual pin number.
4. Set VIRTUAL_PIN to the pin number you selected.
5. Attach a thermistor to an analog pin on your Arduino. Make sure to use an analog pin, not a digital pin.
Schematic:
[Ground] – [10k-resistor] – | – [Thermistor] – [5V]
|
Analog Pin
6. Set the thermistorPin variable to match the pin used to connect the thermistor.
7. Set the token variable to match the Arduino token from the Dashboard.
8. Compile and upload this sketch.
9. Once the Arduino connects to the Dashboard it should automatically update the Thermistor widget with data.
*/

#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include <CayenneTemperature.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token = “AuthenticationToken”;

// Virtual Pin of the Thermistor widget.
#define VIRTUAL_PIN V1

// Analog pin the thermistor is connected to.
const int thermistorPin = 0;

// Resistance of the resistor. Currently set to 10k but this can be set to the measured resistance of your
// resistor for greater accuracy.
const float resistance = 10000;

Thermistor thermistor(thermistorPin, resistance);
}

void setup()
{
Serial.begin(9600);
Cayenne.begin(token);
}

void loop()
{
Cayenne.run();
}

// This function is called when the Cayenne widget requests data for the Virtual Pin.
{
CAYENNE_OUT(VIRTUAL_PIN)
}

// This command writes the temperature in Celsius to the Virtual Pin.
{
Cayenne.celsiusWrite(VIRTUAL_PIN, thermistor.getCelsius());
}

Every time i try to compile i receive the following error.

Arduino: 1.8.5 (Windows Store 1.8.10.0) (Windows 10), Board: “WeMos D1 R2 & mini, 80 MHz, 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200”

In file included from C:\Users\lee\Documents\sketch_jul17c\sketch_jul17c.ino:8:0:

C:\Users\lee\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.4.1\libraries\ESP8266WiFi\src/ESP8266WiFi.h: In function ‘void setup()’:

C:\Users\lee\Documents\ArduinoData\packages\esp8266\hardware\esp8266\2.4.1\libraries\ESP8266WiFi\src/ESP8266WiFi.h:27:8: error: expected unqualified-id before string constant

extern “C” {

    ^

sketch_jul17c:89: error: expected ‘}’ at end of input

}

^

exit status 1
expected ‘}’ at end of input

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

Kind regards

Lee

i have made the changes to your code:

#define CAYENNE_DEBUG
#include <CayenneMQTTESP8266.h>
#include <CayenneTemperature.h>
#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space


// Virtual Pin of the Thermistor widget.
#define VIRTUAL_PIN V1

// Analog pin the thermistor is connected to.
const int thermistorPin = 0;

// Resistance of the resistor. Currently set to 10k but this can be set to the measured resistance of your
// resistor for greater accuracy.
const float resistance = 10000;

Thermistor thermistor(thermistorPin, resistance);
// WiFi network info.
char ssid[] = "TEST";
char wifiPassword[] = "TEST";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";

unsigned long lastMillis = 0;
void setup()
{
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

void loop()
{
  Cayenne.loop();
}


CAYENNE_OUT(VIRTUAL_PIN)
{
  Cayenne.celsiusWrite(VIRTUAL_PIN, thermistor.getCelsius());
}

Thank you @shramik_salgaonkar that’s helped show me where i was going wrong.

And it’s finally got it working, although now i have an issue with the dashboard not displaying the correct temp but i’ll start another post for help with that as i believe its a problem with the resistor and thermistor values.

kind regards

Lee

You can continue here only.

Although I’ve now got data showing up in the dashboard the temp is well out compared to the actual temp in the room.

My basic understanding is that I need to be able to update the thermistor values with the real values of the thermistor I’m using, and that on top of this the D1 mini also has an onboard voltage divider on the a0 pin so will need to be able to take this into account in my final sketch.

Kind regards

Lee

can you try this code.

float ntc(int analogpinNum){

int RawADC = analogRead(analogpinNum);

long Resistance;
double Temp;

// Assuming a 10k Thermistor. Calculation is actually: Resistance = (1024/ADC)
Resistance=((10240000/RawADC) – 10000);

/******************************************************************/
/* Utilizes the Steinhart-Hart Thermistor Equation: */
/* Temperature in Kelvin = 1 / {A + B[ln(R)] + C[ln(R)]^3} */
/* where A = 0.001129148, B = 0.000234125 and C = 8.76741E-08 */
/******************************************************************/
Temp = log(Resistance);
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp – 273.15; // Convert Kelvin to Celsius

// Uncomment this line for the function to return Fahrenheit instead.
//Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert to Fahrenheit

return Temp; // Return the Temperature

}

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

void loop() {

// Read the first line of the request
float sensorValue = ntc(0);
// Match the request

Serial.print("Temperature Celsius:");
Serial.println(sensorValue);

delay(1000);

}

Therrmistor connection:

3.3v ---- 10k thermistor----------10k resistor----GND
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;|;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; A0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

@shramik_salgaonkar thank you for your help so far.

Did you want me to add the code to the sketch you previously gave me, or compile and upload the new code?

Kind regards

Lee

make a new sketch with the above and see if you are getting correct temperature value.

I’ve tried the code, but am unable to compile due to the following error.

Arduino: 1.8.5 (Windows Store 1.8.10.0) (Windows 10), Board: “WeMos D1 R2 & mini, 80 MHz, 4M (1M SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 921600”

sketch_jul17d:9: error: stray ‘\226’ in program

Resistance = ((10240000 / RawADC) – 10000);

^

sketch_jul17d:18: error: stray ‘\226’ in program

Temp = Temp – 273.15; // Convert Kelvin to Celsius

^

C:\Users\lee\AppData\Local\Temp\arduino_modified_sketch_271055\sketch_jul17d.ino: In function ‘float ntc(int)’:

sketch_jul17d:9: error: expected ‘)’ before numeric constant

Resistance = ((10240000 / RawADC) – 10000);

                                   ^

sketch_jul17d:18: error: expected ‘;’ before numeric constant

Temp = Temp – 273.15; // Convert Kelvin to Celsius

             ^

exit status 1
stray ‘\226’ in program

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

kind regards

Lee

try this.

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

void loop() {

// Read the first line of the request
float sensorValue = ntc(0);
// Match the request

Serial.print("Temperature Celsius:");
Serial.println(sensorValue);

delay(1000);

}

float ntc(int analogpinNum){

int RawADC = analogRead(analogpinNum);

long Resistance;
double Temp;

// Assuming a 10k Thermistor. Calculation is actually: Resistance = (1024/ADC)
Resistance=((10240000/RawADC) - 10000);

/******************************************************************/
/* Utilizes the Steinhart-Hart Thermistor Equation: */
/* Temperature in Kelvin = 1 / {A + B[ln(R)] + C[ln(R)]^3} */
/* where A = 0.001129148, B = 0.000234125 and C = 8.76741E-08 */
/******************************************************************/
Temp = log(Resistance);
Temp = 1 / (0.001129148 + (0.000234125 * Temp) + (0.0000000876741 * Temp * Temp * Temp));
Temp = Temp - 273.15; // Convert Kelvin to Celsius

// Uncomment this line for the function to return Fahrenheit instead.
//Temp = (Temp * 9.0)/ 5.0 + 32.0; // Convert to Fahrenheit

return Temp; // Return the Temperature

}

Checking the temp in the console i’m getting a room temp of around -16.95 degrees while the room temp is 25.5 degrees using two known thermometers.

Regards

Lee

have you used the correct value thermistor and resistor?

I’ve just double checked and the resistor that I got out of the 10k packet is in fact a 1k, serves me right for not checking codes.

As I don’t have anymore 10k and will have to order some, i’ll have to come back to the project when they arrive.

sorry for wasting your time and thank you for all your help

Lee

add what ever resistor you have in series to make 10 k :stuck_out_tongue_winking_eye:

I’ve managed to find some 10k +/- 5% resistors and have managed to get within 2.5 degrees on room temp so its looking good.

I’m still waiting for the food probe to arrive but from details online it’s 50k at 25 degrees, so would i just need to use a 50k resistor when it arrives? and am i able to just add in the code you supplied to the first sketch you supplied? to enable me to view the temp from the dashboard.

regards

Lee

can you share the detail of the sensor your are using?

It’s actually a replacement probe for my IKEA fantast thermometer. So details are hard to come by. But I’ve seen several projects using it for a BBQ probe using resistors between 47k and 50k, and reporting good results.

I have managed to find one doc where somebody has recorded resistance against temp, which I’ll link to. Sensor_Fantast.pdf - Google Drive

Regards

Lee