Go Down

Topic: Need help with simple code for driving a motor and monitoring a "water sensor?" (Read 2325 times) previous topic - next topic


Hi guys, I'm very new to Arduino and I'm looking for some help or someone to hopefully spit out a few lines of code for me.  I have C and matlab training, but its been about 7 years since I've done any programming.  I know what I'm looking to accomplish is very simple, I just don't have the time to read through a bunch of tutorials and spend a few nights trying to figure out exactly how to write the code for this.

Background:  My GF's is a teacher of a special Ed class who started an organic garden to raise money for classroom materials, b/c our education systems suck.  I've been tasked with creating an automatic watering system to make sure her garden doesn't die from lack of water.  As cheap as possible.

The Plan:  There will be 2X 55gal drums that will collect rain water from the school's gutters. I'll run a cheap garden hose between the bottom of both drums to keep the water levels even, with a "T" fitting between them going to a 12V RV water pump that draws up to 4 amps.  I need 2 portions of code, one basically wasting a day's worth of time then turning on the water pump for 10mins a day.  I was thinking it could just count to what ever number was calculated by the Arduino's clock rate and 85800secs/day, which = 23hrs and 50mins.  It would then flip on the pump and count to what ever number was calculated with the Arduino's clock rate and 600secs which =10mins.  Seems simple enough.  I will be using the output from the Arduino to a transistor to a relay to the motor.  The entire system will be powered by a 12V deep cycle battery and a trickle charge solar panel.  I realize I will probably have to adapt the 12V to whatever this bad boy needs, I'll use a voltage regulator.  The second portion of code I'm looking for is to monitor the water level in 1 position near the bottom of the barrels to prevent the motor from turning on when the water source is depleted.  Also, I need recommendations on the cheapest Arduino that would accomplish this task.  I don't care about expansion possibilities bc this will be the sole purpose of this particular module.

Things I need from you guys:
-Recommendation on which Arduino module would be best/cheapest
-Code for timing and controlling motor
-Code for monitoring whether the water sensor is submerged or not
-What I can use as a water sensor

Once I have a starting program, I will understand it instantly and should be able to fine tune it myself with a few tuts and questions.  Starting is the hard part.  Any and all info is welcome and VERY appreciated by me and about 20 other people. 



you can make a arduino for less than 10$ on a bread board or protoboard: http://arduino.cc/en/Main/Standalone

i would use a RTC chip to get the time of day, not count like you say.

search google for "arduino water level sensor" or  "arduino water level indicator"
http://dduino.blogspot.com all my Arduino/electronic projects!!!

{NEW} Getting Started, Learning, Reference + FAQ PDF!!:


I guess I can't speak for everyone, but a lot of us around here are not answering questions on this site for a living.  Actually, I'm not sure how I should say this, but personally I find your request a little off-putting.

"Tell me what to buy and write all my programs for me, okay?"

I think you would get a much better response, at least from me, if you took a stab at each of your questions yourself first rather than asking us to tell you what to buy and give you the code to run it.

While most of us are here to try and help, we are not servants.

I'll get you started.  A good place to begin would be an Arduino UNO.  Go buy one and take a crack at what you want to do.  If it fails, come back, show us what you did, then we might be able to help.

Jack Christensen


Thanks sirbow2, I'm checking into those now.  I figured there was a more efficient way of keeping track of time, but that's how new I am to this Arduino world, and forums for that matter.

BillO:  I wasn't expecting anyone to answer if they didn't like my post or lack of effort.  I work full-time in a traveling job and am never at home where all of my geek stuff is and will only have about 2 maybe 3 days to implement this entire project, when i fly home for the weekend.  I only have an ipad and an iphone with me.  I realize you all don't just sit around and write code for people for fun, I was asking for anyone that had the time and desire to write something basic to help me out.  As a favor.  At least to get me started so when I got home, I'd be able to hit the ground running.  I did the best I could to give all the info about my application and it seemed like a fairly simple program.  I guess I could have mentioned that part of my situation but didn't think it was important/necessary.  Ok, so the Arduino UNO would be a cheapish module that can do what I'm trying to do?

Jack Christensen:  Ok, thanks for the heads-up.  I wasn't sure exactly which section my post fell under, considering it was several. 

-I usually answer questions so I'm not good at asking them..


I realize you all don't just sit around and write code for people for fun

i do to practice my skills :P IF i were to help you out, i need to know what exactly you are going to use in this project. ex what works best for you for sensing water level, how your going to do time, how big is this motor you are speaking of?

Edit: I saw your duplicate thread in the programming section(forum hint, don't double post, you get raged upon :p) . The arduino can count using millis() for 49 days before it starts over. And it counts in milliseconds not seconds, so; 85,800,000 millis for a day. VERY simply we could just make a while loop that waits for a day:

while(millis()<85800000+lastPumpTime) do nothing
lastPumptime = millis() its been a day, record time
digitalWrite(pump, HIGH); turn on pump
while(millis()-lastPumpTime<600000) wait 10min
turn off pump

the code isn't 100% but almost. I'm guessing a relay would be best for switching the pump. Water level would be quite easy to implement too.
http://dduino.blogspot.com all my Arduino/electronic projects!!!

{NEW} Getting Started, Learning, Reference + FAQ PDF!!:


Schweet!  That is pretty much exactly the type of code I had in mind.   :smiley-mr-green:  I'm learning the rules of the forums quickly, the hard way.  haha. 

I'm open for suggestions on water sensor, read the last paragraph of this page: http://arduino.cc/playground/Main/CoffeeTronics, por favor.  I plan on mounting a sensor about 1" higher than I attach the drain hose, at the bottom of the barrel.  i guess it could just be a piece of exposed wired.  basically, it stays wet and everything works as normal until it becomes dry in which case the Arduino will just skip around the "turn pump on" portion of code and start its cycle over for the next day.  It would stay off until the barrels filled back up, protecting the motor.  So it looks like maybe some code that reads capacitance?  I'll look around some tomorrow and read/attach any info I can find on it. It's pretty much bed time. 

For counting time, accuracy isn't very important.  All I really care for it to do is be accurate to ~30mins/year.  As in, I wouldn't care if it lost 30mins of time in a year.  Considering this would be doing nothing besides counting, I imagine it would stay fairly accurate. 

I'm good on the electronics part, I'm going to go from Arduino->transistor->relay->motor.  I'll find an appropriate transistor to switch the relay.  I'll use a 5V voltage regulator to get power from a gigantic deep cycle battery also used to power the 12V 4amp motor. 

-Side thought.  On the RTC, linked below, it appears that i can set it up to count days and have a daily alarm.  Couldn't I just use that daily alarm as my trigger to a circuit that drives a motor high for 10mins using a 555 timer and a counter circuit?  Do you think it would be better to keep the time and make the entire control circuit logic based instead of micro-controller based?

Links to hardware:
motor:   http://www.ebay.com/itm/RV-Water-Pump-12V-45W-w-Automatic-Switch-4-0L-Min-1206-/150772585853?pt=Motors_RV_Trailer_Camper_Parts_Accessories&hash=item231abf157d&vxp=mtr

motor relay:  http://search.digikey.com/scripts/DkSearch/dksus.dll?WT.z_header=search_go&lang=en&site=us&keywords=z217-nd&x=0&y=0

if i use the RTC:  search.digikey.com/us/en/products/PCF8583P%2FF5,112/568-1084-5-ND/735698



To make things simpler, can you elevate the barrels and use gravity feed to get water flowing? Then, all you need is a powered valve the arduino can instruct to open. Better, you don't care about water level issues in this scenario.

Go Up