Custom Aquarium controller

I am making a Aquarium Controller with Arduino Uno. I have a sensorshield board on the Arduino which has a RTC module (DS3231) Connected at the IIC and 2 relays connected at digital pins 4 and 5 and a Servo motor connected at 7.

The Controller worked fine till here. Then I added Display. I have the OLED 0.96 connected at A4 and A5.

The Code Shows upload done but nothing happens. I tested the display seperately on a different UNO and also on the same UNO with the SSD1306 code and it works fine, but no output when using my code.

Can some one please check what I am doing wrong.

Attached is my code.

#include <Wire.h>
#include <Servo.h>
#include <SPI.h>
#include <RTClib.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels

// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins)
#define OLED_RESET     4 // Reset pin # (or -1 if sharing Arduino reset pin)
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

int Relay1 = 4;
int Relay2 = 5;
Servo myservo;

int pos = 0;

RTC_DS3231 rtc;
//Time t;
float temp = rtc.getTemperature();

const int LightOnHour = 6; //SET TIME TO ON LIGHT RELAY (24 HOUR FORMAT)
const int LightOnMin = 30;
const int LightOffHour = 19; //SET TIME TO OFF LIGHT RELAY
const int LightOffMin = 35;
const int FeedOnHour = 11; //SET TIME TO ON Servo (24 HOUR FORMAT) 
const int FeedOnMin = 30;
const int FeedOffHour = 11; //SET TIME TO OFF Servo
const int FeedOffMin = 32;
const int PumpOnHour = 6; //SET TIME TO ON PUMP (24 HOUR FORMAT) 
const int PumpOnMin = 40;
const int PumpOffHour = 19; //SET TIME TO OFF PUMP
const int PumpOffMin = 45;


void setup() {
 Serial.begin(115200);
 display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
 display.display();
 delay(2000);
 display.clearDisplay();
 rtc.begin();
 pinMode(Relay1, OUTPUT);
 digitalWrite(Relay1, LOW);
 pinMode(Relay2, OUTPUT);
 digitalWrite(Relay2, LOW);
 myservo.attach(8);
 //testscrolltext();
}

void loop() {
 DateTime t = rtc.now();
 Serial.print("Temperature: ");
 Serial.print(temp);
 Serial.println(" ");
 Serial.print(t.hour());
 Serial.print(" hour(s), ");
 Serial.print(t.minute());
 Serial.print(" minute(s)");
 Serial.println(" ");
 
 display.clearDisplay();
 //display.display();
 display.setTextColor(WHITE);
 display.setCursor(0,0);
 display.setTextSize(1);
 display.print(t.dayOfTheWeek());
 display.println(",");
 display.println(t.day());
 display.println("-");
 display.println(t.month());
 display.println("-");
 display.println(t.year());
 display.println(" ");
 display.println(t.hour());
 display.println(":");
 display.println(t.minute());
 display.println(":");
 display.println(t.second());
 display.print("Temp:");
 display.println(temp);

 if(t.hour() == LightOnHour && t.minute() == LightOnMin){
   digitalWrite(Relay1,HIGH);
   Serial.println("LIGHT ON");
   display.println("Light:ON");
   }
   
   else if(t.hour() == LightOffHour && t.minute() == LightOffMin){
     digitalWrite(Relay1,LOW);
     Serial.println("LIGHT OFF");
     display.println("Light:OFF");
   }

 if(t.hour() == PumpOnHour && t.minute() == PumpOnMin){
   digitalWrite(Relay2,HIGH);
   Serial.println("PUMP ON");
   display.println("Pump:OO");
   }
   
   else if(t.hour() == PumpOffHour && t.minute() == PumpOffMin){
     digitalWrite(Relay2,LOW);
     Serial.println("PUMP OFF");
     display.println("Pump:OFF");
   }

 if(t.hour() == FeedOnHour && t.minute() == FeedOnMin){
   for (pos = 0; pos <= 90; pos += 1) { // goes from 0 degrees to 90 degrees
   // in steps of 1 degree
   myservo.write(pos);              // tell servo to go to position in variable 'pos'
   delay(15);                       // waits 15ms for the servo to reach the position
   }
   for (pos = 90; pos >= 0; pos -= 1) { // goes from 90 degrees to 0 degrees
   myservo.write(pos);              // tell servo to go to position in variable 'pos'
   delay(15);                       // waits 15ms for the servo to reach the position
   }    
   Serial.println("Feeding ON");
   digitalWrite(Relay2,LOW);
   Serial.println("PUMP OFF");
   display.println("Feed:ON");
   display.println("Pump:OFF");
 
   }
   
   else if(t.hour() == FeedOffHour && t.minute() == FeedOffMin){
     delay(1000*20*60);
     digitalWrite(Relay2,HIGH);
     Serial.println("Pump ON");
     display.println("Feed:OFF");
     display.println("Pump:ON");
   }
 display.display();
 delay (1000);
  
}

AquariumController2.ino (4.02 KB)

IMG_20200321_170320 (1) (Mobile).jpg

You have posted code without using code tags. The code tags make the code look

like this

when posting source code files. It makes it easier to read, and can be copied with a single mouse click. Also, if you don't do it, some of the character sequences in the code can be misinterpred by the forum code as italics or funny emoticons. The "Code: [Select]" feature allows someone to select the entire sketch so it can be easily copied and pasted into the IDE for testing.

Unless the sketch is too large, it's better if you post your code, rather than attach it. When it's attached, we have to download it, create a folder then open your code in our IDE. And afterwards, the folder remains unless we navigate to the "Temp" folder and manually remove it. It's much easier to just view the code in your post.

Hi,
Welcome to the forum.

Please read the post at the start of any forum , entitled "How to use this Forum".
OR
http://forum.arduino.cc/index.php/topic,148850.0.html.
Then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom... :slight_smile:

Edited the original post to include the code with code tags. Added circuit design.

What happens when you run it? You said nothing; does that mean no Serial output?

What numbers for memory does the compiler report?

It looks like you have everything powered off the Arduino .

With servos/relays you need a separate power supply

@Wildbill - No Serial output, No display on the OLED. Attached below is the compiler report.

@Hammy- It worked fine till I added the OLED. Also I will be powering the Arduino with a 9v power supply once it is working properly.

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

         Using Port                    : COM7
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
         AVR Part                      : ATmega328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 3
         Firmware Version: 4.4
         Vtarget         : 0.3 V
         Varef           : 0.3 V
         Oscillator      : 28.800 kHz
         SCK period      : 3.3 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f (probably m328p)
avrdude: reading input file "C:\Users\max\AppData\Local\Temp\arduino_build_362768/AquariumController2.ino.hex"
avrdude: writing flash (18070 bytes):

Writing | ################################################## | 100% 3.35s

avrdude: 18070 bytes of flash written
avrdude: verifying flash memory against C:\Users\max\AppData\Local\Temp\arduino_build_362768/AquariumController2.ino.hex:
avrdude: load data flash data from input file C:\Users\max\AppData\Local\Temp\arduino_build_362768/AquariumController2.ino.hex:
avrdude: input file C:\Users\max\AppData\Local\Temp\arduino_build_362768/AquariumController2.ino.hex contains 18070 bytes
avrdude: reading on-chip flash data:

Reading | ################################################## | 100% 2.67s

avrdude: verifying ...
avrdude: 18070 bytes of flash verified

avrdude done.  Thank you.

I was looking for the compiler output that tells you how much flash and RAM you've consumed.

As to power, if you actually are powering everything from the Arduino, that may well be the reason it isn't working.

Hi,
OPs diag.

Thanks.. Tom.. :slight_smile:

So I finally got it working. and it wasnt power issue. Error was in the code. Will upload the corrected code soon.

Hi,
How are you powering your project?

Tom... :slight_smile:

m powering it using a 9 v adapter to the Arduino.

maxwega:
m powering it using a 9 v adapter to the Arduino.

What power rating?
Tom.. :slight_smile:

Sorry Tom, I dont understand your question. Besides what difference does it make with what rating it has. As I said it wasnt power issue. I was earlier powering it with the same adapter. The Problem started after adding the code for Display OLED.

Hi,
What current is the 9V supply rated at?
Also if you draw too much current through the UNO you will overload the 5V linear regulator that is on the UNO board.

The regulator does not have a heatsink on it, so it doesn't need to dissipate to much energy and it will shutdown dur to thermal overload.

You project may work now, but in time the regulator will give you problems.
A servo that is continually under load will cause this.
What does the servo do?

Tom... :slight_smile:

Tom, Thank you for explaining that.

Input : 100-240v~50/60Hz 0.6A max
Output: 9V - 1A

This is what is written on the Adapter. The Servo is for feeding the fishes. It will be working once a day for a minute max.

The Max load on the arduino will be from the 2 Relays as one is for light, which will be on for 12 hours and other is for Pump, which will be on for 16 to 18 hours.

I was planning to use a 5V - 550mA mobile charger to power the Sensor Shield board externally. Will that work? Or should I continue with the 9V adapter.? (PS - I have 12V-1A adapter too.)