storing the values from temperature sensor

Hello,

I have set up a basic temperature sensor with a RGB LED that changes colour with temperature. However I would like to save the data to my computer. I have seen many examples that use a SD card to store the data but I want the data saved on my computer. please help me! Also im a newbie to arduino so hope you can see my code and i will try to understand.

int redPin = 11;   // Red LED,   connected to digital pin 9
int grnPin = 10;  // Green LED, connected to digital pin 10
int bluPin = 9;  // Blue LED,  connected to digital pin 11

int ThermistorPin = 1;   // Analog input pin for thermistor voltage
void setup()
{
  Serial.begin(9600);  //Start the serial connection with the computer
                       //to view the result open the serial monitor  
  Serial.println("Thermistor temperature measurement:");
  Serial.println("\n           Vo           Rt           T (C)");                     
  
  pinMode(redPin, OUTPUT);   // sets the pins as output
  pinMode(grnPin, OUTPUT);
  pinMode(bluPin, OUTPUT);
              
}

void loop() {
 
int Vo; // Integer value of voltage reading

float R = 9870.0; // Fixed resistance in the voltage divider

float logRt,Rt,T;

float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;

Vo = analogRead(ThermistorPin);   // read voltage of analog pin 1

Rt = R*( 1023.0 / (float)Vo - 1.0 );

logRt = log(Rt);

T = ( 1.0 / (c1 + c2*logRt + c3*logRt*logRt*logRt ) ) - 273.15;   // converting voltage to temperature


Serial.print("          "); Serial.print(Vo);   // print on serial monitor


Serial.print("          "); Serial.print(Rt);


Serial.print("          "); Serial.println(T);


// setting the colours of the RGB LED

if(T >= 26.2)
 {
    digitalWrite(redPin, HIGH);   // red
    delay(100);
    
    digitalWrite(grnPin, LOW);
    digitalWrite(bluPin, LOW);

 }

if((T < 26) && (T >= 23.2))
 {
    digitalWrite(redPin, HIGH);   // yellow
    digitalWrite(grnPin, HIGH);
    delay(100);
    
    digitalWrite(bluPin, LOW);

 }
  
  if((T < 23) && (T > 20.2))
 {
    digitalWrite(grnPin, HIGH);   // green
    delay(100);
    
    digitalWrite(redPin, LOW);
    digitalWrite(bluPin, LOW);
  
 }

if((T < 20) && (T > 17.2))
 {
    digitalWrite(grnPin, HIGH);   // aqua
    digitalWrite(bluPin, HIGH);
    delay(100);
    
    digitalWrite(redPin, LOW);
    

 }

 if(T <= 17)
 {
    digitalWrite(bluPin, HIGH);   // blue
    delay(100);
    
    digitalWrite(grnPin, LOW);
    digitalWrite(redPin, LOW);
  
 }
}

Thank you for any help

Here is my attempt to create a file to save the data to, as expected it doesn’t work. please help!

int redPin = 11;   // Red LED,   connected to digital pin 9
int grnPin = 10;  // Green LED, connected to digital pin 10
int bluPin = 9;  // Blue LED,  connected to digital pin 11

int ThermistorPin = 1;   // Analog input pin for thermistor voltage
void setup()
{
  Serial.begin(9600);  //Start the serial connection with the computer
                       //to view the result open the serial monitor  
  Serial.println("Thermistor temperature measurement:");
  Serial.println("\n           Vo           Rt           T (C)");                     
  
  pinMode(redPin, OUTPUT);   // sets the pins as output
  pinMode(grnPin, OUTPUT);
  pinMode(bluPin, OUTPUT);
              
}

void loop() {
 
int Vo; // Integer value of voltage reading

float R = 9870.0; // Fixed resistance in the voltage divider

float logRt,Rt,T;

float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;

Vo = analogRead(ThermistorPin);   // read voltage of analog pin 1

Rt = R*( 1023.0 / (float)Vo - 1.0 );

logRt = log(Rt);

T = ( 1.0 / (c1 + c2*logRt + c3*logRt*logRt*logRt ) ) - 273.15;   // converting voltage to temperature


Serial.print("          "); Serial.print(Vo);   // print on serial monitor


Serial.print("          "); Serial.print(Rt);


Serial.print("          "); Serial.println(T);


// setting the colours of the RGB LED

if(T >= 26.2)
 {
    digitalWrite(redPin, HIGH);   // red
    delay(100);
    
    digitalWrite(grnPin, LOW);
    digitalWrite(bluPin, LOW);

 }

if((T < 26) && (T >= 23.2))
 {
    digitalWrite(redPin, HIGH);   // yellow
    digitalWrite(grnPin, HIGH);
    delay(100);
    
    digitalWrite(bluPin, LOW);

 }
  
  if((T < 23) && (T > 20.2))
 {
    digitalWrite(grnPin, HIGH);   // green
    delay(100);
    
    digitalWrite(redPin, LOW);
    digitalWrite(bluPin, LOW);
  
 }

if((T < 20) && (T > 17.2))
 {
    digitalWrite(grnPin, HIGH);   // aqua
    digitalWrite(bluPin, HIGH);
    delay(100);
    
    digitalWrite(redPin, LOW);
    

 }

 if(T <= 17)
 {
    digitalWrite(bluPin, HIGH);   // blue
    delay(100);
    
    digitalWrite(grnPin, LOW);
    digitalWrite(redPin, LOW);
  
 }
{
String dataString = "T";   // data string = T value

File dataFile = open("templog.txt", FILE_WRITE);   // creating file to write to
if(dataFile);

  dataFile.println(dataString);
  dataFile.close();   // closing file
  Serial.println(dataString);   // printing data string (T) on serial

else
{
  Serial.println("no")   // if doesnt work print no on serial
}
}
}
if(dataFile);

If you successfully opened the file, do nothing (;). Otherwise, do nothing.

Then, regardless of whether you successfully opened the file, or not, write to and close it.

Then, you have an else floating around that is not paired with an if. Does that even compile? I doubt it.

hello, thank you for your reply! so i should delete the else statement? anything else?

when deleting else statement i get File, dataFile, FileWrite and open not declared in this scope

ollie97: I want the data saved on my computer.

Serial.print("          "); Serial.print(Vo);   // print on serial monitor
Serial.print("          "); Serial.print(Rt);
Serial.print("          "); Serial.println(T);
}

It appears that you just need a proper choice of destination. The serial monitor is really just for debugging. Instead, you can use a proper terminal programme like RealTerm which can save the data to a CSV file. Another option is PLX/DAQ which is an Excel macro and enables you to save the Data directly into an open Excel file. It also enables you to send the data live to a graph. Both of the above are freebies.

Ok thank you, how would I choose a proper destination? And what code do I need to add? Also I tried using the plx daq but I couldn't connect ! Due to my code I think

ollie97: Ok thank you, how would I choose a proper destination? And what code do I need to add? Also I tried using the plx daq but I couldn't connect ! Due to my code I think

I assume your code is kosher and you can see what you expect to see on the serial monitor. In that event it is simply a matter of running RealTerm instead of the serial monitor, no change of code required. You need to set the baud rate, filename and COMport, all of which is self-evident. The port is the same as the one used by the IDE.

PLX is run from Excel and equally intuitive but your code will need the proper output format.

LABEL,DATA, and TIME are Excel commands fed from Arduino. A header is put on the file and each line is timestamped using the PC clock. Below are snippets

void setup() {

  Serial.println("LABEL,Time,InTemp,OutTemp,);

}

void loop() {
  Serial.print("DATA,TIME,   "); 

  Serial.print(InTemp);
  Serial.print(" ,  ");
  Serial.print(OutTemp);
  Serial.println(" ,  ");

hello, thank i have got it to work!!!

for any one using this the LED is on RGB led not three individual LEDs
here is my code:

int redPin = 11;   // Red LED,   connected to digital pin 9
int grnPin = 10;  // Green LED, connected to digital pin 10
int bluPin = 9;  // Blue LED,  connected to digital pin 11

int x = 0;
int row = 0;

int ThermistorPin = 1;   // Analog input pin for thermistor voltage
void setup()
{
   Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
 Serial.println("Thermistor temperature measurement:");
 Serial.println("LABEL, Vo, Rt, T (C)"); 
 Serial.println("\n--------------------");

  pinMode(redPin, OUTPUT);   // sets the pins as output
  pinMode(grnPin, OUTPUT);
  pinMode(bluPin, OUTPUT);
              
}

void loop() {
 
int Vo; // Integer value of voltage reading

float R = 9870.0; // Fixed resistance in the voltage divider

float logRt,Rt,T;

float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;

Vo = analogRead(ThermistorPin);   // read voltage of analog pin 1

Rt = R*( 1023.0 / (float)Vo - 1.0 );

logRt = log(Rt);

T = ( 1.0 / (c1 + c2*logRt + c3*logRt*logRt*logRt ) ) - 273.15;   // converting voltage to temperature





// setting the colours of the RGB LED

if(T >= 26.2)
 {
    digitalWrite(redPin, HIGH);   // red
    delay(100);
    
    digitalWrite(grnPin, LOW);
    digitalWrite(bluPin, LOW);

 }

if((T < 26) && (T >= 23.2))
 {
    digitalWrite(redPin, HIGH);   // yellow
    digitalWrite(grnPin, HIGH);
    delay(100);
    
    digitalWrite(bluPin, LOW);

 }
  
  if((T < 23) && (T > 20.2))
 {
    digitalWrite(grnPin, HIGH);   // green
    delay(100);
    
    digitalWrite(redPin, LOW);
    digitalWrite(bluPin, LOW);
  
 }

if((T < 20) && (T > 17.2))
 {
    digitalWrite(grnPin, HIGH);   // aqua
    digitalWrite(bluPin, HIGH);
    delay(100);
    
    digitalWrite(redPin, LOW);
    

 }

 if(T <= 17)
 {
    digitalWrite(bluPin, HIGH);   // blue
    delay(100);
    
    digitalWrite(grnPin, LOW);
    digitalWrite(redPin, LOW);
  
 }
 
 {                    
 Serial.print("DATA,TIME,"); Serial.print(Vo); Serial.print(","); Serial.print(Rt); Serial.print(","); Serial.println(T);
 row++;
  x++;
  if (row > 360) 
   {
    row=0;
    Serial.println("ROW,SET,2");
   }
  delay(1000);
}
}

ollie97: i have got it to work!!!!!!

Good, and it only took an hour, so I'm glad to see it was pretty painless.

The variable int x appears to be redundant.

:D