newcomer with some questions about the basics

Hello all,

This will probably be apparent shortly, but I am a total newcomer to arduino - and physical computing, microcontrollers, etc. in general.

I’d like to build a controller to automate a fish tank. Specifically, the following sorts of things:

  1. turn different lighting units on and off at certain times of the day
  2. use PWM to dim the lights such that they turn on, ramp up over a few hours, ramp back down over a few hours, then turn off
  3. use PWM to slowly ramp DC motors up and down, to create wave-like water movement
  4. monitor float switches and activate a pump when water level falls below a certain point, to replace evaporation
  5. monitor temp, and turn heater(s) on and off at certain set points (with some hysterisis, so it doesn’t just flutter on and off at the set point)
  6. similarly, monitor pH and do different things in response

I have been reading this forum and other resources on the 'net and I have the feeling that all this is possible, but I’m having trouble visualizing the entire system. First of all, a gut check that all these things are possible?

Secondly, it seems like all of the examplesand tutorials I’m finding are of simple systems - hardware and code to do ONE of the above things at a time. I’m probably using the wrong terminology here, but what is the controller’s capability to multitask? Can it ramp multiple PWM outputs up and down at the same time, all while waiting for a float switch to trigger, and then respond to that, while continuing to ramp the PWM?

Again, I’ve seen examples of code where a loop easily generates the oscillating PWM signal, but can an arduino do that in the background while doing other things?

Thanks in advance for any help or direction!

Well, it’s doable I suppose… except perhaps the pH monitor (I haven’t seen a digital one anywhere… I’ve always used litmus paper (good old bio class :)) It seems like quite a lot, but I would get an arduino mega, just in case (you’ll be using a lot of pins)… Also, start basic - try each of the seperate “systems” you’ve described seperately first, then start adding them together to finish off your product.

P.S.: For waves, don’t use motors, use servos, and swing them back and forth with paddles, simpler circuit and better results…

You really love your fish to spoil them so much :smiley:

Its all possible with the Arduino. I also agree that I don’t know so much about pH and if you could do it, you might need some expensive transducer. As for the rest start by building 1 feature and coding it as a function that gets called in loop()

Then add the next feature and incorporate it into its own function. The modular approach or stepwise refinement where you start simple and get progressively more complex as you go along…

My recollection of pH sensors is one of extremely high impedances, of the order of tens of mega-ohms, but my recollection is very, very old!

Thanks for the replies.

As far as the pH sensor, I’ve got to imagine it’s not too challenging. I mean, you can buy a commercial pH monitor with probe for $100 or so, and even if a DIY solution cost me more than that it wouldn’t be a big deal. Plus, I’ve read about other people that built DIY fish tank controllers similar to this with pH sensors, so it’s gotta be possible! Then again, I don’t really know what I’m doing when it comes to this stuff! ;D

Regarding the development approach and programming to put this all together. I indend to develop these functions one at a time, then eventually combine them all. But the “combine them all” part still strikes me as challenging, since I just can’t picture in my head how to write code to get the arduino to do lots of things at once. Would it look something like this example? Excuse the silly pseudo-code:

First, write a function for each process

light_control_function {
check the time
if time is “morning” turn the lights on
if time is “morning + n” then fade the lights higher by some factor of n
if time is “night - m” then fade lights lower by factor of m
if time is “night” then turn lights off
}

wave_control_function {
step PWM signal to wavemaker up or down X amount per second
}

level_control_function {
if float switch is open, turn dosing pump on
if float switch is closed, turn dosing pump off
}

temp_control_function {
if temp is below x, turn heater on
}

Then, you would have a loop in the main function that would just execute each of these:

loop {
do all functions
}

Can the controller maintain output on a specific pin even when that code is not active? For example, if the first function called in the main loop was to check the time and fade the lights up or down, I imagine it would work by calling the analogwrite function on the PWM pin controlling the dimmer for the lights. But then when it was “done” with that function and moving on to the function to check temperature, would it keep the light’s PWM pin value constant? Or does that pin shut off when the code is “done?”

Also, how would you control the loop? Would you typically program some time delay into it? Or, would you do all the time handling in each function, then let the controller just step through them over and over again?

Hopefully these questions make sense. I don’t yet feel like I speak the language of arduino so some of this might be so basic it’s a non-issue!

If you call digitalWrite() or analogWrite() then the pin will stay in that state until you set it to otherwise.

There might not be any need for a delay, you could just poll your sensors however many times per seond your code runs.

You might run into the circumstance where you want to react faster than 1 loop of your code would take, there are a few ways you could cope with such a situation but I’d wait till it’s a problem. (One easy way that might suit might be to not poll every input every iteration).

Ok, that info about analogWrite() and digitalWrite(). I had figured that was the case, but, like I said, I’m very new to all this. :smiley:

Polling sensors and responding on a certain interval raises another question. I see that there are chips people have added to arduinos such that they “know the real time” in a sense. What is the timekeeping ability without this additional chip? Assuming I am running lights off time of day (i.e. “turn on at 8 PM”) instead of some preset interval (i.e. “turn on 12 hours after you last turned off”) then I’m guessing I want one of the external time chips. Is that an accurate statement?

Also, regarding a wavemaker. There are lots of commercial units out there that feed PWM to a DC motor to ramp it up and down in speed every few seconds, so I was assuming I would duplicate that approach. But, the thought someone mentioned above (use a servo to move a paddle) is interesting. The first tank I’ll be trying this on will be small (15 gallons) but eventually I want to use this controller on a large tank (300 - 400 gallons) so at that point, I would need a pretty big paddle and a really beefy servo. The only sources I know of for servos are for little hobby servos from R/C stuff, does anyone have a source for more robust servos? Or even some sort of linear actuator?

to paraphrase my Physics 101 professor:

give me a long enough lever and a place to put the fulcrum, and I can move anything.

that is to say, the small hobby servos are fine – use some gearing and/or levers to actuate the “wave arm” from them.

Thanks for the feedback. While I approach all of this, I am already starting to design a servo-operated wave box in my head, so we’ll see.

Any thoughts from anyone on the issue of timekeeping? Does/can the Arduino keep accurate time without external parts?

In the long term, there is no internal timekeeping but I’ve tried a couple of Duemilanoves and found them to be accurate to a couple of seconds a day using the millis() function.

give me a long enough lever and a place to put the fulcrum, and I can move anything.

Didn’t Archimedes say that? Or perhaps it was newton.

I don’t know… and I haven’t tried googling it. I’m quite sure it didn’t originate with my Physics 101 professor (who, as it turns out, was neither Newton nor Archimedes). :wink:

Regarding time keeping:
http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2688

Any thoughts from anyone on the issue of timekeeping? Does/can the Arduino keep accurate time without external parts?

There is a library for handling date and time on Arduino here:
http://www.arduino.cc/playground/Code/DateTime

With a standard arduino board it is accurate to a few seconds a day.

So, without a hardware clock (like the DS1307), you will be a few seconds per day off (potentially), and your internal clock will reset every time power is tripped.

While, with a hardware clock, you get more accurate timekeeping, plus the time will be correct if power is tripped.

Correct?

Thanks yet again for answering these questions.

So, without a hardware clock (like the DS1307), you will be a few seconds per day off (potentially), and your internal clock will reset every time power is tripped.

While, with a hardware clock, you get more accurate timekeeping, plus the time will be correct if power is tripped.

That is correct, but although the crystal in a hardware clock could be a little more accurate than the arduino crystal, it can still drift a second per day.

As long as your definition of “hardware clock” includes an associated crystal and backup battery (and not just the DS1307 chip by itself), you get more accurate timekeeping, plus the time will be correct if power is tripped, as you say.

There are lots of examples for you to study, for example http://www.sparkfun.com/commerce/product_info.php?products_id=99.

Heu… no my post or don’t want to hijack the post… but is this not want you wnat to do ?

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1240000018

Awesome, thanks. That project duplicates a lot of what I’m trying to accomplish.