Posts tagged ‘Pressure Sensor interfacing’

Pressure sensor interfacing with Microcontroller

Here , I try to explain is that a pressure sensor detects the pressure and passes an accordingly scaled voltage to microcontroller which converts it into digital data .

For this,i have used ATMEGA32   and MPX4115 pressure sensor. MPX4115 pressure sensor integrates on-chip, bipolar op amp circuitry and thin film resistor networks to provide a high level analog output signal and temperature compensation.More details can be found here MPX4115.

Code is written in C using AVR Studio 4 and winavr gcc compiler.

The ATMEGA32 has an  built-in ADC module. ADC module needs to be initialized.To know  details about ADC initialization and ADC  channel selection,see ATMEGA32 Data sheet.

ADC Initialization

ADMUX=(1<<REFS0);                         // For Aref=AVcc;
ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); //prescalar div factor =128

ADC Channel Selection

//Select ADC Channel ch must be 0-7

ADMUX=(ADMUX&0xE0)|ch;
//Start Single conversion
ADCSRA|=(1<<ADSC);
//Wait for conversion to complete
while(!(ADCSRA & (1<<ADIF)));
ADCSRA|=(1<<ADIF);

Conversion

I have converted  ADC value to pressure using this formula:

adc_result= (5.0/1023.0)*ReadADC(0);

adc_result=((adc_result/5.0)+0.095)/0.009-1;

Source Code

This example code reads analog value from channel 0 and displays it on LCD.

#include <avr/io.h>
#include <inttypes.h>
#include <util/delay.h>
#include “lcd.h”

void InitADC()
{
ADMUX=(1<<REFS0);                         // For Aref=AVcc;
ADCSRA=(1<<ADEN)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0); //Rrescalar div factor =128
}

uint16_t ReadADC(uint8_t ch)
{
//Select ADC Channel ch must be 0-7

ADMUX=(ADMUX&0xE0)|ch;
//Start Single conversion
ADCSRA|=(1<<ADSC);

//Wait for conversion to complete
while(!(ADCSRA & (1<<ADIF)));

ADCSRA|=(1<<ADIF);

return(ADC);
}

int main(void)
{
float adc_result;
DDRB = 0×00;
//Initialize LCD
InitLCD(LS_BLINK|LS_ULINE);
LCDClear();

//Initialize ADC
InitADC();

LCDWriteString(“Pressure monitor”);
_delay_ms(1000);
while(1)
{
LCDClear();
LCDWriteStringXY(0,1,”Pressure=”)
adc_result= (5.0/1023.0)*ReadADC(0);           // Read Analog value from channel-0

adc_result=((adc_result/5.0)+0.095)/0.009-1;

LCDWriteIntXY(9,1,adc_result,3); //Print the value in 4th column second line

LCDWriteStringXY(12,1,”Kpa”);
_delay_ms(10000);
}
return 1;
}

Circuit Diagram

Pressure sensor interfacing

Pressure sensor interfacing Circuit

Download Source code and circuit diagram

Follow

Get every new post delivered to your Inbox.

Join 38 other followers