Hobbies And Interests
Home  >> Science & Nature >> Science

How to Measure Temperature Using a Microcontroller

Microcontrollers are small integrated circuits that contain memory, programmable inputs and outputs and a processor. The inputs read data from connected electronic components, such as sensors and potentiometers, while the outputs control components and devices like LEDs and motors. You can purchase pre-built augmented microcontrollers, such as the Arduino and Maple, that allow you to create electronics projects quickly and easily. It is easy to connect a temperature sensor to a microcontroller and take a reading.

Things You'll Need

  • Microcontroller
  • Computer
  • 3-pin Temperature sensor
  • Breadboard
  • Single core wire
Show More

Instructions

  1. Write the Program

    • 1

      Connect your microcontroller to your computer. Attach an external power source, if necessary. Turn the microcontroller on. Launch your microcontroller's programming software.

    • 2

      Type in the code that tells the microcontroller to start serial communication with your computer.

    • 3

      Declare integer variables for the reading taken from the temperature sensor and the final temperature's value. "tReading" and "tFinal" are examples of easy-to-understand names for these variables. You may need to insert this code before setting up communication between the microcontroller and your computer, depending on your microcontroller.

    • 4

      Add the code that tells the microcontroller which analog input to read from. The reading is taken from the input that connects the temperature sensor's output to the microcontroller.

    • 5

      Convert the reading from the microcontroller's input to a temperature. Look at your temperature sensor's documentation to find out how to perform the conversion. Use the variables you declared earlier to set up the equation. Your equation may resemble this: tFinal = tReading / 2;

    • 6

      Type in the code that prints the calculated temperature to your computer screen.

    • 7

      Add a time delay at the end of your code. This prevents the program from constantly refreshing your screen with new temperature readings. For example, if you set the delay to 1000 milliseconds, or 1 second, the calculated temperature will appear on your computer screen once every second.

    • 8

      Test your code using the test function in your programming application, if it is included. Upload the program to your microcontroller. Disconnect the microcontroller from its power source.

    Build the Circuit

    • 9

      Place your 3-pin temperature sensor on the breadboard with each pin on a separate copper track.

    • 10

      Connect the sensor's ground pin to the microcontroller's ground output using a piece of single core wire.

    • 11

      Connect the sensor's output pin to the microcontroller's input channel using a piece of single core wire. Use the input channel your program is reading from.

    • 12

      Connect the sensor's Vcc or Vss pin to the microcontroller's voltage output using a piece of single core wire.

    • 13

      Connect the microcontroller to its power source. Turn the microcontroller on. Launch your temperature reading program. The temperature reading appears on your computer screen.


https://www.htfbw.com © Hobbies And Interests