Hi,
I want my code to work for in a way that the second sensor in the coding works for 7 seconds. This works now, but only prints out one value every 7 seconds. I want it to print all values from 0-7 seconds and then stay idle for another 7 seconds until the loop restarts again.This is then send to matlab where a signal from serial FT232 is used and plot a graph. Any help on this would be appreciated.
// int sensors
#include <SoftwareSerial.h>
#define rxPin 0
#define txPin 1
const int sensorA1=analogRead(A1);
const int sensorA3=analogRead(A5);
int relay_pin=digitalRead(13);
int Interval;
SoftwareSerial mySerial(rxPin,txPin);// setup new serial ports
void setup()
{
Serial.begin(9600);// setting data rate for analog and digital input
mySerial.begin(9600);// setting data rate for serial input
pinMode (13,OUTPUT);//Defining ports as output
pinMode (rxPin,INPUT);
pinMode (txPin,OUTPUT);
}
void loop()
{
//Sensor A1 read and print
Serial.print("Sensor Value (A1): ");
Serial.print(analogRead(A1));
float voltageA1 = (analogRead(A1)*5.0)/1024.0;// scaling towards 0-5v for analog read
Serial.print(" Volts:(A1) ");
Serial.print(voltageA1);
float pressure_pascalA1 = (0.505*((float)voltageA1-1))*1000000.0;// conversion voltage to pascal
float pressure_barA1 = pressure_pascalA1/10e5;
Serial.print(" Pressure before solenoid (A1) = ");
Serial.print(pressure_barA1);//plotting data
Serial.println(" bars");
if (pressure_barA1<=0.32)// Pressure read when pressure below specific value.
{
digitalWrite(13, HIGH);
Serial.print("Sensor Value (A5): ");// Sensor A3 read and print, triggering of the second sensor for reading value.
Serial.print(analogRead(A5));
float voltageA5 = (analogRead(A5)*5.0)/1024.0;
Serial.print(" Volts:(A5) ");
Serial.print(voltageA5);
float pressure_pascalA5 = (0.505*((float)voltageA5-1))*1000000.0;
float pressure_barA5 = pressure_pascalA5/10e5;
Serial.print(" Pressure at chamber (A5) = ");
Serial.print(pressure_barA5);// plotting data
Serial.println(" bars");
Serial.print("Waiting for 7 seconds");
} else
digitalWrite(13, LOW);
delay (7000);
}