The Planted Tank Forum banner
101 - 110 of 110 Posts

· Registered
Joined
·
2 Posts
Hey, so sorry to dig up a rather old thread, but this stuff is totally still relevant!

There's a bunch of other sketches that just don't provide the simplicity and ease of this sketch, so I wanted to use it.

Unfortunately, it won't compile, with the following errors below. No idea why, I didn't change anything, and I tested with another Arduino-branded example sketch to make sure my connections were fine (which they are)... Help, anyone??

 

· Registered
Joined
·
113 Posts
Discussion Starter · #102 ·
Hey, so sorry to dig up a rather old thread, but this stuff is totally still relevant!

There's a bunch of other sketches that just don't provide the simplicity and ease of this sketch, so I wanted to use it.

Unfortunately, it won't compile, with the following errors below. No idea why, I didn't change anything, and I tested with another Arduino-branded example sketch to make sure my connections were fine (which they are)... Help, anyone??

I'm guessing you are using a recent (1.8) version of the Arduino editor?
You might have to try the 1.0.X versions, preferably 1.0.5. The newer ones (1.5 and newer) are using a bugged version of the gcc compiler, causing all sorts of problems.
I can't get it working on the newer versions either!
 

· Registered
Joined
·
113 Posts
Discussion Starter · #105 ·
interesting project! one thing i can not find is the schematics for the whole setup. Can anyone help with that? thanks.
Well - I don't have a complete schematic, as it depends to heavily on your choice of components.
What I did with this particular setup was the 'brute force' way of dimming. I connected the Arduino to a MOSFET, and used it to switch the neutral wire of the light (12 volt). This doesn't always work, it depends greatly on the power supply!

Sent from my Nexus 5X using Tapatalk
 

· Registered
Joined
·
1 Posts
Well - I don't have a complete schematic, as it depends to heavily on your choice of components.
What I did with this particular setup was the 'brute force' way of dimming. I connected the Arduino to a MOSFET, and used it to switch the neutral wire of the light (12 volt). This doesn't always work, it depends greatly on the power supply!

Sent from my Nexus 5X using Tapatalk
Hi Benjaf, I read through the whole thread and realized there isn't any electrical schematic as well. I am pretty new to the microcontroller world but would like to build this project for my house aquarium as well. Wonder if you would draw out a simple drawing on all the wiring connection so that I can try to follow. Thanks a lot and sorry for the trouble.
 

· Registered
Joined
·
8 Posts
Awesome code, I've been looking for something like this. How would I incorporate a push button settable sunrise time with an lcd to display current time, on set time, and intensity %?
I started with this code which is a simple on off and clock display...
Code:
//NJarpa
// Arduino timer on/off setpoint.
//If you find this code,visit INSTRUCTABLES and type the title above.
//Arduino UNO + RTC 1307 + 16X2 LCD + 4 buttons


#include <LiquidCrystal.h>   //Libraries
#include <RTClib.h>
#include <Wire.h>

LiquidCrystal lcd(2, 3, 4, 5, 6, 7); //Arduino pins to lcd
//LCD 1602
//RS to 2pin, EN to 3pin, D4 to 4pin, D5 to 5pin, D6 to 6pin, D7 to 7pin
//Contrast=  10K potentiometer: 1 to Vcc, 2(center)to VO, 3 to GND
//Backlight= K to GND(with 1K resistor), A to Vcc
//Vss to GND , Vdd to +5v

RTC_DS1307 RTC;                     // define the Real Time Clock object
//RTC 1307
//SDA to analog 4,  SCL to analog 5

//You need 4 buttons like this,to enter the set points, with 10K resistor to ground (for each one)

//                  To arduino pins(8, 9, 10, 11)
//                        |
//                        |
//              switch    |   
//              _______   |         10K          
//    +5V  0-----0   0----0------/\/\/\/\-------0  to GND

const int DOWN_BUTTONon =9;        //Buttons Pins
const int UP_BUTTONon =8;
const int DOWN_BUTTONoff =11;       
const int UP_BUTTONoff =10;
const int Relay =12;             //Relay pin

//-----Variables for debouncing------//

boolean lastDownONButton = LOW;
boolean currentDownONButton = LOW;
boolean lastUpONButton = LOW;
boolean currentUpONButton = LOW;
boolean lastDownOFFButton = LOW;
boolean currentDownOFFButton = LOW;
boolean lastUpOFFButton = LOW;
boolean currentUpOFFButton = LOW;


int set_on = 12;        //The default "ON" desired time
int set_off= 12;        //The default "OFF" desired time


void setup(){
  pinMode(Relay, OUTPUT);
  
     Wire.begin();
     RTC.begin();
     lcd.begin(16, 2); // Configura lcd numero columnas y filas
     
     lcd.setCursor(0,0);  //Show "TIME" on the LCD
     lcd.print("TIME");
     lcd.setCursor(0,1);
     lcd.print("ON");    //Show "ON" on the lcd
     lcd.setCursor(6,1);
     lcd.print("OFF");  //Show "OFF" on the lcd
}
     
   //----Debouncing function for all buttons----//
boolean debounce(boolean last, int pin)
{
boolean current = digitalRead(pin);
if (last != current)
{
delay(5);
current = digitalRead(pin);
}
return current;
}
     
 

void loop(){
//--------Show current Time On LCD--------//


DateTime now = RTC.now();        // Clock call
now = RTC.now();

lcd.setCursor(5,0);                 
if(now.hour() < 10)
{
lcd.print("0");
}
lcd.print(now.hour(), DEC); //Print hour
lcd.print(':');
if(now.minute() < 10)
{
lcd.print("0");
}
lcd.print(now.minute(), DEC); //Print min
lcd.print(':');
if(now.second() < 10)
{
lcd.print("0");
}
lcd.print(now.second(), DEC); //Print sec

//----Debounce  buttons---//
currentDownONButton = debounce(lastDownONButton, DOWN_BUTTONon);
currentUpONButton = debounce(lastUpONButton, UP_BUTTONon);
currentDownOFFButton = debounce(lastDownOFFButton, DOWN_BUTTONoff);
currentUpOFFButton = debounce(lastUpOFFButton, UP_BUTTONoff);

//-----Turn down the set "ON"-----//
if (lastDownONButton== LOW && currentDownONButton == HIGH)
{
if(set_on>0){    //"ON" Set point  down never lower than 0
set_on--;        
}
else{
  lcd.setCursor(3,1);
  lcd.print("0");
}
}

//----Turn up the set "ON"----//
else if (lastUpONButton== LOW && currentUpONButton == HIGH)
{
  if(set_on<23){   //"ON" Set point up never higher than 23
  set_on++;
}
else{
  lcd.setCursor(3,1);
  lcd.print("23");
}
}

//---Print the set "ON"---//
lcd.setCursor(3,1);
if(set_on < 10){   
  lcd.print("0");
}
lcd.print(set_on);
lastDownONButton = currentDownONButton;
lastUpONButton = currentUpONButton;

//-----Turn down the set "OFF"-----//
if (lastDownOFFButton== LOW && currentDownOFFButton == HIGH)
{
if(set_off>0){    //"OFF" Set point  down never lower than 0
set_off--;
}
else{
  lcd.setCursor(10,1);
  lcd.print("0");
}
}

//----Turn up the set "OFF"----//
else if (lastUpOFFButton== LOW && currentUpOFFButton == HIGH)
{
  if(set_off<23){   //"OFF" Set point up never higher than 23
  set_off++;
}
else{
  lcd.setCursor(10,1);
  lcd.print("23");
}
}

//---Print the set "OFF"---//
lcd.setCursor(10,1);
if(set_off < 10){   
  lcd.print("0");
}
lcd.print(set_off);
lastDownOFFButton = currentDownOFFButton;
lastUpOFFButton = currentUpOFFButton;



//----Relay Function----//
if(set_on == set_off){
   digitalWrite(Relay, LOW);
}

if(set_on < set_off){
  
             if(now.hour() >= set_on && now.hour() < set_off ){             //Start
             digitalWrite(Relay, HIGH);
             }
             else if(now.hour() >= set_off) {
             digitalWrite(Relay, LOW);
             }
             else{
             digitalWrite(Relay, LOW);
             }
}
if (set_on > set_off){

            if(now.hour() >= set_on && now.hour() <= 23){                  //Start
            digitalWrite(Relay, HIGH);  
            }
            else if(now.hour() < set_off){
            digitalWrite(Relay, HIGH);
            }
            else if(now.hour() >= set_off && now.hour() < set_on){
            digitalWrite(Relay, LOW);  
            }
}

}// The End
as I was just turning on and off relays before So id like to get rid off the set off buttons and make it a fixed 16 hours from set on time and replace the relay stuff with your addpoint array as well as adding randomizing into the array to simulate cloud cover?
so the schedule would look something like this:
Code:
void InitializeChannels(int channels) {
	
	// Channel 1:
int	channelNo = 1;	// Currently editing channel 1
int	pin = 9;		// Channel 1 uses pin 9
	Channels[channelNo] = Channel(pin, MaxPoints, fademode_linear, Points[channelNo]);
/*--------Channel-----------(--------------Hours----------------,------Min----,----Intensity---);---Default time------Description--------------------*/
	Channels[1].SetPoint(              set_on               ,       0     ,        0       );  //    6 am   dawn starts; start of day
	Channels[1].AddPoint(            set_on + 1             ,       0     , random( 85-169));  //    7 am   fade up to 30-60% light within 1hr; end dawn
        Channels[1].AddPoint( random(set_on +  1 - set_on +  4) , random(5-55),       204      );  //  7-11am   randomly fade to 80% light; mid-morning burst
	Channels[1].AddPoint( random(set_on +  4 - set_on +  6) , random(5-55), random(143-190));  // 10a-1pm   randomly fade to 56-75% light; late-morning clouds
	Channels[1].AddPoint(            set_on + 7             ,       0     ,       227      );  //    1 pm   fade up to 90% light; midday burst
	Channels[1].AddPoint( random(set_on +  7 - set_on +  9) , random(5-55), random(165-204));  //   1-4pm   randomly fade dn to 60-80% light; midday cloud
	Channels[1].AddPoint( random(set_on + 10 - set_on + 12) , random(5-55), random(190-216));  //   4-7pm   fade up to 75-85% light; mid-evening burst
  Channels[1].AddPoint(                  set_on + 14            ,      30     ,       178      );  //  8:30pm   fade dn to 70% light; start dusk
	Channels[1].SetPoint(             set_off               ,       0     ,        0       );  //   10 pm   dusk ends lights are off; start of night 
}
Please tell me if that makes sense, im new to the coding language and would like to progress from simple on/off triggers to fun stuff like this.
 

· Registered
Joined
·
360 Posts
i am finnally finding this again after a few years and finding myself building basically the same setup but with 4 channels instead of 3

i have to figure out why its not happy with channel 3 this time tho and im not entirely sure where to go from here
 
101 - 110 of 110 Posts
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.
Top