my code is also attached here, I am not very good at coding, but my main sketch is, that i want to be able to write an 's' in the serial monitor, to start the process. then when the liquid streams in front of the first sensor, the timeer should start to count, and then the timer should stop counting again when the liquid streams in front of the second sensor.
I am not very experienced with programming yet
I want to measure the time between a liquid flow reaches sensor 1 to it reaches sensor 2. I have set up the wiring and it seems to work. i just don't know which output my sensor give me. (LOW/HIGH, a voltage, or?) i am using these sensors: docs.rs-online.com/861c/A700000007162061.pdf
i want to start the system with writing an 's' to the serial monitor, and then when sensor 1 "see" the liquid it should start the timer and count until sensor 2 "see" the liquid.
Can anyone help me?
code:
const int Sensor1Pin = 2; //definerer pin for sensor 1 (hvid/orange)
const int Sensor2Pin = 3; //definerer pin for sensor 2 (orange)
int SensorValue1; //definerer et tal for værdien af sensor 1
int SensorValue2; //definerer et tal for værdien af sensor 2
bool tidtaeller = false;
char input;
unsigned long timer;
unsigned long tidsvaerdi;
void setup()
{
Serial.begin(9600); //sætter baud raten til 9600
pinMode(Sensor1Pin,OUTPUT); //sætter værdien af "Sensor1Pin" til outputtet
pinMode(Sensor2Pin,OUTPUT); //sætter værdien af "Sensor2Pin" til outputtet
}
void loop()
{
if(Serial.available())
{
input = Serial.read();
if(input=='s') //hvis der skrives s i serial monitoren
{
Serial.print("måling kører");
SensorValue1 = digitalRead(Sensor1Pin); //sæt værdien af sensor 1 til at være det der bliver skrevet i "Sensor1Pin"
SensorValue2 = digitalRead(Sensor2Pin); //sæt værdien af sensor 2 til at være det der bliver skrevet i "Sensor2Pin"
if((tidtaeller == false) && (SensorValue1 == LOW)) //hvis tidstælleren ikke er igang, og sensor 1 værdien er lav
{
tidtaeller = true; //sæt da tidstælleren til true
timer = millis(); //og start med at tæl ind i "tidtæller"
}
if(tidtaeller == true && SensorValue2 == LOW) //hvis tidtælleren er igang, og sensor 2 værdien er høj
{
Serial.print("tiden er:"); //skriv da "tiden er:"
tidsvaerdi = millis()-timer; //beregn tiden lige nu, minus tiden da "tidtæller" startede
Serial.println(tidsvaerdi); //udskriv denne værdi
tidtaeller = false; //sæt tidtæller til false for at stoppe denne
}
}
if(input=='e')
{
Serial.print("mĂĄling stoppet");
tidtaeller = false;
}
}
}
yes, because I am not sure what signal my sensors send out. i now that when the reciever can see the emitter, it has a low voltage, and then when the signal between the reciever and the emitter "breaks" it gets a high voltage.
So what i was think is to set the timer to count when the sensor values get HIGH