allanhurst:
Could you check using serialWrite what the a/d is actually reading?
regards
Allan
I've used the EasyTransfer library to send the number read from the analog pin that the LM35 is feeding into and transferring that back to an Arduino Mega via Serial1 and then sending that to the Serial port to show on the Serial Monitor. Both the standalone Arduino on breadboard and the Arduino Mega are using a common ground. The standalone Arduino is setup the same as here:
Reading the value coming from the LM35 when directly connected to the Arduino I get a values in the range:
231 - 232
constantly. If I then report back the 'total' variable I get ~14690, which equates to a temperature of ~24C.
But when sending the value back to the Arduino Mega from the standalone, I get values in the range:
11 - 36
which then gives me a value for 'total' ~2619, which equates to a temperature of ~4.2C. Hence why the LED was showing 4 and not the expected temperature reading of ~24C
If I put a multimeter reading on the +ve and -ve rails of the breadboard near to the LM35 the voltage is 4.50V running off of a 9V battery through a 7805 voltage regulator. If I use a 9V bench supply still going through the 7805, I get a reading of 4.56V steady, and the value of 'total' is ~2950 i.e. 4.8C!!
If I use the Arduino Mega to connect the wires from the resistors for the LEDs and the wire from the LM35 to A5 and supply power as well, I then get the reading for 'total' of ~15460, a temperature of 25C (it's warmed up a bit while I've been doing this). The voltage reading on the multimeter is showing 4.90V
But if you read 231 with the a/d the voltage is 231/1023 * 1.1 ie ~ 0.248 volt
which is about 24.8 C given the LM35's 10mV/C
(0.248 / 0.01) or 0.248 * 100
Ie fine.
What on earth are do doing with 'total' to get these strange values? just take the a/d value , use floats to do the sums as above, then display the (int) of your answer.....
or if you want to stick with integers, make all the variables longs and do it thus..
temp = 110*(adval)/1023
note if you use ints you'll get overflow in the above at higher temps.. - they're only 16 bit. Longs are 32 bit - plenty.
regards
Allan
ps
all this fiddling about with supply changes shouldn't make any difference -the internal 1.1v bandgap reference is very stable, though may not be exactly 1.1v. Measure it and insert value as appropriate if you want very accurate results.
allanhurst:
Sorry - haven't read your code in detail...
But if you read 231 with the a/d the voltage is 231/1023 * 1.1 ie ~ 0.248 volt
which is about 24.8 C given the LM35's 10mV/C
(0.248 / 0.01) or 0.248 * 100
Ie fine.
What on earth are do doing with 'total' to get these strange values? just take the a/d value , use floats to do the sums as above, then display the (int) of your answer.....
or if you want to stick with integers, make all the variables longs and do it thus..
temp = 110*(adval)/1023
note if you use ints you'll get overflow in the above at higher temps.. - they're only 16 bit. Longs are 32 bit - plenty.
regards
Allan
This is the code that reads the data and calculates the temperature:
void readTemp(float& tempC, float& tempF)
{
unsigned total(0);
for (int n = 0; n < 64; ++n) // 64(max) analogue readings for averaging
{
total += analogRead(A5);
}
/*
mydata.number = total;
ET.sendData();
*/
Serial.println(total);
tempC = total * 0.001632; // Calibrate by slightly changing 0.0016xx
tempF = tempC * 1.8 + 32; // Celcius to Fahrenheit
}
The 231 reading is the value I get when running on an Arduino, which computes the right temperature. But when I run standalone I get 11-36, hence the single digit being displayed on the LED!
Yes, I did see that post. But without averaging the readings and just use one reading, see my post#45. When I use the Arduino I get a reading of 231 which equates to 24.88C and then if I use the standalone I get a reading of 11. I think there's a problem with the voltage!
I think the problem I have with the standalone is that I have the ARef pin connected to 5V, and I'm now thinking that connecting the ARef pin to GND via a 100nF decoupling capacitor will probably help. I'll try this later this evening.
Ah! if you connect Areg to +5 it'll have 5v on it whatever you select in code.... and your measurements will be 1.1/5 times low. Hope you haven't blown up your bandgap reference....
Well I've connected a 100nF capacitor between ARef and GND on Atmega328P on breadboard. The RX and TX wires are going from the standalone Arduino on a breadboard to the Arduino Mega pin#19 and pin#18 respectively. They are sending the value of 'total' across:
void readTemp(float& tempC, float& tempF)
{
unsigned total(0);
for (int n = 0; n < 64; ++n) // 64(max) analogue readings for averaging
{
total += analogRead(A5);
}
mydata.number = total;
ET.sendData();
tempC = total * 0.001632; // Calibrate by slightly changing 0.0016xx
tempF = tempC * 1.8 + 32; // Celcius to Fahrenheit
}
The reading for that is ~6670, and the LED is showing ~10. The multimeter is showing a circuit voltage of 4.70V, and the OUT pin of the LM35 is showing a voltage of 0.202V.
If I use the formula:
tempC = total * 0.015625;
I get a temperature reading of 104.22. Clearly something is still wrong????
The difference between with and without the 100n is interesting. Shouldn't make any difference
unless there's loads of noise, in which case the 'without' readings would jump about a lot. - even so a good idea.
Your post #51 .. 0.202v with 1.1v ref should give an a/d reading of about 188 and hence a temperature of 20.2C
the averaging stuff....
64 x 188 = 12032 ( where did your 6670 come from? ). implies 188 ave and hence a voltage 188/1023 * 1.1 => 0.202 v => 20.2C
Can you measure the Aref volts with a meter? near the nominal 1.1v? decoupling that with 100n would do no harm
what ambient temperature was it when you did these tests?
#53....
series 1 implies around 12C, series 3 around 7C. A long way from the 20.2C the 0.202 volts implies. So the a/d is telling you lies. As I suggested earlier, you may have damaged the 1.1v ref by putting 5v onto it.
chuck away your averaging bit and try displaying the answers directly - they seem pretty stable anyway.
if ok then you know what to play with.
And it may be worth putting a small delay between a/d readings to allow settling.
Here's a progress update. I got some ATmega328PU chips and the results were the same. I recently bought some Arduino Pro Mini clones, and they work a treat. My LED is now showing the correct temperature. The Pro Mini is really small so will be able to produce a PCB that I can connect that to as well as the LED, and the rest of the parts.
Thank you to everyone especially Allan for all the help on this little project. Frustrating and equally annoyed that I couldn't get this to work with a standalone ATmega328P or even a 168P!!
Wawa:
Not on my calculator.
I think you didn't calculate that the A/D gives a value that is about 10x the temp.
Leo..
It's because we're taking 64 readings and then averaging the total readings hence the above line. If fact this code was taken from your reply at msg#16 on 24/Oct/2016.
Hi,
Can you pull the display circuity out in your stand alone, just have atmega chip and lm35, what does the serial output say your raw analog data is?
Have you got bypassing on the stand alone PCB, 0.1uF and 10uF on the 5V lines?