HELP! Temperature Reading LM35

Hi Guys,

I am currently using a sketch which takes the temp reading from an LM35 on A0 and prints it in the serial monitor in Celsius. Perfect!

I would like to have this data logged in Cayenne however i cannot for the life of me get this to work, if i follow the custom setup or even follow one of the TMP36 setups it gives me a wild readout - 46.00 etc.

Any help with this would be great? Just a simple script to send the info being printed in the serial monitor to cayenne would be perfect! Here is the print out script i am running currently.

Cheers Guys!

int tempPin = 0;

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

void loop() {
float temp = (5.0 * analogRead(tempPin) * 100.0) / 1024;
Serial.print(temp,1);
Serial.println(" degrees C ");
delay(1000);
}

I don’t really see why that wouldn’t work, but lets try this to see if there is any difference.

//int tempPin = 0;

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

void loop() {
  float temp = (5.0 * analogRead(A0) * 100.0) / 1024;
  Serial.print(temp,1);
  Serial.println(" degrees C   ");
  delay(1000);
}
1 Like

Hi Adam the sketch i had is working in the serial monitor,

The problem i am having is getting that data into cayenne? The data comes in but the temperature is way out however the temperature in serial monitor is perfect?

What script do i add to make it upload into cayenne?

Arduino Uno + Ethernet W5100 Sheild

Thanks so much for your help!

What are you using as your sketch right now?

1 Like

I am using the sketch below for the TMP36 i figured this should work for the LM35?
I have tried adding my script in but im not really sure where to add it?

/*
Cayenne TMP36 Example

This sketch shows how to send temperature data to a TMP36 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 TMP36 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 TMP36 to an analog pin on your Arduino. Make sure to use an analog pin, not a digital pin.
   Schematic:
   [Ground] -- [TMP36] -- [5V]
                  |
              Analog Pin
6. Set the tmpPin variable to match the pin used to connect the TMP36.
7. Set the voltage variable to match the voltage used to connect the TMP36.
8. Set the token variable to match the Arduino token from the Dashboard.
9. Compile and upload this sketch.
10. Once the Arduino connects to the Dashboard it should automatically update the TMP36 widget with data.
*/

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

// If you're not using the Ethernet W5100 shield, change this to match your connection type. See Communications examples.
#include <CayenneEthernet.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "TOKEN CODE REMOVED";

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

// Analog pin the TMP36 is connected to.
const int tmpPin = 0;

// Voltage to the TMP36. For 3v3 Arduinos use 3.3.
const float voltage = 5.0; 

TMP36 tmpSensor(tmpPin, voltage);

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, tmpSensor.getCelsius());
	// To send the temperature in Fahrenheit or Kelvin use the corresponding code below.
	//Cayenne.fahrenheitWrite(VIRTUAL_PIN, tmpSensor.getFahrenheit());
	//Cayenne.kelvinWrite(VIRTUAL_PIN, tmpSensor.getKelvin());
}

So Currently i am running the above sketch and i know my LM35 is reading 16 degrees Celsius aprrox and in cayenne i am getting a reading of -33.40 degrees celsius ?

I actually don’t have any LM35’s :open_mouth: I ordered a pack of 10 but they are coming from china so it’ll be a month or so before they get here. Anyway, I can’t really help you out much there, thought I had one here.

Below the line Cayenne.celsiusWrite(VIRTUAL_PIN, tmpSensor.getCelsius()); add:

Serial.print(tmpSensor.getCelsius(),1);
Serial.println(" degrees C   ");

If that doesnt give you the number you are expecting in the serial console you can try commenting out the line Cayenne.celsiusWrite(VIRTUAL_PIN, tmpSensor.getCelsius()); and below it add:

float temp = (5.0 * analogRead(A0) * 100.0) / 1024;
Cayenne.celsiusWrite(VIRTUAL_PIN, temp);
2 Likes

You are a legend! The sketch below works perfectly! Thank You!

*/

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

// If you're not using the Ethernet W5100 shield, change this to match your connection type. See Communications examples.
#include <CayenneEthernet.h>

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "Add Token";

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

// Analog pin the TMP36 is connected to.
const int tmpPin = 0;

// Voltage to the TMP36. For 3v3 Arduinos use 3.3.
const float voltage = 5.0; 

TMP36 tmpSensor(tmpPin, voltage);

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

void loop()
{
    float temp = (5.0 * analogRead(tmpPin) * 100.0) / 1023;
  Serial.print(temp,1);
  Serial.println(" degrees C   ");
  delay(1000);
  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, tmpSensor.getCelsius());
 float temp = (5.0 * analogRead(A0) * 100.0) / 1023;
Cayenne.celsiusWrite(VIRTUAL_PIN, temp);
  // To send the temperature in Fahrenheit or Kelvin use the corresponding code below.
  //Cayenne.fahrenheitWrite(VIRTUAL_PIN, tmpSensor.getFahrenheit());
  //Cayenne.kelvinWrite(VIRTUAL_PIN, tmpSensor.getKelvin());

Its work Great but on when it trying to refresh its display in minus values for mili-seconds and then it goes back to display real value with LM35… Did you have any solution for it ?