Hello , i'm building an water level on my 6k L tank based on the angle that the
floater makes . Inside the floater will be an mpu6050 accelerometer/gyro board ,already cover by epoxy.
So the floater it's hoked to a rigid pipe/stick and makes semi circle while goes from level high or low or the oposite as picture.
lower level 180º mpu6050 reports -1 ,90º decres reports 0 and on top reports 1. i think it's in radians .
I want convert this to percentage, but math it's not my great advantage. Can someone help me with the formula?
so -1 its 0% ,0rads it's 50% and 1 it's 100% . to be more "fun" we have negative numbers ...
Thank you. Map() shoud solve. i never had used map() before ,but apear that will work for this. i post the result and the code if someone want to use it,because they use ultrasonic sensors that have only a short range and this mpu6050 it's presize for measure tank level...
like i told i never used map befor and i'm getting strange "behavior": this sketch for test the mpu6050 i get an output of 50%,ALWAYS! independent of the variable "incl" .why that happens?
While this is a little late I'll toss it out anyway. Yes, you can use your MPU6050 to measure tank level. Personally I see it as a poor choice simply because first you need to isolate all your electronics as you have done with epoxy or similar like silicone and next you still have a moving arm to pivot so you may have mechanical issues.
Given the choices as to how to go about this I would have used "The Bubbler Method of Liquid Level Measurement" . Simple ans accurate and can not only afford tank level but how much water is in your tank in liters or gallons or whatever trips your trigger. No wetted parts and no moving parts in your tank.
@jim-p : It works indeed. i don't know what calculation i made the first time that it didn't match...thank you @Ron_Blain : i belive that your solution is more acurate ,but can't beat the price of an mpu6050 and this is my house tank for irrigation,not a professional solution. Just for i have an metter inside home (by rfm69 and mysensors library) just in case i forgot someting on, wasting water during the night. if the water get too low there is an external pump from underground that fills the tank again. but i'm the generation that knows ,water must be preserved..
final scketch ,if it 's usefull for someone, for serial output values:
One more question. It is possible move pin D2 (int) that is an interrupt to pin D3?
D2 is used for the rfm69(and mysensors library) for the same propose. i used basicMPU6050 library here.