You are on page 1of 11

NAME: ETHAN A.

MANAOIS DATE: 4/3/2024


SECTION: BSEE-3D SUBMITTED TO: ENGR. GILFRED ALLEN MADRIGAL

Laboratory Activity 2: Temperature Sensor with PIC Microcontroller

Introduction:

Temperature sensing is a crucial aspect of many embedded systems. The LM35 temperature sensor
is a popular choice due to its linear output and ease of interfacing with microcontrollers. The LM35
temperature sensor outputs an analog voltage signal that varies linearly with temperature. However,
microcontrollers typically operate on digital signals. To utilize the temperature readings from the LM35,
we employ the built-in ADC of the PIC microcontroller. The ADC converts the analog voltage signal from
the LM35 into a digital value that the microcontroller can process. By configuring the ADC appropriately,
we can ensure accurate temperature measurements with high resolution. In our experiment, understanding
the ADC's functionality and calibration is crucial for obtaining precise temperature readings.

While obtaining temperature measurements is essential, presenting this information in a user-


friendly format is equally important. The LCD serves as a visual interface between the user and the
temperature sensing system. It allows for real-time display of temperature readings in a clear and
understandable format. By interfacing the LCD with the PIC microcontroller, we can dynamically update
the temperature values as they are measured. Additionally, the LCD provides flexibility in terms of
displaying additional information, such as unit symbols or system status indicators. Understanding how
to initialize, control, and communicate with the LCD is essential for developing effective user interfaces
in embedded systems.

Integrating the ADC and LCD into the temperature sensing system enhances its overall
functionality and usability. The ADC ensures accurate and reliable temperature measurements, while the
LCD provides a convenient means of displaying these measurements to the user. Together, they form a
cohesive system that can accurately sense and present temperature information in real-time. Furthermore,
by simulating and programming the ADC and LCD alongside the LM35 sensor, students gain valuable
experience in sensor interfacing, data conversion, and display output, which are fundamental skills in
embedded systems design and development.
Objectives:

After successful completion of this activity, student should be able to:

• Integrate an ADC for precise temperature measurements and an LCD for clear real-time display,
improving system functionality.
• Incorporate an LCD for accessible presentation of temperature data, enhancing user experience.
• Engage students in ADC and LCD simulation and programming to cultivate essential skills in
sensor integration and data display.

Equipment Required:

Computer with mikroC for PIC IDE installed

Computer with Proteus simulation software

PIC Microcontroller (e.g., PIC16F877A)

LM35 temperature sensor

16x2 LCD display

Crystal Oscillator

2 Capacitors

Power supply

Procedures:

1. Build the designed circuit in Proteus simulation software.


2. Connect the LM35 temperature sensor to the analog input pin of the PIC microcontroller.
3. Interface the LCD display with the PIC microcontroller using appropriate control pins.
4. Write a MikroC program to initialize the PIC microcontroller.
5. Implement code to read analog voltage from the LM35 sensor.
6. Convert the analog voltage to temperature using appropriate scaling factors.
7. Display your SURNAME, Initials and the temperature value on the LCD.
8. Compile the code and generate the hex file.
9. Upload the generated hex file to the PIC microcontroller.
10. Simulate the circuit and verify its functionality.
11. Observe the temperature readings displayed on the LCD.
Example Source Codes for LCD:

// LCD module connections

sbit LCD_RS at RB0_bit;

sbit LCD_EN at RB1_bit;

sbit LCD_D4 at RB2_bit;

sbit LCD_D5 at RB3_bit;

sbit LCD_D6 at RB4_bit;

sbit LCD_D7 at RB5_bit;

sbit LCD_RS_Direction at TRISB0_bit;

sbit LCD_EN_Direction at TRISB1_bit;

sbit LCD_D4_Direction at TRISB2_bit;

sbit LCD_D5_Direction at TRISB3_bit;

sbit LCD_D6_Direction at TRISB4_bit;

sbit LCD_D7_Direction at TRISB5_bit;

// End LCD module connections

char txt1[] = "Microprocessor Lab";

char txt2[] = "BSEE 3";

char txt3[] = "Lcd4bit";

char txt4[] = "example";

char i; // Loop variable

void Move_Delay() { // Function used for text moving

Delay_ms(500); // You can change the moving speed here

}
void main() {

TRISB = 0x00; // Set PORTB as output

PORTB = 0x00; // Clear PORTB

ADCON1 = 0x06; // Configure AN pins as digital I/O

Lcd_Init(); // Initialize LCD

Lcd_Cmd(_LCD_CLEAR); // Clear display

Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off

Lcd_Out(1, 6, txt3); // Write text in the first row

Lcd_Out(2, 6, txt4); // Write text in the second row

Delay_ms(2000);

Lcd_Cmd(_LCD_CLEAR); // Clear display

Lcd_Out(1, 1, txt1); // Write text in the first row

Lcd_Out(2, 5, txt2); // Write text in the second row

Delay_ms(2000);

// Moving text

for (i = 0; i < 4; i++) { // Move text to the right 4 times

Lcd_Cmd(_LCD_SHIFT_RIGHT);

Move_Delay();

while (1) { // Endless loop

for (i = 0; i < 8; i++) { // Move text to the left 7 times


Lcd_Cmd(_LCD_SHIFT_LEFT);

Move_Delay();

for (i = 0; i < 8; i++) { // Move text to the right 7 times

Lcd_Cmd(_LCD_SHIFT_RIGHT);

Move_Delay();

Simulation Environment:
DIAGRAM
SIMULATED DIAGRAM
Source Code for Temperature Sensor:
sbit LCD_RS at RB0_bit;
sbit LCD_EN at RB1_bit;
sbit LCD_D4 at RB2_bit;
sbit LCD_D5 at RB3_bit;
sbit LCD_D6 at RB4_bit;
sbit LCD_D7 at RB5_bit;
//
sbit LCD_RS_Direction at TRISB0_bit;
sbit LCD_EN_Direction at TRISB1_bit;
sbit LCD_D4_Direction at TRISB2_bit;
sbit LCD_D5_Direction at TRISB3_bit;
sbit LCD_D6_Direction at TRISB4_bit;
sbit LCD_D7_Direction at TRISB5_bit;
//
float temperature;
float Displaytemp;
char temp [4];
//
void main(){
TRISB=0X00; //all PORTB as output
TRISA=0X0F; //PORTA0 as Input
Lcd_Init(); //initialise the LCD
ADC_Init(); //initialise ADC
//
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF); //cursor off
//
Lcd_Out (1,3,"temperature");
Lcd_Out (2,4,"sensor");
delay_ms (2000);
//
Lcd_Cmd(_LCD_CLEAR);
Lcd_Cmd(_LCD_CURSOR_OFF);

while (1){
temperature=ADC_Read(RA0);
floattostr (Displaytemp, temp);
Lcd_Out (1,3, "temperature");

Displaytemp=(temperature*50*10)/1023;
Lcd_Out (2, 4, Rtrim(temp));
//
Lcd_Out (2,8,"C");
delay_ms (500);
}
}
Conclusion:

IN CONCLUSION, I FULFILLED THE FOLLOWING EXPERIMENT OBJECTIVES,


WHICH LET ME UNDERSTAND THAT INTEGRATING AN ADC FOR PRECISE
TEMPERATURE MEASUREMENTS AND AN LCD FOR REAL-TIME DISPLAY
CONSIDERABLY IMPROVED THE MICROCONTROLLER SYSTEM'S FUNCTIONING. THE
LCD MAKES IT EASIER TO CONVEY TEMPERATURE DATA AND ENHANCES THE
OVERALL USER EXPERIENCE. LASTLY, MAXIMIZING THE FUNCTIONALITY OF PROTEUS
AND MIKROC FOR PIC SOFTWARE IN THE SIMULATIONS AND PROGRAMMING OF ADC
AND LCD HAS EFFECTIVELY DEVELOPED FUNDAMENTALS IN SENSOR INTEGRATION
AND DATA PRESENTATION.

Questions to answer:

1. How does the LM35 temperature sensor function, and what are its advantages in temperature
sensing applications?
Ans: LM35 IS A TEMPERATURE SENSOR THAT GENERATES AN ANALOGUE
SIGNAL PROPORTIONAL TO THE CURRENT TEMPERATURE. THE OUTPUT VOLTAGE
IS EASILY UNDERSTOOD TO PROVIDE A TEMPERATURE READING IN CELSIUS.
THE ADVANTAGE OF THE LM35 OVER THE THERMISTOR IS THAT IT DOES NOT
REQUIRE EXTERNAL CALIBRATION.

2. Explain the process of converting analog temperature readings from the LM35 sensor into digital
values using the Analog-to-Digital Converter (ADC) in the PIC microcontroller.
Ans: A FEW EASY STEPS ARE REQUIRED TO CONVERT ANALOG TEMPERATURE DATA
FROM THE LM35 SENSOR TO DIGITAL VALUES USING THE PIC MICROCONTROLLER'S
ANALOG-TO-DIGITAL CONVERTER (ADC). FIRST, THE LM35 SENSOR GENERATES AN
ANALOG VOLTAGE SIGNAL PROPORTIONATE TO THE TEMPERATURE IT MONITORS.
THIS ANALOG VOLTAGE IS APPLIED TO ONE OF THE PIC MICROCONTROLLER'S
ANALOG INPUT PORTS. THE ADC IN THE PIC MICROCONTROLLER SAMPLES THIS
ANALOG VOLTAGE AND CONVERTS IT TO A DIGITAL VALUE REPRESENTING THE
TEMPERATURE. THIS DIGITAL NUMBER IS SUBSEQUENTLY PROCESSED AND
DISPLAYED AS DESIRED, SUCH AS ON AN LCD PANEL, RESULTING IN A DIGITAL
REPRESENTATION OF THE TEMPERATURE MEASUREMENT.
3. What role does the Liquid Crystal Display (LCD) play in improving user interaction and
accessibility of temperature data?
Ans: THE LIQUID CRYSTAL DISPLAY (LCD) VISUAL INTERFACE GIVES
CUSTOMERS CLEAR AND EASY-TO-READ TEMPERATURE DATA IN REAL-TIME.
BY DISPLAYING THE INFORMATION DIRECTLY ON THE SCREEN, USERS MAY
RAPIDLY GRASP THE CURRENT TEMPERATURE WITHOUT NEEDING EXTRA
TOOLS OR CALCULATIONS. THIS IMPROVES USER INVOLVEMENT BY
REDUCING THE PROCESS OF ACCESSING AND INTERPRETING
TEMPERATURE DATA, MAKING IT MORE ACCESSIBLE AND INTUITIVE.

4. What are the key steps involved in programming the PIC microcontroller to read temperature
data from the LM35 sensor and display it on the LCD?
Ans: THE ESSENTIAL STEPS IN PROGRAMMING THE PIC MICROCONTROLLER TO
READ TEMPERATURE DATA FROM THE LM35 SENSOR AND DISPLAY IT ON THE
LCD INCLUDE INITIALIZING THE NECESSARY PINS FOR INPUT AND OUTPUT,
SETTING UP THE ADC MODULE TO READ ANALOG DATA FROM THE LM35
SENSOR, CONVERTING THE ANALOG TEMPERATURE READINGS TO DIGITAL
VALUES, PROCESSING THE DIGITAL VALUES TO OBTAIN THE TEMPERATURE IN
CELSIUS OR FAHRENHEIT, AND FINALLY SENDING THE TEMPERATURE DATA TO
THE LCD FOR DISPLAY.
5. How do you troubleshoot common issues encountered during the simulation or programming of
the ADC and LCD in the temperature sensing system?
Ans: WHEN TROUBLESHOOTING TYPICAL ISSUES WITH ADC AND LCD IN A
TEMPERATURE SENSING SYSTEM, MAKE SURE ALL CONNECTIONS ARE SECURE
AND PROPERLY WIRED. CHECK THE CODE FOR FLAWS OR TYPOS AND ENSURE IT
MATCHES THE HARDWARE CONFIGURATION. CHECK POWER SUPPLY AND
GROUND CONNECTIONS. IF THE ADC RESULTS APPEAR INACCURATE, DOUBLE-
CHECK THE REFERENCE VOLTAGE AND CALIBRATION PARAMETERS. CONFIRM THE
INITIALIZATION SEQUENCE AND PIN CONNECTIONS IF YOU ARE EXPERIENCING
LCD DIFFICULTIES. IN ADDITION, TEST EACH COMPONENT SEPARATELY TO ISOLATE
THE PROBLEM. IF THE PROBLEM PERSISTS, REVIEW THE REQUIRED DOCUMENTS
OR SEEK HELP FROM INTERNET FORUMS OR COLLEAGUES.
References:
https://www.engineersgarage.com/lm35-description-and-working-
principal/#:~:text=LM35%20is%20a%20temperature%20sensor,not%20require%20any%20exter
nal%20calibration.

https://www.electronicwings.com/pic/lm35-temperature-sensor-interfacing-with-pic18f4550

You might also like