Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Arduino map and constrain function

Status
Not open for further replies.

imranahmed

Advanced Member level 3
Advanced Member level 3
Joined
Dec 4, 2011
Messages
817
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,298
Location
Karachi,Pakistan
Activity points
6,493
Hi,

Please let me know that I have ultrasonic sensor values in feet from 1 ft to 13 ft. But I want to convert that values to percentage.
For example: 1 ft is 100% , 1.5 ft is 95%........................13 ft is 10%.
 

Hi,

how does the digital readings look like. Please list a couple of digital values and their corresponding distance.

BR
 
Hi,

how does the digital readings look like. Please list a couple of digital values and their corresponding distance.

BR

1 ft is 100% till 13 ft is 10% but percentage values should increase or decrease with gap of 5% 100%, 95%, 90%, 85%, 80%................15%, 10%

If water tank full means 100% then gradually tank is sinking 95% 90% 85%........10%
--- Updated ---

Hi,

how does the digital readings look like. Please list a couple of digital values and their corresponding distance.

BR
Tank size is programmed with different sizes selected in menu from 1 to 13 feet.
If I have tank of 7 feet then I will set tank size 7ft then readings should be display according tank size i,e 7ft.
In 7feet tank water from bottom of tank to 6ft from top 1ft left for space.
ultrasonic readings should be looks like if water is full in 7ft tank left 1 feet from top means water is 6ft then readings shows
100% then water going down 95% , 90% , 85% , 80% , 75%......................10%.
 
Last edited:

Hi,

I'm curious if the readings are linear (I asume so). If so, someone can solve this problem easily by an equation. The question is, do the readings (digital values) increase or decrease with an increasing distance? Is the relation direct or indirect proportional?

So if it possible please post some digital values and their corresponding distance, as it seems you have the measurement results. With this values we are able to provide you an appropriate equation, and with the values we are able to check the suggested solution before posting.

If I have tank of 7 feet then I will set tank size 7ft then readings should be display according tank size i,e 7ft.

So you also want to adjust the maximum depth of the tank e.g. one tank ranges from 1 ft (100 %) to 13 ft (10 %) and an other one from 1 ft (100 %) to e.g. 7 ft (10 %). Am I right?

BR
 
Hi,

I'm curious if the readings are linear (I asume so). If so, someone can solve this problem easily by an equation. The question is, do the readings (digital values) increase or decrease with an increasing distance? Is the relation direct or indirect proportional?

So if it possible please post some digital values and their corresponding distance, as it seems you have the measurement results. With this values we are able to provide you an appropriate equation, and with the values we are able to check the suggested solution before posting.



So you also want to adjust the maximum depth of the tank e.g. one tank ranges from 1 ft (100 %) to 13 ft (10 %) and an other one from 1 ft (100 %) to e.g. 7 ft (10 %). Am I right?

BR
Yes exactly 100% right
Please proceed with some hints or lectures.
--- Updated ---

Hi,

I'm curious if the readings are linear (I asume so). If so, someone can solve this problem easily by an equation. The question is, do the readings (digital values) increase or decrease with an increasing distance? Is the relation direct or indirect proportional?

So if it possible please post some digital values and their corresponding distance, as it seems you have the measurement results. With this values we are able to provide you an appropriate equation, and with the values we are able to check the suggested solution before posting.



So you also want to adjust the maximum depth of the tank e.g. one tank ranges from 1 ft (100 %) to 13 ft (10 %) and an other one from 1 ft (100 %) to e.g. 7 ft (10 %). Am I right?

BR
Digital values in percentage are indirect proportional to distance because water tank full means 100% and distance is minimum because ultrasonic sensor is attached upside down in the top of the tank.
 
Last edited:

Hi,

I have ultrasonic sensor values in feet from 1 ft to 13 ft.

I assume you have the DIGITAL values e.g. 1 m = 512, 2 m = 384 m, 3 m = 256, 4 m = 128 .... (just an example). It's much easier to provide a solution with actual measurement results instead of guessing and assuming things.

Or are you using an arduino function which already provides percentage as a result?

Br
--- Updated ---

How have you implemented the map() function?
 
Last edited:
Hi,



I assume you have the DIGITAL values e.g. 1 m = 512, 2 m = 384 m, 3 m = 256, 4 m = 128 .... (just an example). It's much easier to provide a solution with actual measurement results instead of guessing and assuming things.

Or are you using an arduino function which already provides percentage as a result?

Br
I am not using Arduino function but intent to make a function to get result in percentage.
Actual readings are float values from 0.00 to 13.00 ultrasonic sensor can measure upto maximum 13 feet.
Readings start 0.00 , 0.01 , 0.02.........1.00 , 1.01 , 1.02.............2.00.........3.00......till 13.00 in feet.
But I want these readings in percentage in gap of 5% i.e water start to fill the tank display shows 10% water increase some 15% ....20%....25%....30%.....100%.
But I one thing to be noted that percentage and distance are indirect proportional.
--- Updated ---

Hi,



I assume you have the DIGITAL values e.g. 1 m = 512, 2 m = 384 m, 3 m = 256, 4 m = 128 .... (just an example). It's much easier to provide a solution with actual measurement results instead of guessing and assuming things.

Or are you using an arduino function which already provides percentage as a result?

Br
--- Updated ---

How have you implemented the map() function?
distanceFeet = map(distanceValue, 1, 13, 100, 10);
 


You might use the following code to check if the reading is within a certain range.

case 1 ... 1.49:
// 100 %;
break;

case 1.5 ... 1.99:
// 95 %;
break;

...
 
To obtain increments of 5, scale your data values to occupy a range of 1 to 20, truncate the fractional portion, then multiply the remaining integer by 5.
Looks like below?

Code:
  t = pulseIn(echo, HIGH);
 
  // Calculating distance
  h = t / 58;
 
  h = h - 6 ;  // offset correction
  h = 20 - h;  // water height, 0 - 50 cm
 
  hp = 5 * h;  // distance in %, 0-100 %
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top