HOW TO INTERFACE SENSORS WITH 8051 MICRO CONTROLLER?

Introduction:

Sensors are the electro-mechanical devices which converts the physical world parameters (air, wind, speed, light, color..) into its corresponding electrical signals. Using sensors many developments is been done. Mostly all the micro controllers are interfaced with sensors  for a particular task.

Case study:

For example lets consider a visitor counter.

This is built around the IR-sensor and 8051 MCU and a 7-segment LED display, this will. Here the IR-sensor detects the change in the variations in the light and gives a ON/OFF pulse. These pulses are fed to the MCU and counts the number of pulses. Displays the count on 7-segment LED display.

Classifications of Sensors:

Sensors are classified into two types they are,

  • Digital sensors.
  • Analog Sensors.

Digital sensors:

This kind of sensors gives the ON/OFF pulses at the output side, which means 0V and 5V. Basically, all the digital sensors are Analog in nature but in the back end these are interfaced to comparators.

Examples:

  • IR-Sensor.
  • Ultrasonic sensor.
  • PIR sensor.
  • Proximity sensors.
  • Metal detectors.

Many more sensors are getting manufactured as per the requirements of users.

Analog Sensors:

            These are not like digital sensors that is they could not give ON/OFF signals as output instead they will produce a sinusoidal wave as output. These signals need some analog to digital converters (ADC) for interfacing with MCU. Now a days mostly all the MCUs has its own ADC channels, except for 8051 families there is no ADC block internally so analog sensors are to be interfaced with ADC for 8051.

Examples:

  • Current sensor.
  • MEMS
  • Humidity sensor
  • Temperature sensor etc..

Caution:

         While interfacing a sensor to 8051 the power supply should not exceed the ratings of the sensor, this may damage the sensor.

Note: Before using any sensor calibrate and check it, if it is working properly or not.”

Source code:

Digtial sensor interfacing with 8051:

As in the previous code lets do a simple visitor counter, using IR-sensor.

#include <regx51.h>
sbit sen = P1^0;
void delay(int time){
int i,j;
for(i=0;i<=time;i++)
for(j=0;j<=1275;j++);
}
void main()
{
int c,d,count;
char num[]={0xC0,0xF9,0xA4,0xB0,0x99,0x92,0x82,0xF8,0x80,0x98};
sen = 0;
sen = 1;
P2=P3=0x00;
P2=0xC0;
P3=0xC0;
c=0;
d=0;
while(1)
{
while(sen==0)
{
if(d>=10)
d=0;
P2 = num[d++];
count = 0;
c=0;
delay(1);
while(count++>=0)
{
P3=num[c++];
delay(45);
if(count>=10)
break;
while(sen==1);
delay(10);
}
}
}
}

IR SENSOR INTERFACING WITH 8051

                                                    Fig a: 8051 circuit diagram interfacing with IR sensor

Analog Sensor interfacing:

In this example we are going to learn interfacing 8051 with ADC 0804

ADC 0804:

These chips are CMOS 8-bit successive approximation analog to digital converters. Where the outputs can be interfaced with micro-controller/microprocessor directly without any logic. Differential inputs allow increasing in CMMR (Common Mode Rejection) and offset input voltage. And the analog input reference can be controlled externally.

Features of ADC 0804:

  • 8 bit resolution
  • Differential analogue voltage inputs
  • 0-5V input voltage range
  • No zero adjustment
  • Built-in clock generator
  • Voltage at Vref/2 can be externally adjusted to convert smaller input voltage spans to full 8 bit resolution.

Resolution:

            Resolution refers to the conversion of an analog voltage to a digital value. It indicates the number of discrete values that an ADC can produce over the range of analog values, these are in binary format.

Step size:

            It is the voltage difference between the one digital voltage level and the next voltage level that can be measured by the ADC.

Since ADC 0804 is single channel ADC and has 8-bit resolution. It gives the smaller step size that is input voltage span is 0-5V and the step size is 19.3mV (5V/255). In this situation we called Vref/2 is left open.

Pin Diagram of ADC 0804:

Fig b: ADC 0804 pin diagram.

Pin Description:

[table id=1 /]

Code:

#include<regx52.h>
#define input P2               //Input port1 (read values of ADC)
#define output P0              // Output port0 (connected to LED's)
sbit wr= P3^5;                 // Write pin.
sbi trd= P3^6;                 // Read pin.
sbit intr= P3^4;               // Interrupt pin.
void delay(unsigned intmsec )  // Delay function
{
int i,j ;
for(i=0;i<msec;i++)
for(j=0; j<1275; j++);
}
voidadc()            // Reading values from ADC and display on the LED's
{
rd=1;
wr=0;
delay(10);
wr=1;
while(intr==1);
rd=0;
output=input;
delay(10);
intr=1;
}
void main()
{
input=0xff;          // Declare port 1 as input port.
output=0x00;         // Declare port 0 as output port.
while(1)
{
adc();
}
}

Interfacing Circuit:

ADC 0804 INTERFACING WITH 8051

Fig c: ADC0804 interfacing with 8051

Categories: Design, posts

Leave a Reply

Your email address will not be published. Required fields are marked *