Hi everyone! I know that there are plenty of tutorials what teach how this little sensor works. I have now watched two days different tutorials and topics, without solutions. Something is still wrong..
I have tried to power that many ways. Arduino own 5V, Stable 5V (from 9V step down to 5V). I have tried many scripts but all my temperatures have been between 100-500 degree. (Should be 24)
I check the datasheet may times that the wiring is ok + I have tried four different sensor and all of them gives just random values
So do you have any idea where I can continue the troubleshooting?
Current setup:
9V battery -> Stepdown 5V
Arduino nano get the power from battery + USB
Short wiring in breadboard.
Voltmeter shows:
9V battery -> 8.70V
After Stepdown -> 5V
+Vs + GND -> 4.997V
GND + Vout -> 0.034V to 0.108V (I think this should be 0.25V? but it's not..?(And even I make it cooler or warmer I don't see any logic how the voltage should change))
When I connect LM35 to analoguepin0 and run ReadAnalogVoltage script. I will got results 2.09V to 1.18V or AnalogRedSerial gives values 181 to 453. There is no sense how it jumps.
What causes this? Power source gives stable 5V to Arduino and LM35, but still somehow the voltage jumps?
The last code what I have used is from Adafruit
//TMP36 Pin Variables
int sensorPin = 0; //the analog pin the TMP36's Vout (sense) pin is connected to
//the resolution is 10 mV / degree centigrade with a
//500 mV offset to allow for negative temperatures
/*
* setup() - this function runs once when you turn your Arduino on
* We initialize the serial connection with the computer
*/
void setup()
{
Serial.begin(9600); //Start the serial connection with the computer
//to view the result open the serial monitor
}
void loop() // run over and over again
{
//getting the voltage reading from the temperature sensor
int reading = analogRead(sensorPin);
// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = reading * 5.0;
voltage /= 1024.0;
// print out the voltage
Serial.print(voltage); Serial.println(" volts");
// now print out the temperature
float temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
//to degrees ((voltage - 500mV) times 100)
Serial.print(temperatureC); Serial.println(" degrees C");
// now convert to Fahrenheit
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
Serial.print(temperatureF); Serial.println(" degrees F");
delay(1000); //waiting a second
}
I attached two pictures from different setups, none of those are working..
Thank you for you time if you have any clue where I should continue troubleshooting
I'm not sure of your setup, but those LM temp sensors have always been VERY unstable for me. If you look online, you'll see a lot of suggestions to filter the input power with capacitors. I've followed that advice that with only minimal success. I've usually just ended up reporting the running average.
You use an LM35, but you post a sketch for a TMP36.
This sketch should work for an LM35.
Leo..
// LM35 temp sensor connected to analogue input A0, +5volt and ground
unsigned int total; // A/D readings
float tempC; // Celcius
float tempF; // Fahrenheit
void setup() {
analogReference(INTERNAL); // use the internal ~1.1volt Aref | change to (INTERNAL1V1) for a Mega
Serial.begin(9600);
}
void loop() {
total = 0; // reset total
for (int x = 0; x < 64; x++) { // 64(max) analogue readings for averaging
total = total + analogRead(A0); // add each value
}
tempC = total * 0.001632; // Calibrate by changing the last digit(s)
tempF = tempC * 1.8 + 32; // Celcius to Fahrenheit
Serial.print("The temperature is ");
Serial.print(tempC, 1); // one decimal place
Serial.print(" Celcius ");
Serial.print(tempF, 1); // one decimal place
Serial.println(" Fahrenheit");
delay(1000); // use a non-blocking delay when combined with other code
}
Here's an LM35 + Nano sketch I wrote, with smoothing, the LM35 is "naked", no caps or resistors. I include a monitor copy showing the output at 1 second interval, you can see where I put my finger on it for a few seconds.
Columns are: raw ADC, sum of 8 samples, temp C, temp F.
/*
LM35 thermometer, no floats, no delays
http://www.ti.com/lit/gpn/lm35
*/
const byte sampleBin = 8, // number of samples for smoothing
aInPin = A0;
const int fudge = 170; // adjust for calibration
const int kAref = 1090, // analog ref voltage * 1000
kSampleBin = sampleBin * 1000,
tEnd = 2000; // update time in mS
int tempC,
tempF;
uint32_t total, // sum of samples
tStart; // timer start
void setup()
{
Serial.begin(9600);
analogReference(INTERNAL); // use 1.1V internal ref
analogRead(aInPin);
for(int i = 0;i < sampleBin;i++) // for smoothing, fill total
total += analogRead(aInPin); // with sampleBin * current
// reading
}
void loop()
{
if(millis() - tStart > tEnd)
{
tStart = millis(); // reset timer
total -= (total / sampleBin); // make room for new reading
total += analogRead(aInPin); // add new reading
tempC = total * kAref / (kSampleBin + fudge);
tempF = (tempC * 18 + 3200) / 10;
Serial.print(analogRead(aInPin));
Serial.print("\t");
Serial.print(total); // sum of samples
Serial.print("\t");
prntTemp(tempC);
prntTemp(tempF);
Serial.println();
}
}
void prntTemp(int temp){
Serial.print(temp / 10); // whole degrees
Serial.print(".");
Serial.print(temp % 10); // tenths
Serial.print("\t");
}