AT89C51-Proteus Simulation Infrared Distance Measuring System

System Overview

This system constructs an infrared distance measuring system using the GP2D12 infrared distance sensor, AT89C51 microcontroller, ADC0832 analog-to-digital converter, and LM016L LCD display. The system measures distance using the GP2D12, converts the analog signal to a digital signal, and displays it on the LCD.

Hardware Components

1. GP2D12 Infrared Distance Sensor

The GP2D12 is an infrared distance sensor produced by Sharp, with the following main features:

  • Measurement Range: 10-80cm

  • Output Signal: Analog Voltage (0.4-2.4V)

  • Operating Voltage: 4.5-5.5V

  • Low Power Consumption: Approximately 33mA

2. AT89C51 Microcontroller

As the core controller of the system, its main functions include:

  • Controlling the ADC0832 for analog-to-digital conversion

  • Processing measurement data

  • Controlling the LCD display

3. ADC0832 Analog-to-Digital Converter

An 8-bit serial ADC with the following main features:

  • 8-bit Resolution

  • Dual Channel Input

  • Serial Interface

  • 5V Power Supply

4. LM016L LCD Display

A 16×2 character LCD used to display measurement results.

Hardware Connections

Connections for AT89C51:

P1.2 -> ADC0832 CS

P1.1 -> ADC0832 CLK

P1.0 -> ADC0832 DI

P1.0 <- ADC0832 DO (Note: DI and DO can be shared)

P0.0-P0.7 -> LM016L D0-D7 (External pull-up resistors required)

P2.0 -> LM016L RS

P2.1 -> LM016L RW

P2.2 -> LM016L E

Connections for GP2D12:

VO -> ADC0832 CH0

VCC -> +5V

GND -> GND

Software Design

Main Program Flow

  1. Initialize LCD

  2. Loop:

  • Read ADC value

  • Convert to distance value

  • Display on LCD

Application Code

#include<reg51.h>

#include<intrins.h>

#include<string.h>

#include<stdio.h>

#include “ADC0832.h”

#include “LCD1602.h”

#define uint8 unsigned char

#define uint16 unsigned int

#define uint32 unsigned long

#define A 1388

#define B -5

#define C 2

float getDistance()

{

float d=0.00, sum=0, value=0;

uint8 i=0;

for(i=0; i<10; i++)

{

sum = sum + Get_AD_Result();

}

value = (uint8)(sum/10.0);

d = ( (A*1.0) / ((value+B)*1.0) ) – (C*1.0);

return d;

}

void main()

{

float distance = 0;

uint8 buffer[16];

LCD_Init();

while(1)

{

distance = getDistance();

sprintf(buffer,”Distance=%.1f cm”, distance);

write_str(0, 0, buffer);

}

}

Proteus Simulation Considerations

  1. Add all necessary components in Proteus:

  • AT89C51

  • ADC0832

  • LM016L

  • GP2D12

  • Connect the circuit:

    • P0 port must connect to pull-up resistors

    • Output of GP2D12 connected to ADC0832 CH0

      AT89C51-Proteus Simulation Infrared Distance Measuring System

  • Simulation Debugging:

    • Load the HEX file generated by the project compilation, click the up and down arrows of GP2D12, and observe the LCD display data.

      AT89C51-Proteus Simulation Infrared Distance Measuring System

    System Optimization Suggestions

    1. Add software filtering algorithms, such as moving average filtering, to improve measurement stability

    2. Use more precise ADCs (such as 10-bit or 12-bit) to enhance measurement accuracy

    3. Add temperature compensation algorithms to improve measurement accuracy

    4. Add alarm functions to provide alerts when the distance is too close

    5. Add serial communication functions to upload data to a PC

    Conclusion

    This system implements distance measurement and display functions based on the GP2D12 infrared distance sensor, with the AT89C51 controlling the ADC0832 for analog-to-digital conversion and displaying the results on the LM016L LCD. The system structure is simple, suitable for teaching demonstrations and basic distance measurement applications. In practical applications, further optimization of hardware and software may be required based on specific needs.

    Welcome to follow (operation reference article:Follow the public account and send a message operation), click the blue text at the top “Embedded Simulation Project” or long press to identify the QR code to follow

    Reply in the public account

    5111

    After receiving, automatically send the free Keil project link for this project.

    AT89C51-Proteus Simulation Infrared Distance Measuring System

    Leave a Comment