Proton BASIC Compiler - Building a Barometer

  • Pic® Basic

  • Building a Barometer

    Digital Barometer.MPX5100
    One of my pet projects is building barometers. Way back there was a magazine called ETI and it had a project in for a barometer. It grabbed my attention almost immediately but after going through the parts list my eye fell on the motorola MPX100. I phoned our local agents and no luck. To cut a long story short I basically scrapped the unit after much experimentation.
    A few years ago I found a motorola MPX 5100 (100 kPa 14.5PSI) and when I phoned the agent they had plenty in stock. Was a bit pricey at the time but what it delivered was cool. Factory calibrated, temperature compensated and the output was .2V to 4.7V output. That is 4.5V full scale.It could also be used in wet conditions.
    Now How do I connect my pressure sensor to my micro? I will use the PIC18F452 running at 20Mhz. By now everyone should be able to build a board with a LCD display to Port B with no problem.
    Remember before we can use the sensor we should find out what the unit does and the output.The air pressure around us at sea level is 14.5 PSI approx 1013 mBar. So this unit is ideal for our application. It also outputs a voltage between 0 and 5Volt.
    Remember we are working with a analogue to digital converter. We are going to measure a voltage with it. We need to decide what voltage is going to be used to drive the converter from on step to the next.
    If the ADC is to be used as normal it has been set up to work with 5Volt. Now each step will be equal to 5-1024=0.04883813. You have 0-5v as 1024* 0.04883813.
    Now if we use the MPX5100 at 5 volts then this is not equal 0.04883813 as 4.5 /1024=0.004394531
    MPX5100 = 0.004394531
    PIC18F452 at 5V= 0.04883813
    One solution is to use a op-amp and get it to to the correct multiplication so the steps are correct.
    Thanks to Microchip they have developed their micros so you can use the adjustable Vref in the pic.You can vary the positive as well as the negative of the Vref but I am not going into it at the present time.
    So now the pressure sensor is 100kPa which is equal to 1000Millibar. So 1 millibar = 0.0045 V
    To get our Vref 0.0045*1024=4.6008Volt. So using a bournes multi turn pot with one leg tied to 5V and the other leg tied to 0V and the wiper going to AN3
    Please read the datasheet as to the input impedance of the ADC. Some units need as much as 4700R in series with the input. If the numbers on the display zump around and you have determined its not a PSU problem then check the datasheet and insert that resistor in series.
    The pin on the left of the body with the little notch is pin one1)=Vout2)=GND3)=VSLeave the other pins disconnected. DO NOT CONNECT ANYTHING TO THEM.
    All it leaves now is to write the software.
    Set up the adc as follows.

    TRISA=%00001001 ' Port A direction
    Port A.0 as input from the sensor and AN3 as input to the Vref

    ' ADC
    ADCON1 = %11000101 'an0 in rest dig and an3 in for ref
    Adin_Stime 100 ' ALLOW 100US FOR CHARGE TIME
    Adin_Res 10 ' 10-BIT RESULT REQUIRED
    dim hold_adc as wordLOOP:hold_adc = ADIn 0
    Print At 1,1,Dec hold_adc+110," MilliBar "
    DelayMS 1000

    goto loop
    Due to the offset of the sensor you might have to add about 110 to the reading to get the correct display.
    Also remember we are dealing with an analogue voltage so we cannot measure ½ readings, either 1 or either 2 not 1.5. So what happens now. You will notice that when the reading changes it will flicker half the time one number and then the next number. When it moves up you will see it will show the higher number more than the lower number. There are ways to keep it still but I will leave that up to you to solve.
    Oh for weather if the barometer rises then good weather. If it drops then Rain. If it suddenly drops 2 or more millibar in a few minutes it is about to start raining and if it drops or rises by say 100millibars then RUN your in the eye of a cyclone.
    OK so your unit is up and running how do I know if my readings are accurate. The most common way is to watch the news. In some countries they display the barometer readings for that day and you can compare it. If no telly bulletins then get hold of your nearest weather office. They should be able to give you the local reading. Phone your nearest airport as they also have a barometer running. BTW in aviation 1 millibar = 33ft. Phone the tower and ask the controller on duty for the reading.The local airport sometimes give weather bulletin for aircraft approaching the airport and it also contains a millibar reading as Q&H. If you have a scanner you can tune in. Its around 119mhz. The tower will give you the frequency as well.
    You can buy analogue meters which are calibrated in millibar. Or if you befriend a guy at the local company that sells calibrated meters he can help you calibrate it for you.
    Oh well thats it hope the article will help you barometer boffin s. I have not yet been able to test the barometer over log stretches of time. Try using good quality components. Till next time.