Hi all,
I am working on an arduino project to control the light and monitor temperature in my aquarium.
I have an arduino UNO setup with a 16x2 LCD, DS3231 Real-time clock, DS18B20 one-wire temperature sensor and I will use a MOSFET from pin 10 to control the LED lights.
I have successfully got the LCD to display the correct time, date and temperature. But I am really stuck with a couple of things.
-
I am unsure how to make the 2 loops in my code happen at specific times, for example I want the sunrise loop to happen at 9am and the sunset loop happen at 10pm. I know I need an "if" statement somewhere to check what hour it is and if it is 9am or later then it will execute the loop.
-
I know how to fade an LED but I have no idea how to make the LED fade over a longer period of time. I want the LED to start off and fade all the way up to full brightness over the period of say 1 hour and remain there until it is time for sunset where I want the opposite to happen.
Is there anyone who can help with this?
My code so far is:
#include <DS3231.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <LiquidCrystal.h>int lights = 10;
DS3231 rtc(SDA, SCL); // Init the DS3231 using the hardware interface
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte temp[8] = { //Temp Symbol
0b00100,
0b01010,
0b01010,
0b01110,
0b01110,
0b11111,
0b11111,
0b01110
};#define ONE_WIRE_BUS 8 // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);void setup()
{
// Setup Serial connection
Serial.begin(4800);
lcd.begin(16, 2); // set up the LCD's number of columns and rows:
pinMode(lights, OUTPUT);
lcd.clear(); //Clear the LCD Screen
lcd.createChar(0, temp); //Create temperature symbol
rtc.begin(); // Initialize the rtc object
sensors.begin();
// The following lines can be uncommented to set the date and time
//rtc.setDOW(SUNDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(15, 05, 2016); // Set the date to January 1st, 2014
}void loop()
{
// Send Day-of-Week
lcd.setCursor(1, 0);
lcd.print(rtc.getDOWStr(FORMAT_SHORT)); //Send day of week to LCD
lcd.setCursor(7,0);
lcd.print(rtc.getDateStr(FORMAT_SHORT)); //Send date to LCD
lcd.setCursor(1, 1);
lcd.print(rtc.getTimeStr()); //Send time to LCD
lcd.setCursor(10,1);
lcd.write(byte(0)); //Print temperature symbol to LCD
lcd.setCursor(11, 1);
sensors.requestTemperatures(); //Get temperature from DS18B20
lcd.print(sensors.getTempCByIndex(0)); // Send temperature to LCD
lcd.setCursor(13, 1);
lcd.print((char)223); //Send "Degree" symbol to LCD
lcd.setCursor(14, 1);
lcd.print("C "); //Send C (Celsius) to LCD
delay (1000); // Wait one second before repeating
}void sunrise()
{
//Code here to fade LED from 0 to 255
}void sunset()
{
//Code here to fad LED from 255 to 0
}
Any help would be appreciated,
Thanks