aquarium control

hi all
i need to control high power led array,
i have ordered arduino ,and lcd display shield,and RTC module.
did not get it yet,it will take another week.
i am a noob with software,and that kind of controller,
i have no idea how to connect,and the software is a bigger problem.
electronics if my field,but programing is not.
i need to simulate dusk and downe,with 2 PWM outputs,
no problem with fet power drive,i can handle it.
i dont know even what size of help i am asking...
what can you do to help ?

  • sorry for my bad english*
    Thanks
    Zahi

There was a post recently about aquarium lighting:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1246646894/0
http://frugalreef.com/wiki/DIY_LED_Aquarium_Lights
http://frugalreef.com/wiki/DIY_Reef_Controller

If you can take care of the mosfet/constant current regulation yourself, then you only need to know this:

The standard Arduino (duemilanove) has 6 hardware PWM pins that run at 500Hz and can be manipulated with the analogWrite(_pin,_byte) function. If you should need a higher frequency you'll have to manipulate some cpu registers, but there are posts about that on the forum too.

Thanks,
i will look into that and let you know,
for the frequency issu, why should i need a higher frequency ?
500 Hz is a problem ?
thank you

I don't know if 500Hz are OK for you. You're the one who will build the mosfet driver. I just mentioned it as in the forum post I linked the author was having problems with a commercial LED driver and 500Hz. He said it would flicker at low duty cycles. This may very well be a problem of the driver.

i do not see any problem there,
i know about driving led's with lower Hz,
and it was working fine.
what about progrmming this thing ?
can you layout for me what sources will be free
on the arduino,after connecting the RTC and LCD dispaly ?
i want to add temp control,and a pump or two output.
i mean,what i\o of the arduino will be busy with modules connected ?
thank you so !

if you use an RTC chip that can talk I²C (DS1307 RTC), this will cost you the "analog 4/5" pins (ADC 4/5 shared with SDA/SCL).
connecting an LCD in 4bit mode will cost you 7 lines ( LiquidCrystal - Arduino Reference ). You can choose any pins you like expect "digital 0/1" (UART) unless you can live without PC communication. Also I'm not quite sure if the arduino libs don't always monopolize these pins, even if you don't explicitly start any serial stuff.

here you can see all I/O pins nicely:

the analog 0-5 ADC lines can also be used as GPIO pins. A0-A5 can be accessed as digital 14-19. of course the pin numbers I've used only are valid as long as you use the Arduino specific functions. If you'll be using more low level stuff, the Arduino is just a normal ATMega168/328 AVR chip.

thanks madworm
the rtc module is this :
http://cgi.ebay.com/I2C-RTC-I2C-Real-time-Clock-RTC-BASIC-STAMP-PIC_W0QQitemZ150302042102QQcmdZViewItemQQptZLH_DefaultDomain_0?hash=item22feb327f6&_trksid=p3911.c0.m14&_trkparms=65%3A12|66%3A4|39%3A1|72%3A1205|293%3A1|294%3A200

and the lcd is this :
http://cgi.ebay.com/ws/eBayISAPI.dll?ViewItem&ssPageName=STRK:MEWNX:IT&item=290326040339

so,

2 for RTC
7 for LCD display
2 for PWM output
1 input to monitor led's DC current
1 input for water level float
1 out for water compensation solonoid valve
am i correct ?
any left free ?

I'd make sure the LCD module doesn't come with all the headers soldered in. Right now it seems it is blocking all the ADC pins (from what I can see in the picture on ebay). Without knowing which pins exactly the LCD module uses it's impossible to go any further. Only 6 of the GPIO pins have PWM, so if the LCD uses all of them....

I'd get a schematic before you buy. Right now it's just guessing.

Here's some example code for the RTC chip: I2C Real-Time Clock

:-/
i have paid...it's on it's way...
i am woried about the progrmming,
is it doable for a noob like me ? ;D
i dont even know where to start...
is it much of a problem for one of you guy's
to write or something, a code for me ?
can i just cut and paste a code ?
how do i connect together a few codes,
each controls another function i need ?
what did i got my self into ... :-[

As soon as you have the arduino board, the best thing to do is have a look at the examples !

If you open the arduino software and click on File-->Sketchbook-->Examples you will find what you need. Anything that is not in there you'll find on the PLAYGROUND - interfacing with hardware / interfacing with software. A lot of what you desire has already been done :wink:

Other than that it is just C/C++

99% of what you need will just be basic control structures:

example:

#define __solenoid_pin 5      /* this is digital pin 5 */
#define __analog_sensor_pin 0 /* this is analog input pin 0 */
#define __sensor_threshold_H 500
#define __sensor_threshold_L 450
#define __led_pin 6           /* digital pin 6 can do PWM (8bit resolution) */

void setup(void) {
  pinMode(__solenoid_pin,OUTPUT);
  pinMode(__analog_sensor_pin,INPUT);
  pinMode(__led_pin,OUTPUT);
}

void loop(void) {

  int sensor_value;
  sensor_value = analogRead(__analog_sensor_pin); /* this will return values from 0 to 1023 - 10bit ADC */
  analogWrite(__led_pin,sensor_value/4);          /* LED brightness will reflect sensor value */

  if ( sensor_value < __sensor_threshold_L  ) {
    turn_solenoid_on();
  }
  else if ( sensor_value > __sensor_threshold_H ) {
    turn_solenoid_off();
  }

}

void turn_solenoid_on(void) {
  digitalWrite(__solenoid_pin,HIGH);  /* this will need an NPN transistor + free running diode to drive a solenoid */
}

void turn_solenoid_off(void) {
  digitalWrite(__solenoid_pin,LOW);
}

Talking to the RTC will be more complicated, but there are examples too.

The Complete Beginners Guide to the Arduino

Thank you,
with your support i think i will make it,
let's wait for the boards...

hi
i got the arduino,and the display shield.
when i connect the disply,it takes all the pins,
do i have to soldier wires to the pin i need ?
can anyone direct me to a code of controling
led PWM via RTC ?
this is for high power aquarium lighting.
thanks

hi
only once i have succeeded to upload a sketch,
after that i get this error :

avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51

i have searched the forum for reference ,no luck...
can any one throw me a rope .. ?

Read through this thread

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

And see if any of the suggestions fix the problem.

same problem,
was able to upload 3 times,basic sketch,
since, i get this

avrdude: stk500_getsync(): not in sync: resp=0x00
avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51

i know this is the 4536 time you see it ...
but,i can not do nothing with the arduino now.

system is XP and windows 7
com8 , 9600

went threw all the threads,
and the one you posted,
about that subect,
none helped :-[

thanks

finally !!! problem solved :slight_smile:
I can upload sketch to the arduino ! ;D
my problem was one of the system firewalls...
I stopped the windows fire wall and the kaspersky and windows defender, all completely,
and the arduino started to upload immediately ::slight_smile:
I started these programs again, and I can steel upload,
it is like the beginning now, I am sure that in a few hours
one of this walls will kick back in, and block the com again.
I will try to isolate which one later on...
now back to the sketch I need
thanks

Use Linux :wink:

I'm waiting for the parts to do what basically what your doing (adding in sensors too), but I'd love to hear how it turns out.

:slight_smile:
Linux is not for me...thanks,
but i would love to share about the project.
i am a noob to the programming thing so
this is my bottle neck right now.
i bet this link will give you a kick start,
please let me know what you think,
i really need all the help i can get :sunglasses:
thanks

http://reefprojects.com/wiki/Main_Page

Hi, I,ve just purchased an arduino duemilanove + motor sheild and started off with my first programming. At first I was a bit confused where to start but now i think I got a bit of a grip on it (I hope) :-/. Anyway I know when I run the programm on arduino, however I was not quite sure how to define the 6 analog pins A0 -A5. Earlier in this post the following was stated:

"the analog 0-5 ADC lines can also be used as GPIO pins. A0-A5 can be accessed as digital 14-19. of course the pin numbers I've used only are valid as long as you use the Arduino specific functions."

Now the below is part of my program where I using pin 14 (A0)as an input from a micro switch and 15 (A1) as an output to an optocoupler to control a relay. From what I understand, these are set as digital by default when refering to them by 14 & 15 and analog when refering to them as A0 and A1, or do I need to declare in the programm that these should be so just the same since they are analog? :-/

#include <AFMotor.h>

AF_Stepper motor2(48,2); //48 stepper motor connected on port 2
AF_Stepper motor1(48,1); //48 stepper motor connected on port 1
#define BUTTON 14; //microswitch connected on pin 14
int val = 0; //Store state of pin 14
#define relay 15; //connected on pin 15

void setup() {
pinMode(14, INPUT); //set pin A0 for microswitch as input
pinMode(15, OUTPUT); //set pin A1 for relay as output
Serial.begin(9600); //setup library at 9600 bps
}
void loop() {{
// Routine to set home position if stepper is not homed
val = digitalRead(14); //read input value from microswitch and store it
if (val = LOW); // when signal from micrswitch is OFF
motor2.setSpeed(100); //Set stepper speed at 100 rpm
motor2.step(100, FORWARD, SINGLE); // Jogs stepper off limit switch incase of overshooting
motor2.step(100, BACKWARD, SINGLE); // returns stepper home until microswitch comes ON
motor2.release(); // Releave power supply on motor
}

char incomingByte;
if (Serial.available() > 0) // Waits for signal from serial (USB port)
incomingByte = Serial.read(); // Reads incoming byte from serial (USB port)
val = digitalRead(7); //read input value from microswitch and store it
if (val = HIGH); //If signal from micrswitch is ON
digitalWrite(15,HIGH); //Switches pin 8 (relay) ON

motor2.setSpeed(40); // Set stepper speed at 40 rpm
motor2.step(100, FORWARD, MICROSTEP); //run stepper forward
motor2.step(100, BACKWARD, MICROSTEP); //run stepper backward home
motor2.release(); // Releave power supply on motor
digitalWrite(15,LOW); //Switches pin 15 (relay) OFF
motor1.setSpeed(40); // Set stepper speed at 40 rpm
motor1.step(100, FORWARD, MICROSTEP); // Run stepper forward
motor1.release(); // Releave power supply on motor

uint8_t cmd[]={0x52}; // TO CHECK IF THIS COMMAND IS VALID
Serial.write(0x52); //HOPEFULLY TO SEND COMMAND TO PROGRAMM ON PC TO START. 0x52 is HEX equivalent of charecter 'R'
}

I not quite sure about the last part about the serial write but so far the programming looks ok when verified with arduino - 0016 .......Hope the same happens when I run it on the setup!! Any comments or recomendation are welcome.
Marten

the first recommendation is to post long lines of code using code blocks so its easier to read, use the # icon in the edit window

Pins are digital by default but are temporarily set for analog when you call the analogRead function. Your code should be able to access pins 14 and 15 as written.

A common mistake is to use a single equals sign for the equality test operator:
if (val = HIGH); //If signal from micrswitch is ON <- this is wrong
should be:
if (val == HIGH){ //use double equal sign, remove semicolon and use braces !
// your code here to execute when val is HIGH
}

You don't need to send hex values to send characters, change:
uint8_t cmd[]={ 0x52 }; // this line is redundant
Serial.write(0x52); //HOPEFULLY TO SEND COMMAND TO PROGRAMM ON PC TO START. 0x52 is HEX equivalent of charecter 'R'
To:
Serial.write('R');