About the Temperature Sensor using pic microcontoller

Temperature sensors are used in a wide range of electronic devices, including digital thermometers, home thermostats, ovens, and refrigerators. Figure 1 shows two devices with temperature sensors.

Figure 1. Devices with temperature sensors.

The temperature sensor provided in your kit is a precision analog sensor, whose voltage output is linearly proportional to the temperature. Configured as described here, the sensor has an operating range of about 0Β°C to +150Β°C.

About the Temperature SensorConnecting the Temperature Sensor

The temperature sensor is a three-pin integrated circuit. When the device’s flat side is facing towards you, the three pins are labeled 1, 2, and 3, from left to right, as shown in Figure 2.

Depending on your kit, you may have either an LM35 temperature sensor or an LM335 temperature sensor. You can identify your sensor by reading the text on the flat face of the device, as shown in Figure 3. The two sensors are wired slightly differently on the breadboard and produce different analog outputs, so it is critical to identify which type you have before moving ahead.

Figure 3. LM35 (left) and LM335 (right).
If you have the LM35, connect the temperature sensor as shown in Figure 4. Pin 1 is connected to power, and pin 3 is connected to ground. Pin 2 connects to ground through a 1.0 uF capacitor, and to Port C4 (pin 27) on the microcontroller through a 10K Ohm resistor.
If you have the LM335, connect the temperature sensor as shown in Figure 5. Pin 1 is inserted into the breadboard but not connected to anything. Pin 3 is connected to ground. Pin 2 connects to power through a 1K ohm resistor, and to Port C4 (pin 27) on the microcontroller.

Reading and Plotting Temperature Data

Using MATLAB, it is possible to plot data gathered from the ATmega microcontroller. Using the ms.adc_read command, you can have MATLAB gather data from the temperature sensor and display the temperature over time as an x-y graph.
About the Temperature Sensor1. Send command prompt instructions to read the ADC value from the temperature sensor:

>> data=ms.adc_read(4); %Set data equal to temperature value
>> data %Display the current value for the temperature

2. Write a program in the editor window to plot the data from the temperature sensor:

if exist(β€˜ms’)Β  Β %Remove previous connections
delete(ms)
endms=msci.breadboardkit(β€˜COM#’)Β  Β %Connect to com port
msdefinesΒ  Β %Ensure you have ms objects

for i=1:60Β  Β %Start a loop with 60 cycles
pause(1)Β  Β %Pause for 1 second

data=ms.adc_read(4)Β  Β %Read the analog value
plot(i, data, β€˜rs’)Β  Β %Plot the iteration and the value
drawnowΒ  Β %Draw all points plotted so far
hold onΒ  Β %Keep the same graph on the screen
axis([0 60 0 40])Β  Β %Set the x and y axis extentsend

xlabel(β€˜Time (s)’);Β  Β %Label the x axis as Time
ylabel(β€˜Analog Value’);Β  Β %Label the y axis as Analog Value

delete(ms)

About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.