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);
}
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.
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?
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?
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.)