arendst / Tasmota

Alternative firmware for ESP8266 and ESP32 based devices with easy configuration using webUI, OTA updates, automation using timers or rules, expandability and entirely local control over MQTT, HTTP, Serial or KNX. Full documentation at
https://tasmota.github.io/docs
GNU General Public License v3.0
22.15k stars 4.8k forks source link

Set range for analog value with AdcParam #7181

Closed robin13 closed 4 years ago

robin13 commented 4 years ago

I am using an analogue capacitive soil moisture sensor which outputs a voltage. Reading using the Analog input on A0 I get a value between 720 (dry) and 200 (wet). That's small subsection of the entire range 0 -> 1023, but also it is very difficult for me to represent in my head (or in a graph) how "wet" the soil is when I e.g. get the value 250 (quite wet). What I would like is to be able to output the equivalent 0->100 reading. I imagine this being configured with AdcParam something like:

AdcParam 4 200 720 100 0

Where 4 = Remap analogue values. <param1> = lower limit <param2> = upper limit <param3> = value for lower limit <param4> = value for upper limit

In the example I have deliberately set the value for upper limit to a number lower than the value for upper limit because in my example I want 0 to be "dry" and 100 to be "wet", so while <param1> should always be less than <param2>, <param3> and <param4> should just be a range where it is not important which is greater. So going back to the example above, the value 250 would be:

int( ( ( (<param2> - <analogue-value>) / ( <param2> - <param1> ) ) * ( <param3> - <param4> ) ) + <param4> )
or
int( ( ( 720 − 250 ) ÷ ( 720 − 200 ) ) × (  100 − 0 ) ) + 0
= 90

So the result 90 (of 100) is much more meaningful than 250 as a measure of "wetness".

close-issue-app[bot] commented 4 years ago

This issue has been automatically closed because the issue template is missing or incomplete. Filling the template is required so standard questions don't need to be asked again each time. Our ability to provide assistance is greatly hampered if few minutes are not taken to complete the issue template with the requested information. The details requested potentially affect which options to pursue. The small amount of time you will spend completing the template will also help the volunteers, providing assistance to you, to reduce the time required to help you. Please, could you be so kind on completing the issue template in order to have more information so as to properly help you? Thank you for taking the time to report, hopefully it can be resolved soon. Support Information Wiki for more information. Chat for more user experience. Community for forum. Code of Conduct Contributing Guideline and Policy