I am using the Capacitance Sensor Library to get a variable reading form a liquid level probe. The probes input is to an analog pin . What is the value related to what I read on the serial monitor. It is over the value of 1023. How can I map this to output to a PMW pin. I am using that to control a ball valve.
thanks
Hi,
You need to calibrate the values with the tank.
Empty tank and read cap value for tank....usually about 7200. Say it has the value x.
Fill tank and adjust (value read-x)/y to read 100. The value of y is about 29.
So now empty should give 0 and full 100.
G
You've almost answered your own question: Use the map() function. You might also want to use constrain() as well.
Firstly you need to determine the CapSense values for min and max levels.
Then you might want to constrain the sensor reading into that range to avoid using any reading which is out of normal range.
The constrained value can then be used with the map() function to return a result in a range suitable for analogWrite(), which is 0 to 255.
Information on constrain() is here: constrain() - Arduino Reference
Information on map() is here: map() - Arduino Reference
You'd get a better response to your question if you read the forum posting guidelines, where there is loads of information to help you ask better questions.
Hi,
If your input is giving a value of 1023, and indicating that the input to the analog pin is higher,then map function is not going to be much help.
It means your input is higher than 5V so you need to lower the input signal first, before using the input data.
Tom... 