PLEASE DO NOT ANSWER UNLESS YOU ARE SURE YOU ARE CORRECT!! A temperature sensor
ID: 3918470 • Letter: P
Question
PLEASE DO NOT ANSWER UNLESS YOU ARE SURE YOU ARE CORRECT!!
A temperature sensor is to be connected to a pin of choice on the MSP430. Connect a 2-digit 7-segment display. The display is used to display the temperature value measured by the temperature in degrees celcius. Write a program in C in code compsoser studio which achieves the following tasks:
1)Initially the 7-segment display digits are all off.
2)Every second the program does an A/D conversion
3)After every 3 samples, the samples are averaged and the resulting digital value corresponding to the average measured temperature is displayed on the 7-segment display. To display values correctly, you need to calibrate the system.
7 segment pin out
3
P1.0
9
P1.1
8
P1.2
6
P1.3
7
P1.4
4
P1.5
1
P1.6
3
P1.0
9
P1.1
8
P1.2
6
P1.3
7
P1.4
4
P1.5
1
P1.6
Explanation / Answer
The code I wrote requires you to have the Arduino Seven Segment library installed. To do this, go here and download all the files by going to "File>Download" at the top of the page.
Then locate you Arduino sketchbook folder (should be located in "Documents>Arduino" on Windows) and create a folder called "hardware" if there isn't already one. Go in that folder, and paste the folder you downloaded before into the "hardware" folder.
It should not be in a .zip or .rar format, which it will most likely come as when you download it, you must extract the entire folder and place it in the hardware folder.
After you installed the library, upload the code below to the Arduino board, and proceed to the next step.
#include "SevSeg.h"
SevSeg sevseg;
int tempUnits = fahrenheit; //which unit of temperature do you prefer?
int refreshTime = 3000; //how many seconds should it wait before it checks and displays the temp again? 1000 = 1 second
unsigned long timer;
float celsius = 0, kelvin = 0, fahrenheit = 0;
void setup()
{
sevseg.Begin(0,2,3,4,5,6,7,8,9,10,11,12,13);
}
void loop()
{
sevseg.PrintOutput();
//Reads the input and converts it to Kelvin degrees
kelvin = analogRead(0) * 0.004882812 * 100;
//Converts Kelvin to Celsius minus 2.5 degrees error
celsius = kelvin - 2.5 - 273.15;
//Converts Celsius to Fahrenheit minus 2.5 degrees error
fahrenheit = ((kelvin - 2.5) * 9 / 5) - 459.67;
unsigned long mils=millis();
if (mils-timer>=refreshTime) {
timer=mils;
//Print teperature to the displays
sevseg.NewNum(tempUnits,(byte) 2);
}
}
Changing the code to work with a common anode display is simple. Change this line of code:
sevseg.Begin(0,2,3,4,5,6,7,8,9,10,11,12,13);
to:
sevseg.Begin(1,2,3,4,5,6,7,8,9,10,11,12,13);
To change the units of the temperature displayed to Celsius or back to Fahrenheit, change the line of code at the top that says:
int tempUnits = fahrenheit;
to:
int tempUnits = celsius;
if you prefer Celsius.
To change the rate at which the display updates the temperature, change the line of code at the top that says:
int refreshTime = 3000;
to:
int refreshTime = <however many seconds you want it to wait before updating * 1000>;
The code is set to refresh every 5 seconds by default. If you put a number that is too low, it will update so fast that you won't be able to read it
Than put it together
Done.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.