Hey there!
I'm doing a project for school where a package is on the move and during it's travel I need to measure the volume of that package. I've measured 2 dimensions already by using an ultrasonic sensor. So we can save 2 extra sensors we decided to measure the third dimension by timing how long it is detected under the sensor that measures the height. But me and my team are having trouble setting up the timer. When we have the time period we want to multiply it with the speed of the belt so we get the length. as last we will multiply every dimension and it will be printed on our lcd. We've already spend more than 15 hours trying to solve this problem. The arduino forum didn't help us either, can someone pls help us? (You can view our code at the bottom)

I'm doing a project for school where a package is on the move and during it's travel I need to measure the volume of that package. I've measured 2 dimensions already by using an ultrasonic sensor. So we can save 2 extra sensors we decided to measure the third dimension by timing how long it is detected under the sensor that measures the height. But me and my team are having trouble setting up the timer. When we have the time period we want to multiply it with the speed of the belt so we get the length. as last we will multiply every dimension and it will be printed on our lcd. We've already spend more than 15 hours trying to solve this problem. The arduino forum didn't help us either, can someone pls help us? (You can view our code at the bottom)

C-like:
//I2C LCD Toevoegen
#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 time1;
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();
//Basic text LCD
lcd.setCursor(2,0);
lcd.print("Volume");
starttime = millis() //start timer
}
void loop() {
// Variabelen set
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);
// startime false maken
bool starttime = false;
// timer starten
if (final3<56){
time1 = 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 measuredvalue = (final1 + final2);
const int widthpackage = (60-gemetenwaarde);
const int heightpackage = (54-final3);
const int opp1 = (heightpackage*widthpackage);
const int timsensor3 = (elapsedtime*10^-3);//measured time is in millis and i need it in seconds
const int speedconveyorbelt = (1);
const int lengthpackage = (tijdsensor3*speedconveyorbelt);
lcd.setCursor(2,1);
lcd.print (lengthpackage);
}
}
}
}
}
delay(4000);
}
Last edited by a moderator: