Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help on writing the data output from my Arduino Temperature sensor to a f

ID: 644537 • Letter: I

Question

I need help on writing the data output from my Arduino Temperature sensor to a file.The code below is able to read the temperature sensor and spit out the data to the screen however, I want it save on a file. I cannot figure it out, please help!


const int temperaturePin = 0;

void setup()
{
Serial.begin(9600);
}

void loop()
{
float voltage, degreesC, degreesF;
  
voltage = getVoltage(temperaturePin);
  
degreesC = (voltage - 0.5) * 100.0;
degreesF = degreesC* (9.0/5.0) + 32.0;
  
Serial.print("voltage:");
Serial.print(voltage);
Serial.print(" deg C:");
Serial.print(degreesC);
Serial.print(" deg F:");
Serial.println(degreesF);
  
delay(1000);
}

float getVoltage(int pin)
{
return (analogRead(pin) * 0.004882814);
}

I need help on writing the data output from my Arduino Temperature sensor to a file.The code below is able to read the temperature sensor and spit out the data to the screen however, I want it save on a file. I cannot figure it out, please help! const int temperaturePin = 0;

Explanation / Answer

Comment if you have any doubts

//make sure you specify correct serial port number

//connec the arduino board to on of the usb ports. Check whether the serail data is coming or not on the serial monitor

//Run the processing code to save the data to text file.

//To stop the processing program press any key

import processing.serial.*;

Serial mySerial;
PrintWriter output;
void setup() {
//getting the corresponding serial port
mySerial = new Serial( this, "COM3", 9600 );//please change the com port acording to your machine
//initializing the text file
output = createWriter( "/Users/data.txt" );
}
void draw() {
//while data is available on serial port, wrtie if to file.
if (mySerial.available() > 0 ) {
String value = mySerial.readString();
if ( value != null ) {
output.println( value );
}
}
}

void keyPressed() {
//stop the program when a key is pressed.
output.flush(); // Writes the remaining data to the file
output.close(); // Finishes the file
exit(); // Stops the program
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote