Hi guys,
I’ve been trying to replicate a pretty easy arduino project with the photon. I’m trying to collect the room temperature and the outside temperature with two LM335 GE, the problem is that the temperature values are not correct or close to what reality is. So I’ve tried numerous codes but they are still incorrect.
I’m using de 3.3V pin of the photon to power up the LM335 GE
this are my readings
Reading from sensor #2 = 3085(without any formula)
Reading from sensor #1 = 3072(without any formula)
Reading from sensor #1 = 0( multiplying sensor read * 3.3 / 4096)
#include <math.h>
int V = 3300 / 4096;
int s0 = 0;
int s1 = 0;
int s2 = 0;
void loop()
{
s0 = analogRead(A0);
s1=analogRead(A0) * V;
s2=analogRead(A1);
}
when using an external 5V power supply
with the sam code :
Reading from sensor #2 = 4095(without any formula)
Reading from sensor #1 = 4095(without any formula)
Reading from sensor #1 = 0( multiplying sensor read * 3.3 / 4096)
chaning 3300 for 5000 as the external power supply is 5V
#include <math.h>
int V = 5000 / 4096;
int s0 = 0;
int s1 = 0;
int s2 = 0;
void loop()
{
s0 = analogRead(A0);
s1=analogRead(A0) * V;
s2=analogRead(A1);
}
Reading from sensor #2 = 4095(without any formula)
Reading from sensor #1 = 4095(without any formula)
Reading from sensor #1 = 4095( multiplying sensor read * 5000 / 4096)
When using the 3.3V PIN and changing slightly the code instead of multiplying s1 * V, multiply it like this: s1*0.8056640625
Reading from sensor #1 = 3083 (without any formula)
Reading from sensor #1 = 2481( multiplying sensor read * 3300 / 4096)
Hope I explain it as clear as possible.
Thank you for your help.
I suspect your incorrect use of integer math is at play here. You define int V = .805; ( I did the math of 3300/4096 to illustrate the point). But an int can never be that small of a decimal. You should probably define float V = float(3300) / 4096;
#include <math.h>
float V = 0.8056640625;
int s0 = 0;
int s1 = 0;
int s2 = 0;
void loop()
{
s0 = analogRead(A0);
s1=analogRead(A0) * V;
s2=analogRead(A1);
}
But anyway, the output is still incorrect.
Reading from sensor #1 = 3096 (without any formula, just the analog reading)
Reading from sensor #1 = 2489( multiplying sensor read * 0.8056640625)
Thanks, for the fast reply.
I thought “3096” was the voltage I was measuring(the reading straight from the pin without any calculation).
I took the readings from s0, multiply it by 0.8056640625(all of these is s1)
gave me s1 = 3090
divide s1 by 10, to show kelvin, and then -273 to show celsius and it shows -25ºC.
I have not calibrated the circuit as in right now I don`t have a thermometer and comparing it to my phones weather app.
I’m connecting the pin 2 to the A0 and A1 from the sensor one and two respectively.
Not using any resistors.
Using simple maths operators you don’t need to include <maths.h>.
You are mixing integers and floating point numbers.
Int a1 = analogRead(A0);
a1 is a whole number between 0-4095
To get a voltage as a floating point number I would do this:
Float v1 = (float) a1 * 3.3/4095;
v1 is now the voltage measured on pin A0 between 0.0 and 3.3
How you get this voltage to a temperature in degrees C is dependent upon the constants. Please bear in mind not to mix integer and float types when performing maths.
I don't think this is how the sensor is supposed to be used.
The way how I understand this sensor works is via the break-through voltage of a Zener diode which is directly proportional to the ambient temperature.
So you would supply a voltage higher than the break-through (at your maximum readable temperatiure) and then measure how much voltage it took. But once the Zener is open you virtually got a short-circuit condition for the "excess" voltage and for that you should add a current limiting resistor.
This will also counteract self-heating of the sensor due to excess current passing through.
BWT, while the LM335 is rated for a temperature range -50°C..+100°C with 3.3V you will only be able to measure -50°C..~+50°C because any higher than that you won't get a Zener break-through.