Imagine a thermometer that gives you precise digital readings instead of relying on a wobbly mercury line. With embedded systems, you can build exactly that. This project introduces you to creating a digital thermometer using an embedded system.
An embedded system is a small computer designed for a specific task. It's like a mini brain for electronic devices like calculators, microwaves, and even thermometer. In our case, the embedded system will read temperature, process it, and display it digitally.
Components of a Digital Thermometer:
8051 development board
2. ADC0804 board
3. 16*2 LCD
4. LM35 sensor
5. Potentiometer
6. Jumper wires
Circuit Diagram:
Circuit Connections:
The LM35 sensor circuit connections with an 8051 microcontroller typically involve an external Analog-to-Digital Converter (ADC) since the 8051 doesn't have one built-in. Here's a general connection overview:
LM35:
Vcc (Pin 1): Connect to microcontroller's +5V supply.
Output (Pin 2): Connect to the ADC's analog input channel (e.g., ADC0804's IN+).
GND (Pin 3): Connect to microcontroller ground.
ADC (e.g., ADC0804):
Vcc (Pin 16): Connect to microcontroller's +5V supply.
GND (Pin 8): Connect to microcontroller ground.
Clock (CLK): Connect to a clock signal from the microcontroller.
Reference voltage (Vref): Connect to a stable voltage (often half of Vcc).
Analog input (e.g., IN+): Connect to LM35 output (Pin 2).
Digital output (e.g., D0-D7): Connect to microcontroller data pins (e.g., P1 on 8051).
Control pins (CS, RD, WR): Connect to microcontroller control pins for communication (specifics depend on ADC model). Microcontroller (8051):
Power pins (+5V and GND): Connect to respective power rails.
ADC control pins (CS, RD, WR): Connect to corresponding ADC control pins.
LCD (optional): Connect LCD pins to designated microcontroller pins for data and control signals (refer to LCD datasheet).
Working:
The LM35 sensor translates temperature into a voltage increase of 10mV per degree Celsius. This analog voltage is fed into the 8051 microcontroller's ADC, which converts it to a digital value. The microcontroller then uses the conversion rate and performs any necessary calibration to calculate the actual temperature in degrees Celsius. Finally, this calculated temperature is displayed on an LCD screen for easy reading.
Code:
/*this program is for displaying the temperature on 16*2 lcd display using 8051 microcontroller , LM35 sensor and ADC0804*/
#include<reg51.h>
sbit rs=P2^7; //Register Select(RS) pin of 16*2 lcd
sbit rw=P2^6; //Read/Write(RW) pin of 16*2 lcd
sbit en=P2^5; //Enable(E) pin of 16*2 lcd
sbit rd_adc=P3^0; //Read(RD) pin of ADC0804
sbit wr_adc=P3^1; //Write(WR) pin of ADC0804
sbit intr_adc=P3^2; //Interrupt(INTR) pin of ADC0804
void delay(unsigned int) ; //function for creating delay
void cmdwrt(unsigned char); //function for sending commands to 16*2 lcd display
void datawrt(unsigned char); //function for sending data to 16*2 lcd display
void convert_display(unsigned char); //function for converting ADC value to temperature and
display it on 16*2 lcd display
void main(void) //main function
{
unsigned char i;
unsigned char cmd[]={0x38,0x01,0x06,0x0c,0x82};//16*2 lcd initialization commands
unsigned char data1[]="Temperature:";
unsigned char value;
P1=0xFF; //make Port 1 as input port
P0=0x00; //make Port 0 as output port
for(i=0;i<5;i++) //send commands to 16*2 lcd display one command at a time
{
cmdwrt(cmd[i]); //function call to send commands to 16*2 lcd display
delay(1);
}
for(i=0;i<12;i++) //send data to 16*2 lcd display one character at a time
{
datawrt(data1[i]); //function call to send data to 16*2 lcd display
delay(1);
}
intr_adc=1; //make INTR pin as input
rd_adc=1; //set RD pin HIGH
wr_adc=1; //set WR pin LOW
while(1) //repeat forever
{
wr_adc=0; //send LOW to HIGH pulse on WR pin
delay(1);
wr_adc=1;
while(intr_adc==1); //wait for End of Conversion
rd_adc=0; //make RD = 0 to read the data from ADC0804
value=P1; //copy ADC data
convert_display(value); //function call to convert ADC data into temperature and display it on 16*2 lcd display
delay(1000); //interval between every cycles
rd_adc=1; //make RD = 1 for the next cycle
}
}
void cmdwrt (unsigned char x)
{
P0=x; //send the command to Port 0 on which 16*2 lcd is connected
rs=0; //make RS = 0 for command
rw=0; //make RW = 0 for write operation
en=1; //send a HIGH to LOW pulse on Enable(E) pin to start commandwrite operation
delay(1);
en=0;
}
void datawrt (unsigned char y)
{
P0=y; //send the data to Port 0 on which 16*2 lcd is connected
rs=1; //make RS = 1 for command
rw=0; //make RW = 0 for write operation
en=1; //send a HIGH to LOW pulse on Enable(E) pin to start datawrite operation
delay(1);
en=0;
}
void convert_display(unsigned char value)
{
unsigned char x1,x2,x3;
cmdwrt(0xc6); //command to set the cursor to 6th position of 2nd line on 16*2 lcd
x1=(value/10); //divide the value by 10 and store quotient in variable x1
x1=x1+(0x30); //convert variable x1 to ascii by adding 0x30
x2=value%10; //divide the value by 10 and store remainder in variable x2
x2=x2+(0x30); //convert variable x2 to ascii by adding 0x30
x3=0xDF; //ascii value of degree(°) symbol
datawrt(x1); //display temperature on 16*2 lcd display
datawrt(x2);
datawrt(x3);
datawrt('C');
}
void delay(unsigned int z)
{
unsigned int p,q;
for(p=0;p<z;p++) //repeat for 'z' times
{
for(q=0;q<1375;q++); //repeat for 1375 times
}
}
Code Explanation:
This program builds a digital thermometer using an 8051 microcontroller, an LM35 temperature sensor, and an ADC0804 converter to display temperature on a 16x2 LCD. It initializes the LCD communication pins and configures the ADC for reading the sensor output.
The main loop continuously reads temperature. It triggers the ADC to convert the sensor voltage into a digital value.
After the conversion, the program reads the digital value from the ADC. A separate function then converts this digital value to a temperature value in degrees Celsius.
This temperature value is then split into tens and units digits for display. The program sends these digits and a degree symbol as data to the LCD for visualization.
To create a smooth display update, the program includes a delay between each temperature reading.
Overall, this code demonstrates interfacing various components to create a functional temperature measurement system.
Conclusion:
This project demonstrates a simple and effective way to build a digital thermometer using an LM35 sensor and an 8051 microcontroller. The LM35's linear output makes it easy to convert temperature to voltage, and the microcontroller's ADC allows for digital processing and display.
Create Various Projects
Check out our Free Arduino Projects Playlist - Arduino Projects
Check out our Free Raspberry Pi Projects Playlist - Raspberry Pi Projects
Check out our Free TinkerCAD Projects Playlist - TinkerCAD Projects
Check out our Free IoT Projects Playlist - IoT Projects
Check out our Free Home Automation Projects Playlist - Home Automation Projects
Check out our Free NodeMCu Projects Playlist - NodeMCu Projects
Comentários