Monday, 3 July 2017

A little DIY, an AHA and a D'Oh!



I got the soldering iron out at the weekend, and what do you know, I managed to fix my LM35 temperature sensor after all.  I used a small bit of Vero stripboard and soldered the outer two legs in place on tracks 1 and 3, with the body laying down almost flat on the board.  Then I got a short bit of bare jumper wire bent at a right angle, and soldered it to the middle track while the upright part was leaning against the base.  The soldering of that upright to the body of the chip was the tricky part as there wasn't much room between the other two pins to manoeuvre the tip of my soldering iron, or for a clumsy blob of solder that might short the pins out. Thankfully, there was just enough exposed bare metal left over from the broken leg for a drop of solder to actually take and make the connection.  A 3 pin section of header pins completed the job - and Wahay!  I have a working sensor again.

My soldering isn't too pretty, but it got the job done.  The only thing I wish I could have done was solder on the underside, so that I could write pinout information on the bare side of the board and have it visible when plugged into the breadboard, but I couldn't figure how to solder the header pins that way.  With hindsight, maybe what I should have done was push the black plastic clip right to the end of the pins, and then feed them through from above for soldering.  After soldering, take the black clip off the top and slide it back on the underside again.





Of course, to test the sensor, I needed a 5V supply on the breadboard, and remember - it appears that the 5V regulator on my MB-102 PSU is blown.  However, the original board that the LM35 was on had its own 5V regulator.  So after my soldering success, I decided to build myself a little regulator board too.  The regulator is an L78L05, and it had a 22µF capacitor across the Vin and GND pins. It seemed a simple little project, and with just two components and 3 header pins, it was actually quicker than repairing the LM35.

To test it all, I connected a 12V battery to the PSU.  The 5V output was actually putting out nearly 9V, so I put that through my new DIY regulator and that gave a nice steady 4.98V.  I connected that to my LM35 and got an output of around 180mV, which went up and down as I breathed on the sensor (it's pretty cold here in Sydney at the moment!), so I was quite happy that my DIY repair appears to have worked.  Note the mV value here - it should have triggered some thought process here - but I missed it... read on.

Later in the evening, I loaded up my Min/Max temperature sketch, and connected the sensor to the Arduino - it certainly seemed to be working, but was giving readings of a balmy 23-24C while I was sitting there feeling my toes going numb.  I tried changing the reference voltage between 5V and 1.1V, and tried running from a battery rather than USB, but each change seemed to be giving me all kinds of different readings.  I checked the datasheet again, and then had one of those blinding flashes of the bleedin' obvious - a real slap on the forehead "d'oh!" moment...

The sensor generates 10mv per degree C, but nowhere does it say that 0V = 0C.  The chip is supposed to have a range starting at -55C... so of course - that must be the 0V point.  This means that even at freezing point, the output pin should be reading 550mV.  I had assumed that 0C would generate 0V and somehow -55C would generate a -ve voltage!  Well it made sense at the time, but looking back - how stupid was I?? (Hah - remember this statement)

So with this new 'understanding', I looked at my calculations and figured that all I needed to do was offset my calculations by the 55 negative degrees (but by subtracting 5.5 from the final answer?)...  Yeah -OK, it was late at night, and the 55 degrees got all muddled with the factor of 10 (mV per degree) in my head, and suddenly, my calculations were coming up with temperatures almost exactly matching the digital thermometer I was using as a reference.


1
2
  // Calculation for analogReference(INTERNAL) at 1.1v at .1C resolution
     float celsius=((1.1 * analogVal * 100.0) / 1024.0) - 5.5;

BUT this was all completely wrong and purely coincidental, and having revisited it yet again this evening, I'm still not convinced I am understanding either the calculations or even operation of the sensor.  A fact I had previously missed entirely is that there is more than one way to wire up the LM35 - in fact there are 14 different wiring examples in the datasheet with pullup resistors, diodes, and all manner of schemes - each of which makes it operate differently and respond to a different range of temperatures.  I have been using the most basic +5V, GND, and signal back to the Arduino.  Apparently, this gives a measured range of 2C to 150C - so there are no 55 degrees of negativity to account for after all.  That means my adjustment of -5.5, while giving me good results, is simply a fudge factor, and there is still an inaccuracy that I need to track down.  However, it does mean that the 180mV I saw while testing my DIY repair out in the garage, makes more sense - it probably would have been around 18C out there.  So knowing the range I have, I now need to know if 2C = 0mv or 20mV...

I think the next stage in my testing is to combine actual voltage readings with the analogVal reading at the Arduino, and manually check the calculations alongside my reference digital thermometer.  Who on earth said that the LM35 was an 'easy to use'?



No comments:

Post a Comment