Modify/Write code that will plot the current temperature of the device. Be sure
ID: 3587285 • Letter: M
Question
Modify/Write code that will plot the current temperature of the device. Be sure to write the code such that decimal values are plotted, such as 100.52 degrees F.
Given a potential temperature range spanned over 5V or 1023 digital, what is the resolution with which you can read temperature? (what would be the temperature change per bit change?). _________________
Read values and see if what what you calculate is close depending on rounding. Results?
Use a setpoint and LED such that when the temperature drops the setpoint, an LED lights representing a heater energizing.
Plot the setpoint and the state of the LED on MakerPlot.
Use a textbox on MakerPlot to adjust the temperature setpoint.
To prevent device ‘chatter’ (the LED/heater cycling on and off quickly at the setpoint), do not turn off the LED/Heater until the temperature goes above the setpoint + 3 degrees.
This example code is in the public domain.
*/
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int rLED = 2; // Output pin that the LED is attached to
int alarm = 180; // Set alarm level
int sensorValue = 0; // value read from the pot
int angle = 0; // Pot value converted to angle of degrees
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(rLED, OUTPUT);
delay (100);
Serial.println(""); // Sent nothing for CR
Serial.println("!RSET"); // Reset the plot
Serial.print("!O met0.AMAX="); // Set meter alarm on MP
Serial.println(alarm); // alarm value with CR
Serial.println("!SPAN 0,250"); // Set Y-span of MP with CR
Serial.println("@TEXT 1A,D0,0.7,(BLUE),Red LED"); // Label Red LED digital plot
// Xcoor (0A-100A plot area is always 0 to 100, Ycoor -D0 is digital 0, size, color, text
// ****** Deletes MakerPlot Meter 1 & controls to make room
Serial.println("!O met1.Delete");
Serial.println("!O pbmSet1.Delete");
Serial.println("!O tswAlarm1.Delete");
Serial.println("!O lblMet1.Delete");
// ****** Deletes setpoint controls if previosly created
Serial.println("!O SetPoint.Delete");
Serial.println("!O lblSetPoint.Delete");
// ****** Creates setpoint controls to label and set the current setpoint
Serial.println("!O oText.SetPoint=89,57,8,5,180,15,0,8");
Serial.println("!O oLabel.lblSetPoint=80,56,10,3,Set Point:,7,15,8,0");
// ***** creates code in MP when setpoint changed, update met0 alarm setting with its value ((ME))
Serial.println("!POBJ SetPoint.C=!O Met0.AMax = ((ME))");
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of angle of motion
angle = map(sensorValue, 0, 1023, 0, 200);
// ****** Has MakerPlot read and send back value in SetPoint text box
Serial.println("!READ (SetPoint)");
// ****** Accepts incoming data and stores in alarm
alarm = Serial.parseInt();
// Plot in MakerPlot
Serial.print(angle); // Plot angle
Serial.print(","); // comma to seperate values
Serial.println(alarm); // plot alarm with CR
Serial.print("%"); // plot digital value of LED
Serial.println(digitalRead(rLED));
if (angle > alarm) // Check if over alarm
{
digitalWrite(rLED, HIGH); // Turn LED ON
Serial.println("!STAT LED On"); // show status in status with CR
}
else
{
digitalWrite(rLED, LOW); // turn LED Off
Serial.println("!STAT LED Off"); // show status in status with CR
}
// wait 20 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading (at least 2 mS):
delay(20);
}
Explanation / Answer
The code has modified and changed
const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int rLED = 2; // Output pin that the LED is attached to
int alarm = 180; // Set alarm level
int sensorValue = 0; // value read from the pot
int angle = 0; // Pot value converted to angle of degrees
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(rLED, OUTPUT);
delay (100);
Serial.println(""); // Sent nothing for CR
Serial.println("!RSET"); // Reset the plot
Serial.print("!O met0.AMAX="); // Set meter alarm on MP
Serial.println(alarm); // alarm value with CR
Serial.println("!SPAN 0,250"); // Set Y-span of MP with CR
Serial.println("@TEXT 1A,D0,0.7,(BLUE),Red LED"); // Label Red LED digital plot
// Xcoor (0A-100A plot area is always 0 to 100, Ycoor -D0 is digital 0, size, color, text
// ****** Deletes MakerPlot Meter 1 & controls to make room
Serial.println("!O met1.Delete");
Serial.println("!O pbmSet1.Delete");
Serial.println("!O tswAlarm1.Delete");
Serial.println("!O lblMet1.Delete");
// ****** Deletes setpoint controls if previosly created
Serial.println("!O SetPoint.Delete");
Serial.println("!O lblSetPoint.Delete");
// ****** Creates setpoint controls to label and set the current setpoint
Serial.println("!O oText.SetPoint=89,57,8,5,180,15,0,8");
Serial.println("!O oLabel.lblSetPoint=80,56,10,3,Set Point:,7,15,8,0");
// ***** creates code in MP when setpoint changed, update met0 alarm setting with its value ((ME))
Serial.println("!POBJ SetPoint.C=!O Met0.AMax = ((ME))");
}
void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of angle of motion
angle = map(sensorValue, 0, 1023, 0, 200);
// ****** Has MakerPlot read and send back value in SetPoint text box
Serial.println("!READ (SetPoint)");
// ****** Accepts incoming data and stores in alarm
alarm = Serial.parseInt();
// Plot in MakerPlot
Serial.print(angle); // Plot angle
Serial.print(","); // comma to seperate values
Serial.println(alarm); // plot alarm with CR
Serial.print("%"); // plot digital value of LED
Serial.println(digitalRead(rLED));
if (angle > alarm) // Check if over alarm
{
digitalWrite(rLED, HIGH); // Turn LED ON
Serial.println("!STAT LED On"); // show status in status with CR
}
else
{
digitalWrite(rLED, LOW); // turn LED Off
Serial.println("!STAT LED Off"); // show status in status with CR
}
// wait 20 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading (at least 2 mS):
delay(20);
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.