Components and supplies
Arduino Nano R3
Project description
Code
Fishtank Controller.ino
c_cpp
1/*Automated LED Lighting for Planted Aquarium. 2 * 3 *Author: Neeraj R. Rane 4 *Please note that the time is in 24-hour format. 5 *So, enter the time accordingly for proper functioning. 6*/ 7 8 9#define OLED_RESET 4 10#include <Adafruit_SSD1306.h> 11#include <DS3231.h> 12 13DS3231 rtc(SDA, SCL); 14 15//Please note that the time is in 24-hours format. Set the time accordingly. 16int ledStart = 21; //Set the LED start hour 17int ledStop = 23; //Set the LED stop hour 18int fanStart = 21; //Set the Fan start hour 19int fanStop = 23; //Set the fan stop hour 20 21int minutes,hours; 22int potPin = A0; 23int manualSwitch = 6; 24int fanPin = 2; 25int relay1 = 3; 26int relay2 = 4; 27int relay3 = 5; 28int wLed = 9; 29int rbLed = 10; 30 31Adafruit_SSD1306 display(OLED_RESET); 32 33void setup() 34{ 35 pinMode(manualSwitch, INPUT); 36 37 pinMode(wLed, OUTPUT); 38 pinMode(rbLed, OUTPUT); 39 pinMode(fanPin, OUTPUT); 40 41 digitalWrite(relay1, LOW); 42 digitalWrite(relay2, LOW); 43 digitalWrite(relay3, LOW); 44 45 rtc.begin(); 46 47 display.begin(SSD1306_SWITCHCAPVCC, 0x3C); 48 display.display(); 49 delay(1000); 50 display.clearDisplay(); 51 52 display.setTextColor(WHITE); 53} 54 55void loop(){ 56 String time_3231 = rtc.getTimeStr(); 57 hours = time_3231.substring(0,2).toInt(); 58 minutes = time_3231.substring(3,5).toInt(); 59 display.setTextSize(2); 60 display.setCursor(32,1); 61 display.print(hours); 62 display.print(":"); 63 display.println(minutes); 64 65 if(hours >= fanStart && hours < fanStop){ 66 digitalWrite(fanPin, HIGH); 67 } 68 else{ 69 digitalWrite(fanPin, LOW); 70 } 71 72 if(hours == ledStart){ 73 if(minutes >=0 && minutes <=59){ 74 wLedStart(); 75 } 76 digitalWrite(rbLed, HIGH); 77 } 78 79 if(hours>ledStart && hours<ledStop-1){ 80 digitalWrite(wLed, HIGH); 81 digitalWrite(rbLed, HIGH); 82 } 83 84 if(hours<ledStart || hours>ledStop){ 85 digitalWrite(wLed, LOW); 86 digitalWrite(rbLed, LOW); 87 } 88 89 if(hours == ledStop - 1){ 90 if(minutes>=0 && minutes<=59){ 91 wLedStop(); 92 } 93 } 94 95 if(hours == ledStop){ 96 digitalWrite(rbLed, LOW); 97 } 98 99 if(digitalRead(manualSwitch)==HIGH){ 100 manualMode(); 101 } 102 103 display.display(); 104 display.clearDisplay(); 105}//main loop ends here 106 107void wLedStart(){ 108 int fade = map(minutes,0,59,1,255); 109 analogWrite(wLed, fade); 110} 111 112void wLedStop(){ 113 int fade = map(minutes,0,59,255,0); 114 analogWrite(wLed, fade); 115} 116 117void manualMode(){ 118 digitalWrite(rbLed, HIGH); 119 while(digitalRead(manualSwitch)==HIGH){ 120 display.setTextSize(1); 121 display.setCursor(0,20); 122 display.println("Manual Mode"); 123 display.display(); 124 int brightness = analogRead(potPin); 125 brightness = map(brightness,0,1023,0,255); 126 analogWrite(wLed, brightness); 127 } 128 digitalWrite(wLed, LOW); 129 digitalWrite(rbLed, LOW); 130}
Downloadable files
Fishtank Controller
Fishtank Controller
Fishtank Controller
Fishtank Controller
Comments
Only logged in users can leave comments
indoorgeek
0 Followers
•0 Projects
Table of contents
Intro
8
0