Monday, July 1, 2013

quick and dirty way wiring a K type thermocouple with LM358 op amp to replace LM35 on an Arduino

Personally, I prefer to use LM35 as my temperature sensor instead of anything else. The reason is simple, it is bountifully available in our tech arsenal (just a mouse click and I can collect it from block T8), it is very simple to use with no extra circuitry, precision at +- 0.5degC within 0degC to 100degC, and literary it is plug and play with arduino. check out my previous post  on getting started with LM35 and arduino. I am using this sensor for my arduino sousvide setup. After 6 months of abuse, it broke down, the waterproof temperature probe gave way, and water breached in it causing a short circuit. Shown below is my wiring for LM35; the optional 10K Resistor is there to suppress wiring capacitance that came with very long cables.

so my next course of resolution would be to get my hands on spare LM35, and also another method to water proof it. Little did I realise, a small little piece of LM35 is retailing at £1.99 per piece!  To add salt to the wound, a pathetically sized 6cm x 4cm veroboard (stripboard) cost me £1.69 after 50% discount. The price gave me a real shock in my life. I always assumed that ICs are dirt cheap. The other possible explanation is that I have been living in the tech tower with a wide variety of ICs, PCBs, EE components at my disposable to make projects, losing touch with the reality. Arghhhh, how i miss my staffs at the procurement office. Not because of the complicated purchasing process I constantly bang into, but their effort to make sure we are well stocked.

After much googling around and also posting messages on my facebook to BBS (beg borrow steal). I came across websites such as TI are giving samples for free. Since I am staying across the pond and have an expensive looking email address, I can get my hands on 3 type of ICs with 3 samples of each in an order for free, and with shipping included too. As a backup plan, I also ordered a some ICs to complement my K type thermocouple that I have ordered earlier on amazon for £2.93 with free shipping.

The plan is simple. Solder a LM35, stick it into a brass radiator key I have idling around, and seal it with sugru. Sugru is going for £8 per packet of 5 mini sachets. I only needed one. My prior experience  with sugru is a wasteful one. It has an expiry date that will be cured (harden) by than no matter what. Nonetheless, it is a good material to fix stuff. I posted a message on facebook group seeking partners to share the cost of materials; a kind soul from institute of making gave me 2 mini sachets for free!

Always test your equipment/stuff before sealing/cast in sugru or committing more materials on top of the equipment. In my case, i tested this waterproofed LM35 on my arduino before cooking an expensive piece of dry age beef. To my amusement, the temperature reading is fluctuating wildly. This is really bad signal to be the input for the PID control algorithm. It makes the tracking to the set point difficult and unreliable. To make the matter worst, the sealing of the edges on the brass radiator key with sugru did not went well as expected. When it is submerged in the water bath, I saw some air bubbles emerging from the thermo probe.

There can be a myriad of ways on what went wrong. leaky probe, faulty LM35, wiring capacitance that affects the reading, faulty pin on arduino etc etc. Thus, the great troubleshooting begins! I started off plug and play with another LM35 I soldered, but used a plastic bag instead for water proofing. Still the same old wildly fluctuating reading. After much troubleshooting and have exhausted all possible options, I tested the last piece of LM35 before solder and after solder. Ah-ha.... found the culprit. The solder iron is too hot for soldering ICs, and I have put it in contact with LM35 for too long a second.

Having busted 2 out of 3 of my LM35 and lost the 3rd in translation, I am back to my K type thermocouple. One reason that make me don't really like to use K type for my sousvide setup, is because it's temperature range is very wide, it is ranging from -260degC to 1400degC (manufacturer dependent). Divide the temperature range with 5v and than you will get what I mean. Reasons not listed exhaustively for my dislike include the requirement of a cold point compensation circuit for precision; signal output is in the range of milivolts per degC; it need an amplifier circuit to work, and can't connect directly to arduino; the amplification is not exactly linear for a cheapo amplifier which makes the code complicated to work with the circuitry; adafruit Thermocouple Amplifier MAX31855 breakout board going to cost me £16.80 from a UK dealer; and the list goes on.

Having said that, a very simple op-amp with a gain in the range of 100 would easily fit the bill for my setup with K type thermocouple. I just need to figure out the output voltage in milivolts of my k type thermocouple would output at the desired temperature for cooking, amplify it and normalized it to the temperature in degC. The first step is a re-visit to the data sheet of a LM358 IC, something I have not done for some time. To be frank, these ICs data sheets are not written for the layman in mind. Reading the data sheet not knowing what you need or a how to get things done will surely put off many people and abandon the project (not as if their livelihood depends on it). Scrutinizing the data sheet in detail, I just wonder why it does not include the classic text book example of a N-gain amplifier. I forsee that layman looking for something quick and fast through the data sheet will be disapointed and will spent hours trawling the internet for usable bits of info. How many will give up half way or abandon their project in due course of looking up for information?

The quick and dirty way of wiring of LM358 is at the self explanatory figure below, drawn by hand from yours truly.

B-side of the £1.69 veroboard. I still remember what was taught in my digital electronics class many years back. The hint is in the picture below.

Putting everything together for action. no smoke, no sparks. phewwww

I noticed the reading of the k type thermo couple from the LCD with comparison to my trusty digital thermometer. The final temperature read by K type thermocouple with LM358 is always biased at about 9 to 10 degC. This render the previous code useless. Nonetheless, it is easy to fix.

The only modification to the source code, from the code meant for
LM35-> temperature = (5.0*val*100/1024);
 is modified to
LM358-> temperature = (val+9.5);

ARGHHHHH.... can you smell what the ROXXX is cooking?!


Sk8tz Dude said...

Trust an engineer to do things the "difficult" (but interesting?) way...

Others will just buy a crockpot or cooker... lol

Michael Skřepský said...

I used this for two cheap bead K thermocouples on my DIY IR reflow machine. I needed some adjustments of base value and multiplier in the sketch with help of boiling water, body temperature, adjustable soldering iron and IR thermometer. After that it works flawlessly with enough accuracy.

Those amp&compensation chips are 10x expensive as those cheap multimeter thermocouples and have similar cost as my entire arduino controller including 20x4 LCD and two triacs, so i would never buy that.

Unknown said...

The thermocouple temperature sensor listed here are but a small sample of the possible specifications that can be produced and all prices are based on a minimum quantity of 4.