Devices & Components
Arduino Uno Rev3
Button
Electrical Tape
Breadboard (generic)
Hot Glue
OLED SSD1306 (128x64)
Jumper wires (generic)
Servo Module (Generic)
Adafruit Waterproof DS18B20 Digital temperature sensor
Acrylic Sheet (.18 in thickness)
DS3231 RTC Module I2C
Command Strips
IoT Relay Outlet
Resistor 220 ohm
Pill Bottle
LED (generic)
Resistor 1k ohm
Hardware & Tools
Hot glue gun (generic)
Soldering iron (generic)
Laser cutter (generic)
Wire Stripper & Cutter, 18-10 AWG / 0.75-4mm² Capacity Wires
Super Glue
Software & Tools
Arduino IDE
Project description
Code
AAMS_CODE
arduino
Code for the AAMS. Remember to change parameters to be specific to your sensors, servos, and pin layout. Libraries needed: RTClib OneWire DallasTemperature Servo Adafruit BusIO Adafruit GFX Library Adafruit SSD1306
1#include <SPI.h> 2#include <Wire.h> 3#include <Adafruit_GFX.h> 4#include <Adafruit_SSD1306.h> 5#include <OneWire.h> 6#include <DallasTemperature.h> 7#include <Servo.h> 8#include "RTClib.h" 9 10#define pButton 2 11#define pPowerStrip 8 12#define pTemp 10 13#define pStanServo 11 14#define pLED 12 15 16#define stanServoPos 0 17#define stanServoPos2 180 18 19#define daysToNext25Change 14 20 21Servo stanServo; 22 23//remove reset pin (my OLED has none) 24Adafruit_SSD1306 display(-1); 25 26// Setup a oneWire instance to communicate with any OneWire devices 27OneWire oneWire(pTemp); 28 29// Pass our oneWire reference to Dallas Temperature sensor 30DallasTemperature sensors(&oneWire); 31 32RTC_DS3231 rtc; 33 34char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; 35 36int buttonPresses; 37int futureDay, futureMonth, futureYear; 38int changePercent; 39 40void setup() { 41 42 Serial.begin(9600); 43 44 stanServo.attach(pStanServo, 500, 2500); 45 46 //start up library for temp sensor 47 sensors.begin(); 48 49 //set pin modes 50 pinMode(pButton, INPUT); 51 pinMode(pPowerStrip, OUTPUT); 52 pinMode(pTemp, INPUT); 53 pinMode(pStanServo, OUTPUT); 54 pinMode(pLED, OUTPUT); 55 56 // initialize with the I2C addr 0x3C 57 display.begin(SSD1306_SWITCHCAPVCC, 0x3C); 58 59 // Clear the buffer. 60 display.clearDisplay(); 61 62 delay(3000); // wait for console opening [for RTC module] 63 64 if (! rtc.begin()) { 65 Serial.println("Couldn't find RTC"); 66 while (1); 67 } 68 69 // Comment out below lines once you set the date & time. 70 // Following line sets the RTC to the date & time this sketch was compiled 71 rtc.adjust(DateTime(2022, 10, 9, 7, 23, 10)); 72 73 // Following line sets the RTC with an explicit date & time 74 // for example to set January 27 2017 at 12:56 you would call: 75 // rtc.adjust(DateTime(2017, 1, 27, 12, 56, 0)); 76 77} 78 79void loop() { 80 81 if (sensors.getTempFByIndex(0) < 76) { //code to control heater activation 82 83 digitalWrite(pPowerStrip, HIGH); 84 85 } 86 87 DateTime now = rtc.now(); 88 89 display.setTextColor(WHITE); 90 display.clearDisplay(); 91 92 //Display current date MM/DD/YYYY 93 display.setTextSize(1); 94 display.setCursor(0,0); 95 display.print(daysOfTheWeek[now.dayOfTheWeek()]); 96 char currentDate [16]; 97 uint8_t thisDay, thisMonth ; 98 thisDay = now.day(); 99 thisMonth = now.month(); 100 sprintf (currentDate, "%02d/%02d/", thisMonth, thisDay); //add leading zeros to the day and month 101 display.setTextSize(1); 102 display.setCursor(62,0); 103 display.print(currentDate); 104 display.setTextSize(1); 105 display.setCursor(102,0); 106 display.print(now.year(), DEC); 107 108 //Display current time 109 char buffer [16]; 110 uint8_t thisSec, thisMin, thisHour; 111 thisSec = now.second(); 112 thisMin = now.minute(); 113 thisHour = now.hour(); 114 sprintf (buffer, "%02d:%02d:%02d", thisHour, thisMin, thisSec); 115 display.setTextSize(2); 116 display.setCursor(15,12); 117 display.print(buffer); 118 119 //display temperatures 120 sensors.requestTemperatures(); // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus 121 display.setCursor(7,30); 122 display.setTextSize(1); 123 display.print("Water Temp: "); 124 display.print(sensors.getTempFByIndex(0)); 125 display.print((char)247); 126 display.print("F"); 127 128 if (digitalRead(pButton) == HIGH) { 129 130 DateTime future(now + TimeSpan(14,0,0,0)); 131 132 futureDay = future.day(); 133 futureMonth = future.month(); 134 futureYear = future.year(); 135 136 buttonPresses++; 137 digitalWrite(pLED, LOW); 138 139 } 140 141 if (buttonPresses % 52 == 0 && buttonPresses != 0) { 142 143 changePercent = 100; 144 145 } 146 147 else if (buttonPresses % 2 == 0 && buttonPresses != 0) { 148 149 changePercent = 50; 150 151 } 152 153 else if (buttonPresses != 0) { 154 155 changePercent = 25; 156 157 } 158 159 //display next water change 160 display.setCursor(22, 40); 161 display.print(changePercent); 162 display.print("% change on:"); 163 char futureDate [16]; 164 sprintf (futureDate, "%02d/%02d/", futureMonth, futureDay); //add leading zeroes to date 165 display.setCursor(35, 50); 166 display.print(futureDate); 167 display.print(futureYear); 168 169 if (now.year() == futureYear && thisMonth == futureMonth && thisDay == futureDay) { 170 171 digitalWrite(pLED, HIGH); //activate LED 172 173 } 174 175 if (sensors.getTempFByIndex(0) > 78) { //code to control heater activation 176 177 digitalWrite(pPowerStrip, LOW); 178 179 } 180 181 if (thisHour == 12 && thisMin == 0 && thisSec < 5) { //code for auto fish feeder 182 183 stanServo.write(stanServoPos); 184 185 } 186 187 else { 188 189 stanServo.write(stanServoPos2); 190 191 } 192 193 display.display(); 194 195}
Downloadable files
Circuit Diagram
Circuit Diagram
Documentation
Case CAD File (.dxf)
Case CAD File (.dxf)
Case Layout Sketch
Case Layout Sketch
Comments
Only logged in users can leave comments