Aquarium Auto Lighting System

5,532

4

10

About: Hello , my name is John Vasilakis and this is my Arduino profile ! Visit my site www.ardumotive.com

In this DIY guide I will show you how to make your own Arduino aquarium auto lighting system. In this project I decided to make my own PCB that is based on Arduino UNO microcontroller - Atmega328p. Bellow you will find the electronic schematic with PCB layout so you can easily produce it.

The current time can be set for the first time (or when the coin battery is low) via the serial monitor. You can change the lighting change time or led color from code.

~Project updates can be found here:

https://www.ardumotive.com/arduino-aquarium-auto-l...

~Watch the video below:

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: What You Will Need - Hardware

Step 2: Circuit Schematic and PCB

Enter here to see and make any changes to the above circuit.

Step 3: The Code

Connect your circuit with TTL to USB module with 5 cables to the programming header. The pins RX and TX must be cross-connected.

NOTE: If you are using the Arduino UNO board make sure to remove the ATmega328 IC from it first and connect the headers RX to RX and TX to TX pins of the board. The RS pin must be connected to Arduino UNO reset pin.

/*  Arduino based - Aquarium Auto Lighing System
* More info can be found at: http://www.ardumotive.com
* Dev:Michalis Vasilakis Date:21/2/2018 Var:1.0
*/

//Libraries (many thanks to Developers)
#include <Adafruit_NeoPixel.h>
#include <RTClib.h>


//Constants
const int DIN = 2; //Neopixel DIN pin to Arduino Pin 2
const int PIXELS = 29; //How many neopixel leds do you have?
RTC_DS1307 rtc; //Create an object for DS1307 I2C library
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(PIXELS, DIN, NEO_GRB + NEO_KHZ800); //Create an object for NeoPixel library

//Variables;
int H,M; //H for hour and M for minutes
String Time; // Use readTime(); Serial.print(Time); for printing the time in serial monitor
//Variables For color setting
boolean newColor = false;
int r=0;
int g=0;
int b=0;
//Following variables are used for the time setting from serial monitor
boolean newMessage = false;
boolean messageCompleted = false;
char incomingByte;
String command;
//Delay without delay() for fade
unsigned long previousMillis = 0;
const long interval = 250; //Change this value (ms)


void setup() {
pixels.begin(); //Initialize the NeoPixel library
rtc.begin(); //Initialize the RTC DS1307 library
Serial.begin(9600);
//This will run only if the rtc battery is low or rtc ic has wrong time set
if (! rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// This line sets the RTC with an explicit date & time, for example to set
// January 1, 2018 at 00:00am you would call:
rtc.adjust(DateTime(2018, 01, 01, 00, 00, 0));
}
Serial.println("Aquarium Auto Lighting System");
Serial.println("Visit the www.Ardumotive.com for more info \n");
readTime();
Serial.println(Time);
Serial.println("- To set the time send '<SHH:MM>' (example: <S14:05>)");
}

void loop() {
setTime(); //Check for serial set command
readTime();

//Change time and color values bellow if you want
//From 00:00 to 07:00
if (H>=0 && H <7) {
setColor(0,0,50);
}
//From 07:00 to 12:00
else if (H>=7 && H<12){
setColor(50,50,100);
}
else if( H>=12 && H<19){
setColor(180,180,180);
}
else if (H>=19 && H<21){
setColor(50,50,100);
}
}
//Send color to led strip
void setColor(int R,int G,int B){
while ((r!=R) || (g!=G) || (b!=B)){
setTime(); //Check for serial set command

unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
for(int i=0;i<PIXELS;i++){
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(r,g,b));
pixels.show();
}
if (r!=R && r<R){
r++;
}
else if (r!=R && r>R){
r--;
}
if (g!=G && g<G){
g++;
}
else if (g!=G && g>G){
g--;
}
if (b!=B && b<B){
b++;
}
else if (b!=B && b>B){
b--;
}
}
}
}

//Read time from RTC
void readTime(){
DateTime now = rtc.now();
H = now.hour();
M = now.minute();
Time = "Current time in RTC: " + String(H) + ":" + String(M);
}

//Set time, send <SHH:MM> (example <S05:00>)
void setTime(){
if (Serial.available()){
incomingByte = Serial.read();
if(incomingByte=='>'){
messageCompleted=true;
newMessage=false;
}
else if (incomingByte=='<'){
newMessage=true;
}
if (newMessage){
command.concat(incomingByte);
}
}
if(messageCompleted){
//Set time
if (command.charAt(1)=='S'){
int h = (command.substring(2,4)).toInt();
int m = (command.substring(5,7)).toInt();
rtc.adjust(DateTime(2018,01,01,h,m,0));
Serial.println("Done");
readTime();
Serial.println(Time);
}
command="";
messageCompleted=false;
}
}

Step 4: 3D Parts

Step 5: Well Done!

I hope you liked this, let me know in the comments!!!

Indoor Lighting Contest

Participated in the
Indoor Lighting Contest

Be the First to Share

    Recommendations

    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    10 Discussions

    1
    None
    thebigpotatoe

    20 days ago

    That's a pretty epic little PCB and case, but would be awesome to see how you mounted and connected your lights in the tank. Thanks for sharing!

    1 reply
    1
    None
    pgs070947

    4 weeks ago

    Nice project and ideal use of Atmega 328.
    For real beginners, you might need a bit more information on loading a bootloader onto a raw 328 chip, then uploading the code. (Nick) Gammon.au has a load of information on burning the bootloader and uploading code. A shield PCB for a Uno or Nano could be an easier route for some. The DS1307 isn't a great RTC for long-term timekeeping. The DS3231TCX is better, but still drifts. An OLED or LCD display of time and date would help. TimeLib and TimeAlarms libraries are useful for scheduling events and can take the time from the RTC.
    Fish look happy.

    1 reply
    0
    None
    Giannis Vasilakispgs070947

    Reply 4 weeks ago

    Thank you for your comment and tips. I am using the atmega328 with bootloader already on chip. But I know that there is a procedure to burn it on a pure atmel chip.

    1
    None
    dew_it

    Question 4 weeks ago

    I noticed you don't have plants in your aquarium, but do you know if those LED strips would be good enough (colour temp) for a planted tank (not that many plants though)?

    1 answer
    0
    None
    Giannis Vasilakisdew_it

    Answer 4 weeks ago

    I can't say if the led light is correct for all types of plant. In my aquarium I have anoubia and it's ok until now

    1
    None
    dew_it

    Question 4 weeks ago

    I noticed you don't have plants in your aquarium, but do you know if those LED strips would be good enough (colour temp) for a planted tank (not that many plants though)?

    1 answer
    0
    None
    Giannis Vasilakisdew_it

    Answer 4 weeks ago

    I can't say if the led light is correct for all types of plant. In my aquarium I have anoubia and it's ok until now

    1
    None
    AndrewM512

    Question 4 weeks ago

    can i use an arduino nano in place of buliding the whole circut ?

    1 answer