Reading Several sensors simultaneously

Hi,

My aim is to read voltages created by several (5 in total) piezoelectric sensors at once.

I would like to be able to see the data from all sensors in the serial plotter/monitor in order to track the movement of an item from different locations.

I have written the code below, which isn't working....

1 - Can anyone suggest how this can be altered to give me the desired result?

2 - What would be the best way to extract the gathered data for further analysis in Matlab?

Many thanks for your help

// Pin Definitions

const int PIEZO_PIN1 = A0; // piezo output
const int PIEZO_PIN2 = A1; // piezo output
const int PIEZO_PIN3 = A2; // piezo output
const int PIEZO_PIN4 = A3; // piezo output
const int PIEZO_PIN5 = A4; // piezo output

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

void loop()
{
// read piezo ads value in, and convert it to a voltage
int piezoADC1 = analogRead(PIEZO_PIN1);
int piezoADC2 = analogRead(PIEZO_PIN2);
int piezoADC3 = analogRead(PIEZO_PIN3);
int piezoADC4 = analogRead(PIEZO_PIN4);
int piezoADC5 = analogRead(PIEZO_PIN5);

float piezoV1 = piezoADC1 / 1023.0 * 5.0;
float piezoV2 = piezoADC2 / 1023.0 * 5.0;
float piezoV3 = piezoADC3 / 1023.0 * 5.0;
float piezoV4 = piezoADC4 / 1023.0 * 5.0;
float piezoV5 = piezoADC5 / 1023.0 * 5.0;

Serial.println(piezoV1);//print the voltage.
Serial.println(piezoV2);//print the voltage.
Serial.println(piezoV3);//print the voltage.
Serial.println(piezoV4);//print the voltage.
Serial.println(piezoV5);//print the voltage.

delay(250);
}

test_2.ino (1.06 KB)

isn't working.

That doesn't give much to do on but try this

// Pin Definitions

const int PIEZO_PIN1 = A0; // piezo output
const int PIEZO_PIN2 = A1; // piezo output
const int PIEZO_PIN3 = A2; // piezo output
const int PIEZO_PIN4 = A3; // piezo output
const int PIEZO_PIN5 = A4; // piezo output


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

void loop()
{
  // read piezo ads value in, and convert it to a voltage
  int piezoADC1 = analogRead(PIEZO_PIN1);
  int piezoADC2 = analogRead(PIEZO_PIN2);
  int piezoADC3 = analogRead(PIEZO_PIN3);
  int piezoADC4 = analogRead(PIEZO_PIN4);
  int piezoADC5 = analogRead(PIEZO_PIN5);
  float piezoV1 = piezoADC1 / 1023.0 * 5.0;
  float piezoV2 = piezoADC2 / 1023.0 * 5.0;
  float piezoV3 = piezoADC3 / 1023.0 * 5.0;
  float piezoV4 = piezoADC4 / 1023.0 * 5.0;
  float piezoV5 = piezoADC5 / 1023.0 * 5.0;
  Serial.print(piezoV1);//print the voltage.
  Serial.print(" ");
  Serial.print(piezoV2);//print the voltage.
  Serial.print(" ");
  Serial.print(piezoV3);//print the voltage.
  Serial.print(" ");
  Serial.print(piezoV4);//print the voltage.
  Serial.print(" ");
  Serial.println(piezoV5);//print the voltage.
  delay(250);
}

NOTE the use of code tags when posting code. Please use them in future

Thank you for your reply.

I have made the changes, and I can now see that the program is recording all data from the 5 sensors I have connected.

However, all 5 recordings are shown in the same column together in the monitor, and in the plotter, I only get 1 plot which I presume includes all the readings. I have attached 2 screenshots from the data bunched in sets of 5 and the plotter.

Is there a way to change the code so that the data from the 5 sensors are shown separately (different columns) and are plotted separately?

Thanks

Look at the print() and println() structure proposed by @UKHeliBob, you will get everything on the same line

  Serial.print(piezoV1);  //print the voltage. (no line return)
  Serial.print(" "); // print a space
  Serial.print(piezoV2);
  Serial.print(" ");
  Serial.print(piezoV3);
  Serial.print(" ");
  Serial.print(piezoV4);
  Serial.print(" ");
  Serial.println(piezoV5);//println adds output character to go to the next line.

Please read forum rules to see how to use tags properly to post content

Your images