Serial Logging - Multiple Sensors analog read into columns

Hello,

I was hoping to get some guidance on a project that involves serial printing of several analog values. I want those data values to be printed into columns side by side.

I am new to this so my code could the entirely wrong approach. The only information I have found is to use the "\t" to get the next value to go over in the next column.

here is the code I have so far.

int fsrPin0 = 0;     
int fsrReading0; 

int fsrPin1 = 1;     
int fsrReading1;     

int fsrPin2 = 2;    
int fsrReading2;     

int fsrPin3 = 3;     
int fsrReading3; 

int fsrPin4 = 4;     
int fsrReading4;

 
void setup(void) {

  Serial.begin(9600);   
}
 
void loop(void) {
 
 
 
  fsrReading0 = analogRead(fsrPin0); 
  Serial.print("fsrReading0= "); 
  Serial.println(fsrReading0);     
 
 
  delay(500); 
 
  
  
  fsrReading1 = analogRead(fsrPin1);
  Serial.print("fsrReading1 = ");   
  Serial.println(fsrReading1);  
 
  delay(500);

  fsrReading2 = analogRead(fsrPin2); 
  Serial.print("fsrReading2 = ");  
  Serial.println(fsrReading2);  

  delay(500);

  fsrReading3 = analogRead(fsrPin3);
  Serial.print("fsrReading3 = ");   
  Serial.println(fsrReading3);  
  delay(500);

  fsrReading4 = analogRead(fsrPin4);   
  Serial.print("fsrReading4 = ");
  Serial.println(fsrReading4);  
  delay(500);

  
}

Advice appreciated

I want those data values to be printed into columns side by side.

An example of the output that you want to see would be essential.

Is this close to what you want?

int fsrPin0 = 0;
int fsrReading0;

int fsrPin1 = 1;
int fsrReading1;

int fsrPin2 = 2;
int fsrReading2;

int fsrPin3 = 3;
int fsrReading3;

int fsrPin4 = 4;
int fsrReading4;


void setup(void) {

    Serial.begin(9600);
    Serial.println("fsr 0 \t fsr 1 \t fsr 2 \t fsr 3 \t fsr 4");
}

void loop(void) {

    fsrReading0 = analogRead(fsrPin0);
    Serial.print(fsrReading0);
    Serial.print('\t');
    delay(500);

    fsrReading1 = analogRead(fsrPin1);
    Serial.print(fsrReading1);
    Serial.print('\t');
    delay(500);

    fsrReading2 = analogRead(fsrPin2);
    Serial.print(fsrReading2);
    Serial.print('\t');
    delay(500);

    fsrReading3 = analogRead(fsrPin3);
    Serial.print(fsrReading3);
    Serial.print('\t');
    delay(500);

    fsrReading4 = analogRead(fsrPin4);
    Serial.println(fsrReading4);
    delay(500);


}

The only information I have found is to use the "\t" to get the next value to go over in the next column.

Did you try it?

Yes, I will post my readout here in a bit. (gotta go grab the device).

Thanks for the quick replies you guys are great.

hey guys as it turns out I was using the serial.println and serial.print commands incorrectly and thats why my data was jumbled up. Here is the corrected code for keeping multiple sensors in their own columns (For export to matlab, excel etc).

This is a small excerpt. notice the println statement doesn't come in until the last sensor.

sensor0 = analogRead(pin0);  
  Serial.print(sensor0);     // the raw analog reading 
  Serial.print("\t");
  delay(1000); 
 
  sensor1 = analogRead(pin1);  
  Serial.print(sensor1);   
  Serial.print("\t");
  delay(1000);

  sensor2 = analogRead(pin2);  
  Serial.print(sensor2); 
  Serial.print("\t");   
  delay(1000);

  sensor3 = analogRead(pin3);  
  Serial.print(sensor3);    
  Serial.print("\t");
  delay(1000);

  sensor4 = analogRead(pin4);  
  Serial.println(sensor4);     
  delay(1000);

My next step, although not absolutely necessary, would be to export the csv or text file automatically to file.

Thanks guys

Jaunty: I'm using this approach for solving the proposed task, all my data is time-stamped by a DS1307 RTC who is already hooked in to the circuit, we use semicolons ";" for separating the data columns:

#define semicolon ';'   // Semicolon ';'
#define colons ':'     // Colon ':'
#define slash '/'     // Slash '/'
print2digits(tm.Day);
//
Serial.write(slash);
Serial.print(tm.Month);
//
Serial.write(slash);
//Serial.print(tmYearToCalendar(tm.Year)); // Prints full 4-digit year
Serial.print((tmYearToCalendar(tm.Year) - 2000)); // Prints only last 2-digit year
//
Serial.print(semicolon);
print2digits(tm.Hour);
//
Serial.write(colons);
print2digits(tm.Minute);
// If you want seconds logged also, uncomment this block
// Serial.write(colons);
// print2digits(tm.Second);
//
Serial.print(semicolon);
Serial.print((float)DHT11.temperature, 1);
//
Serial.print(semicolon);
Serial.print((float)DHT11.humidity, 0);
//
Serial.print(semicolon);
Serial.print((float)Baro, 1);
//
Serial.print(semicolon);
Serial.print((float)dewPoint(DHT11.temperature, DHT11.humidity),1);
//
Serial.print(semicolon);
Serial.println((float)dewPointFast(DHT11.temperature, DHT11.humidity),1);

My code is based on this examples: DS1307RTC Library and Arduino Playground - Time

Very cool. Thank you for sharing.

Jaunty:
Very cool. Thank you for sharing.

For sure my code needs some clean-up, but hope to help you.