kisa
Junior Member
Posts: 54
|
Post by kisa on Dec 10, 2018 7:52:21 GMT
Hi (again ), I've been using a ultrasonic sensor to measure the depth of my rainwater tanks, which only reads ok when the distance from the water is under about 60cm, anymore than that and the echoing occurs and the readings become messy. Instead of using ultrasonic, I intend to use a potentiometer attached to an arm that is inside the tank with a float that simply moves the potentiometer as it goes up and down. I'll then add some simple maths to convert the reading to a height in the arduino code. My question is how to incorporate this into the current code. I see there are options to use potentiometers for a number of things including light dimmers and fan controllers. Is it ok for me to use the POTCF method? Is it just a matter of me adding my manipulating into here:- if (curDIM1 != lastDIM1) { dimmer1.set(varDIM1); //set dimmer1 value lastDIM1 = curDIM1; send32 = true; } What is the preferred resistance potentiometer to use? Thanks. KISA
|
|
|
Post by papa on Dec 10, 2018 22:11:17 GMT
kisa: I've been using a ultrasonic sensor to measure the depth of my rainwater tanks, which only reads ok when the distance from the water is under about 60cm, anymore than that and the echoing occurs and the readings become messy. papa: Yes, did you see this thread where I tried an ultrasonic sensor node to monitor up to 2 feet of water in my sump cistern & was dissatisfied? Did you then see this thread where I next used spaced probes to measure water levels & amplify the signals with transistors? This has worked very well for me. The only issue was after a year, I needed to remove tarnish from the probes. I adapted the idea from circuits in India used for rain tanks. You might consider this approach, spreading the probes over the distance of your tanks' depth. kisa: "Instead of using ultrasonic, I intend to use a potentiometer attached to an arm that is inside the tank with a float that simply moves the potentiometer as it goes up and down. I'll then add some simple maths to convert the reading to a height in the arduino code. My question is how to incorporate this into the current code. ... papa: Sounds interesting, I'll need to think about it. Let me know what you think about the above water level probe approach.
|
|
kisa
Junior Member
Posts: 54
|
Post by kisa on Dec 11, 2018 7:21:08 GMT
I have seen the ultrasonic info previously, I just wanted to try it out as I could run it from the middle of the tank and thought that would minimise the reflection being further away from the egde. I was also going to see if I could play with the power and timing on the ultrasonic devices to maybe help with the reflections, but never got around to seeing if that was possible and decided time would be better spent using the variable resistor. I've read and seen the probe idea quite a while back (in a few places), but I'm after a lot more accuracy than that. I have 15,000L and even with a fair bit of rain it doesn't raise a lot. I'm confident a variable resistor will work well on an arm (I already have and am going to use a length of PVC pipe with a float on the end). I just need to work out where in the code to just pick up the voltage, alter it as needed, then send it.
|
|
|
Post by papa on Dec 11, 2018 21:02:26 GMT
OK, I also found ultrasonic did not work as hoped in measuring distance to the surface of a liquid. One thought you might try for the ultrasonic: What if you hung the ultrasonic sensor over the middle of the tank? Then have a floating wooden or plastic board that keep floating on the water directly below the sensor. Would the sensor be more accurate bouncing signal off a flat, hard surface? I don't know. My sump cistern had no room for that.
I'm not picturing how to translate (physically) from the float raising to moving the potentiometer,especially since in a large tank, the float will move a great distance vertically & the potentiometer will move a much shorter distance. However, it sounds like you have ideas about that. There are linear potentiometers that slide in a straight line rather than be turned by a knob. Maybe one of those might work.
I can provide some suggestions about the potentiometer code.
|
|
|
Post by papa on Dec 11, 2018 21:50:05 GMT
Potentiometer Code SuggestionsStart with the latest node choices sketch & initial customization found in this post. The POTDIM option is for dimming lights via potentiometer control. However, I believe you can ...
UNcomment #define POTDIM & use much of the code as is. Find its code by searching for "ifdef POTDIM" Some of that POTDIM code with added comments & suggestions for possible changes: #ifdef POTDIM //Potentiometer to control a Dimmer. Brump added. #ifndef DIM1 // ?? disable/comment this line & the next two lines #define DIM1 #endif#define potDIMPin A2 //Potentiometer on A2. where to connect potentiometer wiper, could be another analog pin#ifdef POTDIM if (send69) { // When send69 is true, sends the mapped potDIMRead integer to an OpenHAB item mes.devID = 69; mes.intVal = potDIMRead; // brump send69 = false; txRadio(); } #endif #ifdef POTDIM //brump added potDIMAnalog.update(); potDIMRead = map(potDIMAnalog.getValue(), 0, 1023, 0, 100); // expects pot reading 0-1023, translates to 0-100 if (potDIMRead < 0) { potDIMRead = 0; } if (potDIMRead > 100) { // if you change 100 in above (), change these 100's potDIMRead = 100; } curpotDIM = potDIMRead; if (curpotDIM != lastpotDIM) { delay(5); if (potDIMAnalog.hasChanged()) { send69 = true; // pot reading changed so flags to send pot reading to OpenHAB item varDIM1 = curpotDIM; } lastpotDIM = curpotDIM; } #endif #ifdef POTDIM // Brump added. send69 = true; // Makes sure pot reading is sent at least every 60 seconds (TXinterval)#endif // ifdef POTDIM
As it is, the above will send a mapped pot reading (an integer 0 to 100) to an OpenHAB item. If you analog read the pin without mapping you get integer 0 to 1023. You may need an OpenHAB rule to convert the pot reading to liters or meters deep or whatever you need.
I believe the above gives a good start for you. Please report back what you learn, positive & negative, in working on this project. That is, share your node wiring, your float & potentiometer connection, & your code. What worked & what did not?
|
|
kisa
Junior Member
Posts: 54
|
Post by kisa on Dec 12, 2018 0:55:40 GMT
Thanks again Papa, that's great. I haven't done any coding in the OpenHAB area, so I best get into it . Regarding the ultrasonic suggestion, I found testing the ultrasonic on water to be very consistent, particularly when it was calm. I have 3 connected rain water tanks, the one I measure in is not the same one the rain enters, so it stays very calm as it's filled from the bottom. I think the biggest issue is reflections from the sides of the tank or even multiple bounces off the water and ceiling, but it is hard to test that. Placing something in the middle on the water may be a way to see, but I don't really have anything to do that with right now. I'll come back with any useful information I find out. In regards to the temperature sensors you helped me so much with previously; they've been running since then all around inside the house, in the ceiling and a couple outside (about 5 months now). They are all working well, though I've moved most of them to power supplies (and will do the rest when I can) as the batteries (2 x AA) would only last a bit over a month even when the Arduino Nano's were running in the efficient mode you set up, which I think from memory, only wakes them up every 5 minutes or so. Over a month is still great, but I wish to measure for a couple of years, so best I go to mains power
papa: Kisa, Thanks for the feedback on using ultrasonic sensor to measure distance to water surface. Thanks also for feedback on your using the temperature sensors. That helps motivate me & maybe helpful information for other forum readers.
|
|
kisa
Junior Member
Posts: 54
|
Post by kisa on Dec 12, 2018 9:52:36 GMT
Got it working and am getting values between 0 and 100 on my grafana graph You mentioned mentioned creating an openHAB rule to correct the values. I've never done that, is that something I can do on the Linux box (the box that communicates with the RFM and is also the network connection) so the value is correct before it goes out on the network?
papa: Numeric values may be sufficient for you. You may only need an OpenHAB rule if you want to convert the number values to something else for User Interface display.
|
|
kisa
Junior Member
Posts: 54
|
Post by kisa on Dec 12, 2018 10:14:28 GMT
Got it working and am getting values between 0 and 100 on my grafana graph
Can I set the range to be 0 - 1000 simply by doing this:- potDIMRead = map(potDIMAnalog.getValue(), 0, 1023, 0, 1000);
papa: I believe this is what you need to do:
Determine the highest value you will probably get from reading the potentiometer. In the above line of code, put that value where the 1023 is now.
So for example, if the highest probable value is 100, then I believe the code would be:
potDIMRead = map(potDIMAnalog.getValue(), 0, 100, 0, 1000);
I believe this would receive a range of values from 0 to 100 & map (convert) them to a range of values from 0 to 1000.
Experiment with the code. Should be no risk of harm.
|
|
|
Post by papa on Dec 12, 2018 15:48:33 GMT
kisa, I responded to your last three posts within the posts themselves. I may not be very available for the next few days.
I'd appreciate your posting on this forum what you learn from this project, what worked (& how you accomplished that), what did not work, etc.?
|
|
kisa
Junior Member
Posts: 54
|
Post by kisa on Dec 13, 2018 8:02:03 GMT
Regarding this "potDIMRead = map(potDIMAnalog.getValue(), 0, 1023, 0, 1000);", I don't quite understand what you mean. I wish to get a scale of 0-1000 (or 0-1023 is fine) so I can increase the accuracy of the movement. I'm not worried at this stage of the start and end values, I'll sort them out once it's all in the tank. Initially I just want to get the most out of the accuracy, so having a range of 0-1000 would be good. You mentioned originally that I could analog read the pin, it that easy to do within the code I'm already working with?
I just sorted it
I modified this part:-
//potDIMRead = map(potDIMAnalog.getValue(), 0, 1023, 0, 1000); // commented this out as the mapping was no longer needed
potDIMRead = potDIMAnalog.getValue(); // Added this line to grab the raw value
if (potDIMRead < 0){ potDIMRead = 0; } //if (potDIMRead > 100){ / commented these out to remove the 100 limit // potDIMRead = 100; //}
|
|
|
Post by papa on Dec 13, 2018 12:38:48 GMT
Kiss: I modified this part.
Papa: Yes, I made a parallel suggestion above to replace all instances of 100 ( in your case with 1000)
|
|
kisa
Junior Member
Posts: 54
|
Post by kisa on Dec 14, 2018 8:45:03 GMT
I've completed it and it's now in my tank (which is now full due to a lot of recent rain). I took photos of the assemble if you're interested, though I don't know how to share them on this site.
|
|
|
Post by papa on Dec 14, 2018 19:36:17 GMT
kisa: I've completed it and it's now in my tank (which is now full due to a lot of recent rain). I took photos of the assemble if you're interested, though I don't know how to share them on this site. papa: congratulations. fast work. Yes, I am interested in seeing your float & potentiometer assembly. how to share photos: 1) Post Quick Reply to make a new post 2) At the upper right of the new post, click the edit button 3) In the post, place your cursor where you want a picture. At the upper right of the post being edited, click add attachment. 4) In the dialog box for attachments, click add files & navigate to the folder holding the pictures & upload one at a time. 5) When the post's cursor is where you want a pic, click a photo file's insert button. 6) Click done button when finished with attachments. 7) Click Save Changes button at the lower right of post being edited.
Be aware of size limits for attachments (you may need to resize with a photo editor). Also we are permitted only 3 attachments per post
|
|
kisa
Junior Member
Posts: 54
|
Post by kisa on Dec 14, 2018 21:56:51 GMT
Here are the pictures of the float, arm, & potentiometer.
<< Picture 1
<< Picture 2
<< Picture 3
|
|
|
Post by papa on Dec 15, 2018 0:38:21 GMT
Looking at Picture 1 above & extending the arm via Picture 2 & 3, I may start to understand how this functions. Am I correct: that the float is on the free end of the arm AND the potentiometer's "knob" is the pivot point for the other end of the arm? So that when the float raises & lowers a potentially big distance on the water level, the float & arm assembly turns the potentiometer a relatively short distance. Again is that correct so far? I suppose that you mount the potentiometer side of the arm at the top of one side of a tank, high enough that the pot won't get wet. Is that correct?
Neat idea especially perhaps if a tank is open enough for the float arm to work without getting caught.
From what you said above, I believe you might get a reading of 0 at or near the tank bottom & 1000 at the top. Correct?
Is this giving you the smooth gradient of accurate readings that you wanted?
You could probably adjust parameters of the mapped analogRead to tune the software to each mechanism & tank. For example, let's say when the float is on the tank's bottom you get a pot reading of 10 & when the float is at the very highest point you get a pot reading of 888. To get a resulting range of 0 to 1000, I believe you could make the forumula:
potDIMRead = map(potDIMAnalog.getValue(), 10, 888, 0, 1000);
|
|
kisa
Junior Member
Posts: 54
|
Post by kisa on Dec 15, 2018 6:48:44 GMT
That's pretty much all correct. The black plastic disk sits flat on top of the tank and the pot is sitting about 10mm above the water (at its highest point). The movement is only about half the movement of the pot. I've got the top value which is 590 and I'll know the bottom value once it gets down there . It won't be zero, but pretty close, I didn't want to aim for zero in case it was a bit out. What ever the value I can simply set it as the zero point.
Setting the potDIMRead is good to know, though I'll probably just make the adjustments in openHAB and/or Grafana. I also need to find out and add the equation to compensate for the arc of movement as the water goes down vertically, this will cause a non-linear change in the voltage reading. Looks like a simple sin(theta) will do the trick.
Following that I'll probably change the value to indicate how many litres are in the tanks as opposed to the %
One potential minor issue is that the tank width is less than the height, so it may not be able to read the lowest point. The saving grace may be that due to the pump at the bottom and that the water can't get all the way down, so it may be ok. Also I have to keep an eye on the arm it is does hang freely above the water when it gets low and that it raises in the right direction once it does up again, but I'll worry about that when the time comes.
So far it's in and working fine.
|
|
|
Post by papa on Dec 15, 2018 20:52:45 GMT
Thanks, kisa, for mostly confirming my analysis of your approach & providing more details.
kisa: "One potential minor issue is that the tank width is less than the height, so it may not be able to read the lowest point. ... Also I have to keep an eye on the arm it is does hang freely above the water when it gets low and that it raises in the right direction once it does up again"
papa: Hmm, maybe you could make your arm a little differently to address this, perhaps shorten the main arm & use an elbow at the end to add another arm part with the float at its end. Could you use something like this to create a fuller range of motion for the arm & potentiometer that would not hang up on other aspects of the tank? Interesting mind puzzle & exercise in what we call "farmer engineering" around here.
|
|
kisa
Junior Member
Posts: 54
|
Post by kisa on Dec 15, 2018 22:05:56 GMT
Possibly, I'll have to think about that. I've go a number of other tasks on the go I need to also complete, so I'll probably leave this for now and see how it goes. One is building a larger shed out of two smaller ones (a type of farmer engineering) .
|
|