For My current arduino project I am building a system that can measure the volume of packages. for the lenght I need to measure the time in an If statement but i really can not get it to work do you see the mistake ? I also dont get any error messages.
the code
//I2C LCD Toevoegen (Bibliotheek niet vergeten)
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd (0x27,16,2); /// of 16, 2
int trigPin1 = 10;
int echoPin1 = A1;
int trigPin2 = 3;
int echoPin2 = A0;
int trigPin3 = 5;
int echoPin3 = A2;
// Sensor 1,2 & 3 maximum afstand
int max1 = 60;
int max2 = 60;
int max3= 70;
// Timers opzetten
unsigned long starttime;
unsigned long meetwaarde1;
unsigned long endtime;
void setup() {
//Sensor pinnen
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(trigPin3, OUTPUT);
pinMode(echoPin3, INPUT);
//LCD Setup
lcd.begin();
lcd.clear();
lcd.backlight();
//Basistekst LCD
lcd.setCursor(2,0);
lcd.print("Volume");
}
void loop() {
//starttime starte
unsigned long starttime = millis();
// Variabelen zetten
int duration1, distance1, duration2, distance2, duration3, distance3;
// Sensor 1
digitalWrite (trigPin1, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin1, LOW);
duration1 = pulseIn(echoPin1,HIGH);
// De afstand is de tijd maal door de snelheid van het geluid gedeeld door 2
distance1 = duration1 * 0.034 / 2;
if (distance1 < max1) {
int final1 = distance1;
delay(50);
// Sensor 2
digitalWrite (trigPin2, HIGH);
delayMicroseconds (10);
digitalWrite (trigPin2, LOW);
duration2 = pulseIn(echoPin2,HIGH);
// De afstand is de tijd maal door de snelheid van het geluid gedeeld door 2
distance2 = duration2 * 0.034 / 2;
if (distance2 < max2) {
int final2 = distance2;
delayMicroseconds(50);
//sensor 3
digitalWrite (trigPin3, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin3,LOW);
duration3=pulseIn(echoPin3,HIGH);
distance3=duration3 * 0.034 / 2;
if (distance3 < max3) {
int final3 = distance3;
delayMicroseconds(50);
//boolean starttime = false
starttime=false;
// timer starten
if (final3<56){
meetwaarde1 = millis();
if (final3>56){
endtime = millis();
// tijd pakket onder sensor 3
unsigned long elapsedtime = (endtime-meetwaarde1);
// gemeten waardes omvormen en een paar berekeningen
const int gemetenwaarde = (final1 + final2);
const int breedtepakket = (60-gemetenwaarde);
const int hoogtepakket = (54-final3);
const int opp1 = (hoogtepakketbreedtepakket);
const int tijdsensor3 = (elapsedtime10^-3);
const int snelheidband = (1);
const int lengtepakket = (tijdsensor3*snelheidband);
lcd.setCursor(2,1);
lcd.print (elapsedtime);
}
}
}
}
}
delay(4000);
}