All times are UTC + 8 hours




Post new topic Reply to topic  [ 141 posts ]  Go to page 1, 2, 3, 4, 5 ... 10  Next
Author Message
PostPosted: Jan 7th, '12, 02:11 
Almost divorced
Almost divorced
User avatar

Joined: Nov 11th, '09, 03:13
Posts: 1004
Gender: Male
Are you human?: The top half is
Location: Chiang Mai, NW Thailand.
Anyone interested in a "How to" for ambient and in water temperature measurement using a PIC or similar micro?
I've just made one with a PIC (16F877) 1N914 diode, LM-324 Quad OpAmp and a few resistors.
Accuracy should be around 0.2C, but I have yet to confirm that.


Top
 Profile  
Reply with quote  
    Advertisement
 
PostPosted: Jan 7th, '12, 02:22 
Seriously, this cant be healthy.
Seriously, this cant be healthy.
User avatar

Joined: Mar 26th, '10, 20:46
Posts: 5404
Location: South Australia
Gender: Male
Are you human?: Yep
Location: South Australia
DuiNui wrote:
Anyone interested in a "How to" for ambient and in water temperature measurement using a PIC or similar micro?
I've just made one with a PIC (16F877) 1N914 diode, LM-324 Quad OpAmp and a few resistors.
Accuracy should be around 0.2C, but I have yet to confirm that.


I need a how to for everything, so I'de be interested to see what you did.


Top
 Profile  
Reply with quote  
PostPosted: Jan 7th, '12, 08:24 
Legend Member
Legend Member

Joined: Aug 14th, '10, 03:55
Posts: 530
Gender: Male
Are you human?: Jar Head Clan
Location: Minnesota, USA
:blob8: go for it!


Top
 Profile  
Reply with quote  
PostPosted: Jan 7th, '12, 18:28 
A posting God
A posting God
User avatar

Joined: Dec 10th, '11, 15:03
Posts: 2089
Gender: Male
Are you human?: What is human?
Location: Perth Hills
+1 :D


Top
 Profile  
Reply with quote  
PostPosted: Jan 7th, '12, 22:48 
Almost divorced
Almost divorced
User avatar

Joined: Nov 11th, '09, 03:13
Posts: 1004
Gender: Male
Are you human?: The top half is
Location: Chiang Mai, NW Thailand.
So let's start with a little background theory.
A diode is a device which will only let current flow in 1 direction.
One of its characteristics is that there is a voltage drop across the device which (at constant current) is about 0.7V
and varies by about 2.2mV per degrees C.

So the goal is to provide a constant current to the device and measure the voltage dropped across it which will change with temperature.

Step 1 is to provide a constant current to the device.
This is achieved by using a 7805 Voltage regulator which gives us a constant voltage source.
A 1k resistor from the 7805 to the diode, gives us a constant current of 5mA
(I=V/R, I = 5/1000)

Attachment:
Constant Current.png
Constant Current.png [ 4.42 KiB | Viewed 6768 times ]


Step 2 is to measure the voltage dropped across the diode.
You could just use the A to D converter on the PIC without an LM324.

Let's just look at what that would give us.
The A to D module in the PIC16F877 is 10 bits (1024) and with a supply voltage of 5V, 1 ADC count is equal to about 4.9mV
At best we could achieve an accuracy of 2-4 Degrees.

Therefore we need to amplify the voltage drop across the diode, that's where the LM324 comes in.
I used this part because I happen to have some in my component bins, most single supply rail Op-Amps will do the job.
The LM324 has 4 amplifiers in one 14 pin package, the PIC has an 8 channel A-D module, so with one PIC and 2 LM324's you can measure 8 separate temp sources.

We're not intersted in the abolute voltage at the resistor diode junction, we're interested in the change of voltage drop from a set reference point due to temperature.

The rate of change of voltage drop is very consistant from diode to diode (same part) but every diode, has a slightly different voltage drop at a set temperature,
so we need to cancel out that offset and just amplify the difference.
Also as the temperature rises the voltage drops, so we need a way to invert that behaviour.
The Op-Amp will solve both of these issues.
Op-Amps have a positive input and a negative input they amplify the difference between the two.
To the positive input of the LM324 we want to put a voltage which is equivalent to the voltage at the diode resistor junction at our chosen low temperature point
I have chosen to use 0C because you can put the diode in a cup of water inside a plastic bag and freeze it.
With the frozen diode in place, you put a 1K or similar value pot between the op-amp positive input and ground.
This allows you to trim the voltage into the positive input to offset the fixed voltage at the junction.
You should be able to trim this to 0V, I could only get 0.126mV, so I decided to set it to 1V for now, I may revisit this bit later.

On the negative input you have a 1K resistor from the diode - resistor junction, and a 10k resistor from the output of the Op-Amp.
Forward gain of an Op-Amp is very high and therefore it is necessary to provide some negative feed back to scale the amplification.
10k (R3) and 1k (R2) should scale that to 10 times amplification.

Attachment:
temp-full.png
temp-full.png [ 17.37 KiB | Viewed 6768 times ]


One point here:
In the diagram I have used a 741 Amplifier, this is because my CAD package doesn't have an LM324!!!!
An LM324 is basically a quad 741 anyway, so for a single measurement channel you can use the 741 as in the diagram, for a 4 channel, you'll need an LM324 or similar.

That's about it for now, I kinda slapped this thing together without really thinking about it.
Now I've had to describe how it works, it has made my head hurt lol.

I'll talk more about the software and calibration issues once I have played a bit more.
I seem to be having some issues as the temp approaches 0C and 100C but other than that is seems very stable and very linear.

Any questions/comments fire away.
Analogue electronics is not really my strong point, I'm a digital guy, but hopefully this will work.
Using diodes as temp measurement devices is not a new idea and certainly not mine.
Hopefully this project will be simple enough for others to try.

Cheers for now.

Dui


Top
 Profile  
Reply with quote  
PostPosted: Jan 7th, '12, 23:31 
Seriously, this cant be healthy.
Seriously, this cant be healthy.
User avatar

Joined: Mar 26th, '10, 20:46
Posts: 5404
Location: South Australia
Gender: Male
Are you human?: Yep
Location: South Australia
This is great.

More please.

I should do a PICAXE version and see what the difference in cost is.


Top
 Profile  
Reply with quote  
PostPosted: Jan 7th, '12, 23:41 
Almost divorced
Almost divorced
User avatar

Joined: Nov 11th, '09, 03:13
Posts: 1004
Gender: Male
Are you human?: The top half is
Location: Chiang Mai, NW Thailand.
I have never used PICAXE, afaik it's a PIC Micro with a BASIC interpreter built it, not sure though.
What do you use to program your devices BW?
Chances are you could use a straight PIC with the Development environment from Microchip.
That would require learning C though.
C takes 2 days to learn and 25 years to master :)


Top
 Profile  
Reply with quote  
PostPosted: Jan 8th, '12, 03:52 
Legend Member
Legend Member

Joined: Aug 14th, '10, 03:55
Posts: 530
Gender: Male
Are you human?: Jar Head Clan
Location: Minnesota, USA
Terrific writeup DuiNui :thumbleft: :thumbright:

I'd love to see your code on this project. I would like to use a "Stamp" from Parallax which uses their Pbasic language.

What other sensor ideas do you have up your sleeve :think:
--------
One of the frozen chosen that's not frozen yet.

Currently sunny and 37 degrees F.

Can't believe it's January in Minnesota!


Top
 Profile  
Reply with quote  
PostPosted: Jan 8th, '12, 05:22 
A posting God
A posting God
User avatar

Joined: Oct 16th, '11, 06:12
Posts: 2019
Gender: Male
Are you human?: 0110010110
Location: Brisbane, qld
Didn't you have any thermistors lying about ? :D

Seriously though that's a quite inexpensive way to make a temp sensor. I believe you can also use a transistor. I think you can also put the diode in the feedback of the opamp (my analogue skills are a little shameful as well).
Found this http://www.ti.com/lit/an/snva514/snva514.pdf which might be of interest look at 2nd part of page 5, but of course uses a specific part which probably costs more than a diode. Mind you the cost of parts like this is pretty small compared to the time it takes to get something working ;)
But then its always the most simple or trickiest circuits that are the most fun !
I'm trying to think about why its not working at zero or 100deg very well...I thought it would go to 120deg or so without any issues..not that it matters for AP

Now you have me googling for more circuits :D


Top
 Profile  
Reply with quote  
PostPosted: Jan 8th, '12, 06:16 
Seriously, this cant be healthy.
Seriously, this cant be healthy.
User avatar

Joined: Mar 26th, '10, 20:46
Posts: 5404
Location: South Australia
Gender: Male
Are you human?: Yep
Location: South Australia
PICAXE has some free software and there are a few other free and not so free offerings out there.

You program in a basic derivative that you'll find is pretty much what you'd think it is to the point where often you can just take a punt and it will work.

this is a sub that waits for a button to be released before moving on



Code:
WaitForRelease:
   Do Until pinC.3 = 0
           high b.2     'backlight the button
   Loop
   low b.2              'turn off button backlight
return


Top
 Profile  
Reply with quote  
PostPosted: Jan 8th, '12, 13:49 
Almost divorced
Almost divorced
User avatar

Joined: Nov 11th, '09, 03:13
Posts: 1004
Gender: Male
Are you human?: The top half is
Location: Chiang Mai, NW Thailand.
Bob H wrote:
Terrific writeup DuiNui :thumbleft: :thumbright:

I'd love to see your code on this project. I would like to use a "Stamp" from Parallax which uses their Pbasic language.

What other sensor ideas do you have up your sleeve :think:


Thanks Bob :)
I'll post some code when I have got it calibrated.
The bit that actually calculates the temp is very simple code, most of the code is setting up the I/O and therefore is very device specific.
Basically you read the ADC.
Subtract the 0C offset measured at 0C calibration time.
Multiply it by the "constant" degrees/count (calculated at calibration)
and that's it really...

Other sensors?
I have a water level sensor, very simple, two resistive pins that just use the conductivity of water to "make" the connection.
Despite some initial reliability issues (due to a weird s/w problem) they work very nicely.
Daylight detector to perhaps turn the pump off and the air on, enable the autofeeder that kinda thing.

@SV
Yup you can use a transistor, just have to tie 2 legs together to make it work like a diode.
I recalibrated it today and it measures 99.8 in boiling water, so good enough for me.
I have it freezing at the moment to check the 0C value again.

@BW
I meant what programmer do you use to program the device?
Chances are it will program a standard PIC too.
Though if you are comfortable using PICAxe there is probably no reason to change.
A standard PIC is probably slightly cheaper.


Top
 Profile  
Reply with quote  
PostPosted: Jan 8th, '12, 14:18 
Seriously, this cant be healthy.
Seriously, this cant be healthy.
User avatar

Joined: Mar 26th, '10, 20:46
Posts: 5404
Location: South Australia
Gender: Male
Are you human?: Yep
Location: South Australia
That software link is to a list of programs that work with picaxe. I use the picaxe one on windows and the linAXEpad on linux. The linux one doesn't simulate the state of the pins and for a beginner like me it's really usefull to have the simulator. That and sketchup are the only reason I keep windows on my system now.

The interface to the chip is just through a serial plug or USB to stereo headphone jack. You either program the chip and then plug it into your project, or just add the 10cent stereo jack to your project and connect it to the first and last pins.


Top
 Profile  
Reply with quote  
PostPosted: Jan 8th, '12, 14:34 
Seriously, this cant be healthy.
Seriously, this cant be healthy.
User avatar

Joined: Mar 26th, '10, 20:46
Posts: 5404
Location: South Australia
Gender: Male
Are you human?: Yep
Location: South Australia
A thermal reader would consist of a thermistor, or for an evenly spaced gradient a temperature probe, an 08M chip, a resistor, and a stereo headphone jack.

Then say an alarm or some other output.

so you write your code that would be something like..

Code:
Main:
pause 10000 'have a little nap for 10 seconds between reads
do while pinB.5 > 21.5 'in degrees c if its a temperature probe, or in a digital value if its a thermister
     pause 500
     low B.6
Loop

Goto main:


plug your cable in, click upload

And connect a beeper between pin 6 and earth and your away. The chip can sink or source just enough to burn out an led or a little beeper but obviously you need a transistor or something to power anything like a tap.

Sorry I forgot that you need a device to program other stuff. I've never used anything else, so didnt really understand the question :oops:

these 3 manuals are worth a quick skim


Top
 Profile  
Reply with quote  
PostPosted: Jan 8th, '12, 15:35 
Almost divorced
Almost divorced
User avatar

Joined: Nov 11th, '09, 03:13
Posts: 1004
Gender: Male
Are you human?: The top half is
Location: Chiang Mai, NW Thailand.
Calibration:

I have now calibrated my device and all is looking very accurate and stable.
The software in the PIC dumps debug info to a serial port.
Raw ADC counts and calculated temperature, every second.

Procedure:
Put the diode inside a plastic bag and put that in a cup or something and stick it in the freezer.
Wait until it's frozen solid and plug it back into the circuit.

Two Options here, I went with Option 1, so I'll describe that first.
Option 1:
R4 is a 1K Pot as in the diagram.
Using a DVM on the output of the Op-Amp, trim the Pot to give a set voltage, 0V would be good as that will give you the full range of the ADC for measurement.
I (for some unknown reason) could only get 0.126mV at this stage, so decided to set it to 1.0V (just to simplify the maths really)

Here you have to make note of ADC counts and the voltage at the output of the Op-Amp (1.0V or whatever you choose)

Next you want to do the same thing, but with a pan of boiling water.
I happen to have a single ring portable electric cooker, which made this part very easy.
With the diode in the plastic bag, stick it in the pan and measure mV at the output of the Op-Amp and again ADC counts.

Now you have mV and ADC count readings for 0C and 100C
From this you can work out your amplified counts/degree and mV/degree.

My ADC counts at 0C was 207 (1.0V)
My ADC counts at 100C was 570 (2.785V)
To get degrees/count:
Subtract 0C counts from 100C counts (570-207 = 363)
Equals 3.63 counts/degree or degrees/count = 0.275

So the software reads the ADC, subtracts the 0C offset (in my case 207) and multiplies that by 275 (using integer maths to keep it simple)
The displayed result is 1000 times the real degrees C value.
You can do whatever with the maths at this point, the hard bit is done :)


Option 2:
If you don't have a suitable Pot lying around, you can use a 1k (or so) resistor for R4 and perform the above calibration with that.
You'll get slightly less resolution, but in practice, it really shouldn't make that much difference.

I'll put a circuit up for connection to a 16F877 soon, and then post some code.

Last point is:
Don't use an expensive soldering station to heat your water up, you'll end up with an expensive soldering station that doesn't solder any more, lol.

As always, questions/comments, fire away.

Dui.


Top
 Profile  
Reply with quote  
PostPosted: Jan 8th, '12, 16:42 
Seriously, this cant be healthy.
Seriously, this cant be healthy.
User avatar

Joined: Mar 26th, '10, 20:46
Posts: 5404
Location: South Australia
Gender: Male
Are you human?: Yep
Location: South Australia
Unlike the way boiling water loves being at 100c at sea level, frozen water can be colder than 0, so unless you calibrated just at the thaw, you might be out. My ice comes out of my big freezer at -18c or less (I cant read past -18c) and the little freezer attached to my fridge at around -6c.

It probably wouldn't make a lot of difference, but in my book, everything is worth a mention :)


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 141 posts ]  Go to page 1, 2, 3, 4, 5 ... 10  Next

All times are UTC + 8 hours


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  

Powered by phpBB® Forum Software © phpBB Group
Portal by phpBB3 Portal © phpBB Türkiye
[ Time : 0.067s | 16 Queries | GZIP : Off ]