### You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Project Help and Ideas » Temperature sensor project.. of course

 December 28, 2009 by jgauthier Greetings, I completed all the tutorials, and some extras. I went back to the temperature sensor because I'd like to understand it a little more in depth. When i first set it up, I was using the 9V battery, and a I noticed the temperature was 8-10 degrees high. I read this is because of a 5v calculate voltage and accepted it was my battery. Since then, I've moved directly to USB. I've got fairly constant power, but still receiving high readings. If I read the input side of the LM34, I am showing about 6.6v. I also read that the output should read about 10mv per degrees. My house should be around 66-67F right now, but I am having trouble reading the output. Using my multimeter, I've put the setting on DCV, and then selected 200m. It just stays at zero. Then, i've moved it to DCmA. Then i've selected 200,20, and 2. All stay at 0. Is my multimeter not precise enough to read this? AND... Can i read the voltage from the ADC? Thank you, PIN2 on your LM34 will measure at 660mV for 66F. 74.5F = 745mV on PIN 2... and so on. It is 10mV/F on the datasheet-- so your setting of 200mV on your meter is too small. ALWAYS set your meter at the largest setting possible and then switch down. In this case it's USB at 5V - but what if it's actually more (like 6.6V)??? You risk frying some things, including your chip AND your meter. Before connecting anything, you should check your rail to rail voltage- to be sure the USB is delivering no more than 5V. So set your meter to 10VDC and THEN check it: Use your VM to see what voltage is dropped across it, when connecting positive lead to + RAIL and negative lead to - RAIL- this will tell you what your reference voltage is. Your ADC will skew the results accordingly, unless you update your tempsensor code to adjust for that calculation. For example, if your reference voltage is actually 4.98V, then instead of 5000mV in your calculation, it must be 4980 in order to map the LM34 output ot the 1024 division resolution of the ADC accurately. To check the LM34, you can connect your positive lead on your meter to PIN2 on the LM34 and the negative lead to GROUND to see how much it is dropping across your meter. Your ADC is input only in your current configuration-- it does not generate a voltage. Okay, thanks. That helped. I measured my USB, and it's not steady at all. Anywhere from 5.9-6.7v. Should I regulate? Also, with the USB plugged in (serial pins too), and the main switch to the board turned off, my rails are running at 3v. I traced this back to the yellow pin on the USB cable. I thought this was a passive communication? It actually has 4v on it. When I plug it in it's definitely causing noise, or an issue. It seems that pin two fluctuates based on that being plugged in. It went as high as 1.00 (but the LCD was reading 73 degrees). It's currently reading at .9, which would be 90, and the temperature is reading 74. (ADC: 152) So, my understanding has increased,but something is still going on. My question about the ADC was not if I can generate voltage, but if I could read it. For instance, to get accurate readings, I need to know the reference voltage. Since the LM34 just sends voltage into the MCU and reads that, could I also (i feel the answer is "no") throw a line to the +RAIL and use the ADC to get the reference voltage? Some things from what I've read aren't adding up. if my voltage is high, my temperature should be low. But it's not.. it's too high. Thanks for your help. Understanding "why" is what drives my learning.. :) Thanks! Hi-- let me add a little more, that will help you understand a bit more. VOLTAGE. This is NOT sent anywhere. It does not exist within your circuit. Nor is it a driving or pushing force. This is a major misconception by most students of electronics-- because it is mistaught. Voltage exists ONLY between the terminals of your power-supply. Period. Voltage is an attraction based on a process that separates (whether by chemical or electrical or other means) the most weakly bonded electrons from their home atoms-- and keeps them apart. The level of attraction (what you know as voltage) is the ATTRACTIVE force at the positive terminal-- the free electrons will find their way back to their home atom (any atom that is missing its free electrons) by means of traveling through your circuit pathways to the positive terminal. As such-- voltage CANNOT be measured directly at any point in your circuit. In fact, you cannot measure voltage directly ANYWHERE. The best you can do, is place something between the terminals (like your meter) and measure how much voltage is LOST or "dropped" across that bridge. Furthermore, you can only measure a VOLTAGE DROP between two points of opposing polarity (your meter's leads for example, or on either side of a component, like a resistor or LED). To look at this last statement another way, consider this: Putting your meter across the positive and negative rail puts it in series with the power-supply. Your meter presents an extremely high resistance (mega ohms, in fact) - the purpose being to limit the amount of current that flows through the meter so it doesn't fry it, while allowing just enough current to flow so that it can calculate the drop. If you put your meter across a resistor, you are still putting your meter across the terminals of the power-supply-- but in parallel with the resistor. Because your meter presents so much resistance, virtually all the attractive force is dropped/lost because it can't hardly pull any current through your meter. Your meter measures that loss, which ideally due to the high resistance, should be close enough to the maximum attraction on the circuit at that point, for all intents and purposes. I realize that is a lot to take in, and it flies in the face of most of what you hear-- but that is because most of what you've been told regarding voltage and current is incorrect. I go into detail on it, because I want you to be able to truly understand it, and change the way you communicate about it and think about it. If you talk about it correctly (saying voltage "across" and not "at"), you reinforce to your mind how it actually behaves which leads to greater understanding of how your circuit actually "WORKS" and what's going wrong, if it doesn't. Current is a physical thing-- it IS the electrons in motion-- drawn by the attractive force at the positive terminal. Voltage won't do a thing to you-- current can kill you (where you're dealing with larger currents, capacities, and voltages). Okay, now that you have a little better understanding of voltage and current, let's talk about some of your questions: If your input power is more than 5V, then YES, you should be regulating it. Some components (even parts of your ATMEGA168) cannot handle more than about 6 volts (see the datasheet) and more than that means too much current will force its way through portions of the chip-- it will get hot (or those portions will) and eventually they will break down and short-- because the current WILL get through. With your USB connection, there may be an issue whereby you are not seeing a steady DC voltage-- it may be fluctuation because USB is a serial protocol-- as such it is going to be raising and lowering the voltage at extremely fast rates. Your meter can't register that accurately-- you need an oscilloscope. .9 is 900mV (remember 1 milivolt is .001 If your rail voltage-- which is where your ADC pulls ADCRef from-- is not steady, neither the LM34 nor the ATMEGA168 can provide a stable, reliable answer-- again, you probably want to go regulated. If you use regulated, the 7805 requires the input voltage to be 2 to 2.5 volts HIGHER than the output voltage of 5V. PIN 2 on the LM34 will fluctuate based on any changes on your +5 rail. Plus your calculation in software (the 5000/1024 part of the equation) will ALSO be incorrect because the 5000 is an assumed value representing 5V. In truth, that value should be read off the ADCRef PIN, so that the software calculation automatically stays in sync with the LM34. I have not looked to see if you can pull the mV value off the ADCRef pin-- you might have to use another PIN elsewhere to obtain this, but atleast you now know the method you would use to make the software stay calibrated with the LM34. You need to resolve the fluctuating voltage issue first. Thanks for your lengthy response. It makes sense -- alot. I realized in my green-ness I am definitely referring to things very casually, which if I was more experienced would not make sense. (the LM34 "sending" voltage) Noted! Very bad terminology there. I apologize, but I am thankful for your guidance. I also did not realize that was how a multimeter functioned. That is great understanding. I'm going to head over to mouser/digikey and see if I can find a regulator for my range. Otherwise, I will use a wall wart and continue to use the bundled regulator. It seems I am chasing a rather trivial problem. but I'm not searching for a solution as much as I am seeking a solid understanding. So thanks! I certainly didn't want to visit here again so quickly. I have been reading up on regulators and how to accomplish this. i'm concerned firstly that my USB should not be putting out 6.7v. Secondly, I haven't been able to find a regulator that can regulate down to 5v anything that is not 7 or 8. There might be some math here that makes perfect sense to someone. (Maybe forward voltage difference) well, well, well. I think I have discovered my "problem". I've been thinking all day about how to get alternate power sources since my USB was had 6.7v across it. I tried another USB port... same thing. I tried a USB wall charger. Same thing! My brain is very confused. I've read that wall devices are not guaranteed. But this wasn't the same thing. I tested a 5v line from my PC's power supply. I was also ready about 7v across it. Finally I disassembled an old "9v wall wart". I put it in an isolate part of my bread board attached to the 7805. Guess what? 6.7v! Now, I realized what i've been chasing. This is no coincedence. I changed the battery in my multimeter... and now my 5v are 5v. wow! This has had me quite intrigued. Thanks for all the pointers. Back to USB power, and back to determining how to get the temperature sensor more accurate! CONGRATULATIONS! It's easy to forget our tools can also mislead us-- good thinking! Go back to the part I told you, about how to measure the voltage off of PIN 2 on the LM34. This will give you the reading from the sensor, irrespective of your ATMEGA168, so you know what the sensor is providing to the MCU. Knowing that value, will let you track down what else might be going on (if anything). For example, if you get a 745mV reading-- that means the LM34 says it's 74.5F. And that is exactly what I can read from it. The voltage off PIN2 is reading in relation to how the math of the temperature reads. The voltage/temperature is still wrong.. but I'm not sure I want to fight that battle. It's still several degrees high. I wonder if it's noise. I considered getting a digital one. (DS18B20 -- http://www.mouser.com/Search/Refine.aspx?Keyword=DS18B20) But again, not sure I want to fight that battle =) December 29, 2009 by BobaMosfet "In truth, that value should be read off the ADCRef PIN, so that the software calculation automatically stays in sync with the LM34. I have not looked to see if you can pull the mV value off the ADCRef pin-- you might have to use another PIN elsewhere to obtain this, but atleast you now know the method you would use to make the software stay calibrated with the LM34." `````` How would the microcontroller look at that ADCRef PIN except thru the adc itself? It would always get a full reading. `````` mj ese, Sorry, I've been trying to get back to this thread to answer your entry, but couldn't find it until now. You can monitor the ADCRef pin with another pin by creating your own ADC and comparator circuit to do the AtoD conversion of the ADCRef pin. Flip-Flops, Gates and Op-Amps in combination may be used. I didn't say it would be simple :P BM Hi all, Just wanted to point out that there is something called a "bandgap voltage reference" which measures some semiconductor properties to generate a "stable" reading around ~1.2 volts or so. This is a ~40 year old technique to generate a stable voltage reference (fairly stable over both input voltage and temperature), and there's one of these in your 7805, for example. The 7805 uses a bandgap voltage reference to generate an internal ~1.2V reference, and then uses a precise voltage divider ratio on its own 5V output. It basically has a voltage divider with a fraction of 1.2 / 5.0, and compares that to the bandgap, and does feedback around that comparison. But the ATmega168 also has a built-in bandgap reference source. You can use this in one of two ways: 1) you could use it as the analog reference AREF if you have no intention of measuring input voltages greater than about a volt. See Table 23-2 on page 256 of the ATmega168 datasheet. 2) you could use it as an input to the ADC, so you could effectively compute what AREF is -- this is a way of measuring your 5V supply. Note that the datasheet calls it ~1.1V, and I've been calling it ~1.2V. Furthermore, Figure 29-36 on page 335 of the ATmega168 datasheet shows it to be even slightly different from that. But most importantly, you should be aware that it's simply a function of the semiconductor properties, so it can vary a bit from batch to batch. You can assume that once you measure it for a given chip, it will stay largely the same forever... but for best accuracy, you should measure it once for that chip with a multimeter that you trust as your "true reference". If you're still curious, here's an article from Bob Pease (a legend in the analog electronics industry) about The Design of Band-gap Reference Circuits. Mike Does any one have a problem with the SPDT switch switching between "program mode" and "run mode"?. For the temp sensor project, everytime I want to rebuild the code I have to unplug and plug the usb to do so. I think it might have something to do with the while(1) loop and main not getting an int 0 in the end. Unplugging the USB every time is "sometimes" normal!! I now have to use a spst switch on the yellow wire, instead of unplugging the usb cable. Currently I am using a MAC mini OS X 10.6. There have been times when I did not have to unplug the usb cable but now I do. This has been for OS X and Windows XP and 7. If you or anyone can come up with the exact settings to avoid unplugging or switching off the usb I sure would appreciate it. Like I have said there had been a time when I did not have to unplug the usb but no longer. I have two serial-usb cables and have to unplug or switch off both. Ralph I started on a LM34, but wasn't happy with small differences in temperature caused by miscalculations of the reference voltage, and the worry of my really long interface cable to the transmitter. Check out DS18B20 - it's a digital temperature transmitter in the same size package! This page describes a simple setup really well; http://www.teslabs.com/openplayer/docs/docs/other/ds18b20_pre1.pdf I love how you can hang multiple devices of the one wire, has CRC detection, and alarm limits. And it's digital. So 20 degrees is 20 degrees (+-0.5); no worrying about your calculation and analog noise. And it will run on any digital I/O pin. BobaMosfet, Your third post in this thread, where you discuss the meaning of voltage, is classic and one that would benefit electronics beginners in general. Thanks for the post. Ralph I have pointed it out before so this is somewhat redundant. I regularly use windows 7 window xp and vista. I never find it necessary to unplug the USB cable. Or use any type of switch in the cable. The USB connections work well in all cases. I stated using optical coupler on the USB cable all the time. Last winter I fried a second USB cable from static discharge when I neglected to ground myself and touched the board. static electic At least now my computers and the USB cable are safe from any mistakes I might make on the boards. Darryl, I just received my opto couplers!! Now I just need the time to build your circuit. I wish there was a PCB instead of having to use a proto board but there again once I get around to learning Eagle and once I get my 3D printer milling machine and learn how to use it I could mill my PCB or of course I could etch it. Hey Darryl would you post your schematic for the USB isolation using the opto couplers in the Nerdkit Community Library and Paul (Noter) you had a isolation circuit using transistors would you post that also? I can not find either circuit at the moment I know I have them somewhere but if they were posted to the library then I could easily find them, that would be great :-) Ralph Ralph I have posted the circuit in the library as you suggested. Darryl Ralph, I don't remember having isolation circuit for a USB connection. Are you thinking of the transistor based RS232 to TTL serial converter I was using for a while after my usb cable died? I couldn't use it now anyway because I'm on a laptop these days and it doesn't have a RS232 port. Thanks Paul for that circuit I think I remember that, but of course could never find it. I thought you had a circuit you put together on one of my "yellow wire" threads to separate the USB using MOSFETs similar to how Darryl is using opto isolators, but probable this is the circuit I was remembering, thanks again. Ralph Wow, thanks Darryl for the Optocoupler USB to Nerdkits connection post to the Nerdkits Community Library. Now I (and everybody else) can find it easily. Now to get a Eagle schematic and to make up some PCBs. Ralph

## Post a Reply

Please log in to post a reply.

 Did you know that one NerdKits customer controlled a laser pointer with his computer using a microcontroller? Learn more...