Hi All
Needing a little help with a project currently on the bench. A water tank level indicator with pump control etc.
I am using an ultrasonic distance module to determine tank level and have got it working and sending data ok. The module outputs data in serial format in millimeters. I need to keep the output from the module as whole as possible for maximum resolution. Running into problems calculating total capacity using PI in the calculation. The method I'm using for a vertical cylinder in code is as follows:
314 (PI without decimal point) x 9 (radius 900mm) x 9 (radius 900mm) / 1000 x 1500mm (maximum height of water level in mm) / 10 = 3,815Ltrs
Then 3,851Ltrs minus current reading to give current tank level.
Where the normal way to calculate would be (I think?) :
3.14 x .9m x .9m x 1500mm = 3851Ltrs
All this to keep the working numbers under 65,000. When this method is used I think you lose resolution. I need 1Ltr resolution but this method yields 5Ltr resolution per step.
Is there a fancy way to do the math's without overflowing 65,000 when using a word variable? Perhaps process each digit individually?
Please excuse my mathematical ignorance...If I have any of the calculations wrong please let me know.
Needing a little help with a project currently on the bench. A water tank level indicator with pump control etc.
I am using an ultrasonic distance module to determine tank level and have got it working and sending data ok. The module outputs data in serial format in millimeters. I need to keep the output from the module as whole as possible for maximum resolution. Running into problems calculating total capacity using PI in the calculation. The method I'm using for a vertical cylinder in code is as follows:
314 (PI without decimal point) x 9 (radius 900mm) x 9 (radius 900mm) / 1000 x 1500mm (maximum height of water level in mm) / 10 = 3,815Ltrs
Then 3,851Ltrs minus current reading to give current tank level.
Where the normal way to calculate would be (I think?) :
3.14 x .9m x .9m x 1500mm = 3851Ltrs
All this to keep the working numbers under 65,000. When this method is used I think you lose resolution. I need 1Ltr resolution but this method yields 5Ltr resolution per step.
Is there a fancy way to do the math's without overflowing 65,000 when using a word variable? Perhaps process each digit individually?
Please excuse my mathematical ignorance...If I have any of the calculations wrong please let me know.
Last edited: