A temperature sensor is connected to a microcontroller to measure the temperatur
ID: 1766191 • Letter: A
Question
A temperature sensor is connected to a microcontroller to measure the temperature of the room. A Red LED is also connected to the Port B Pin number 6. The temperature sensor has the following properties: 1. At 0° C,the sensor voltage is O V 2. The temperature coefficient is 0. 2 voC Write a code that will display the measured temperature on the computer screen If the temperature exceeds 50 C, the red LED must be switched on. Print the temperature on the serial monitor. This program will require a combination of Arduino program and port programmingExplanation / Answer
int sensorPin = 0; //the analog pin t Vout (sense) pin is connected to
//the resolution is 2 mV / degree centigrade with a
/*
* setup() - this function runs once when you turn your Arduino on
* We initialize the serial connection with the computer
*/
void setup()
{
Serial.begin(9600); //Start the serial connection with the computer
//to view the result open the serial monitor
pinMode(13, OUTPUT);
}
void loop() // run over and over again
{
//getting the voltage reading from the temperature sensor
int reading = analogRead(sensorPin);
// converting that reading to voltage, for 3.3v arduino use 3.3
float voltage = reading * 3.3;
voltage /= 1024.0; //Voltage divided by 1024 for 10 bits
// print out the voltage
Serial.print(voltage);
Serial.println(" volts");
// now print out the temperature
float temperatureC = (voltage ) * 500 ; //converting from 2 mv per degree wit 500 mV offset
Serial.print(temperatureC); Serial.println(" degrees C");
if (temperatureC > 50) //Condition check if temp>50 the LED goes High
{
digitalWrite(13, HIGH);
}
else
{
digitalWrite(13, LOW);
}
delay(1000); //waiting a second
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.