Unable to get the Temperature Sensor values

I have write code for Temperature sensor to read and display the temperature values. Th code is complied and splashed correctly but does not show the values in Event log.

Can anybody what i am doing wrong ?

Thanks

naveed

You need to post your code - our crystal ball :crystal_ball: has used up all its magic power for this year

BTW, I guess you code was flashed to the device rather than splashed (to prevent water damage) :wink:

4 Likes

thanks for your prompt response. the following is my code which i am running on redbear Duo on breadboard

int tempPin = A0;

double temprature=0.0;
double tempratureF=0.0;

void setup() 
{
    Particle.variable("temprature", &temprature, DOUBLE);
    Particle.variable("tempratureF", &tempratureF, DOUBLE);
   
    pinMode(tempPin, INPUT);
}


void loop()
{
 
 double voltage= (reading * 3.3)/4095.0; 
 
 temprature = (voltage - 0.5) * 100;//waiting a second

tempratureF = ((temprature * 9.0)/ 5.0) +32;

Particle.publish("temprature", String(temprature) + "'C");
Particle.publish("temprature", String(tempratureF) + "'F");
delay(2000);
}

It compile and splash without any error but when i check the event log it gives data given in the above picture.

thanks

@naveed, you are violating the 1-per-second Particle.publish() rule. You can combine both temperature values into a single publish or simply read the variables via the Console.

1 Like

Hmm, where does reading come from?
I doubt this really compiles without error.
If you are using analogRead(tempPin) to acquire your reading then you should not use pinMode(tempPin, INPUT) - analogRead() sets its own pinMode() internally.

Also try using the modern syntax

    Particle.variable("temprature", temprature);
    Particle.variable("tempratureF", tempratureF);

I’m not sure if this really violates the limit as it adheres to the burst rate of 4 events over 4 seconds, but I’d still combine the readings into one event and publish even less frequently (e.g. 1 per 30sec).

3 Likes

@peekay, Thanks very much for your reply. yes i will try to read it from console.

@ScruffR , Thanks for reply. I made the changes as suggested but the result are still the same.

As already replied via PM - you haven’t really applied the suggestions as they were provided, so it’s not surprising that nothing really changed.

Post your current code, so we can see what you actually changed :wink:

2 Likes