Components and supplies
High Accuracy Pi RTC (DS3231)
Arduino Nano R3
IR receiver (generic)
Stepper Motor, Bipolar
Solderless Breadboard Half Size
Dual H-Bridge motor drivers L298
JustBoom IR Remote
Jumper wires (generic)
Tools and machines
3D Printer (generic)
Apps and platforms
Arduino IDE
Project description
Code
fishFeed_mainCode.ino
c_cpp
1 // This code written by Itzik Ifergan, all right reserved. 2 // I hope you find this code useful. :) 3 4 #include <Time.h> 5 #include <Wire.h> 6 #include <IRremote.h> 7 #include <DS1307RTC.h> 8 #include <Stepper.h> 9 10 #define feed_command 41565 //IR number for feeding, this number can change according to the remote you are using. 11 12 Stepper myStepper(200, 8, 9, 10, 11); 13 14 char t[32]; 15 char d[32]; 16 int morning_hour = 07; 17 int morning_minute = 55; 18 int absolute_second = 02; 19 int noon_hour = 12; 20 int noon_minute = 00; 21 int afternoon_hour = 16; 22 int afternoon_minute = 00; 23 int TimeFeed = 5000; // delay time between motor pulses 24 int receiver_pin = 2; // Pin in arduino for receive the input from the remote. 25 int skipMeal = 0; 26 int Motor_steps = -300; // Direction of round, and number of steps. 27 28 IRrecv receiver(receiver_pin); 29 decode_results output; // "output" is vareiable that equal to the input from the remote. 30 31 void setup() 32 { 33 Serial.begin(9600); 34 Wire.begin(9600); 35 36 setSyncProvider(RTC.get); // the function to get the time from the RTC 37 receiver.enableIRIn(); 38 myStepper.setSpeed(150); 39 40 if(timeStatus()!= timeSet) 41 Serial.println("Unable to sync with the RTC"); 42 else 43 Serial.println("RTC has set the system time"); 44} 45 46 47 void loop() 48 { 49 //printing Time and Date in serial port. 50 sprintf(t, "%02d:%02d:%02d", hour(), minute(), second()); // Define "t" as time string. 51 sprintf(d, "%02d/%02d/%02d", day(), month(), year()); // Define "d" as date string. 52 Serial.println(d); 53 Serial.println(t); 54 delay(1000); 55 56 //Initial process in case of receiving triger from remote. 57 if (receiver.decode(&output)) 58 { 59 unsigned int value = output.value; 60 if (value == feed_command) 61 { 62 skipMeal = 1; // determine flag to cancel the next feeding. 63 for(int i=0; i<6; i++) // Loop rotate the motor 5 times. 64 { 65 Serial.print(skipMeal); 66 myStepper.step(Motor_steps); 67 delay(TimeFeed); 68 } 69 } 70 } 71 72 //first feeding at the morning 73 if((hour()== morning_hour) && (minute()== morning_minute) && (second() == absolute_second)) 74 { 75 if (skipMeal==0) // Checking if the fish already ate before 76 { 77 for(int i=0; i<6; i++) // Loop rotate the motor 5 times. 78 { 79 Serial.print(skipMeal); 80 myStepper.step(Motor_steps); 81 delay(TimeFeed); 82 } 83 } 84 else if(skipMeal == 1) // if the fish already ate 85 { 86 skipMeal=0; // reset the feeding flag to "0" for the next feed 87 Serial.println(skipMeal); 88 } 89 } 90 91 //Second feeding at the noon 92 if((hour()== noon_hour) && (minute()== noon_minute) && (second() == absolute_second)) 93 { 94 if (skipMeal==0) // Checking if the fish already ate before 95 { 96 for(int i=0; i<6; i++) // Loop rotate the motor 5 times. 97 { 98 Serial.print(skipMeal); 99 myStepper.step(Motor_steps); 100 delay(TimeFeed); 101 } 102 } 103 else if(skipMeal == 1) // if the fish already ate 104 { 105 skipMeal=0; // reset the feeding flag to "0" for the next feed 106 Serial.println(skipMeal); 107 } 108 } 109 //Third feeding at the afternoon 110 if((hour()== afternoon_hour) && (minute()== afternoon_minute) && (second() == absolute_second)) 111 { 112 if (skipMeal==0) // Checking if the fish already ate before 113 { 114 for(int i=0; i<6; i++) // Loop rotate the motor 5 times. 115 { 116 Serial.print(skipMeal); 117 myStepper.step(Motor_steps); 118 delay(TimeFeed); 119 } 120 } 121 else if(skipMeal == 1) // if the fish already ate 122 { 123 skipMeal=0; // reset the feeding flag to "0" for the next feed 124 Serial.println(skipMeal); 125 } 126 } 127 128 receiver.resume(); // Listening all the time for input from remote. 129 } 130
fishFeed_mainCode.ino
c_cpp
1 // This code written by Itzik Ifergan, all right reserved. 2 // I hope you find this code useful. :) 3 4 #include <Time.h> 5 #include <Wire.h> 6 #include <IRremote.h> 7 #include <DS1307RTC.h> 8 #include <Stepper.h> 9 10 #define feed_command 41565 //IR number for feeding, this number can change according to the remote you are using. 11 12 Stepper myStepper(200, 8, 9, 10, 11); 13 14 char t[32]; 15 char d[32]; 16 int morning_hour = 07; 17 int morning_minute = 55; 18 int absolute_second = 02; 19 int noon_hour = 12; 20 int noon_minute = 00; 21 int afternoon_hour = 16; 22 int afternoon_minute = 00; 23 int TimeFeed = 5000; // delay time between motor pulses 24 int receiver_pin = 2; // Pin in arduino for receive the input from the remote. 25 int skipMeal = 0; 26 int Motor_steps = -300; // Direction of round, and number of steps. 27 28 IRrecv receiver(receiver_pin); 29 decode_results output; // "output" is vareiable that equal to the input from the remote. 30 31 void setup() 32 { 33 Serial.begin(9600); 34 Wire.begin(9600); 35 36 setSyncProvider(RTC.get); // the function to get the time from the RTC 37 receiver.enableIRIn(); 38 myStepper.setSpeed(150); 39 40 if(timeStatus()!= timeSet) 41 Serial.println("Unable to sync with the RTC"); 42 else 43 Serial.println("RTC has set the system time"); 44} 45 46 47 void loop() 48 { 49 //printing Time and Date in serial port. 50 sprintf(t, "%02d:%02d:%02d", hour(), minute(), second()); // Define "t" as time string. 51 sprintf(d, "%02d/%02d/%02d", day(), month(), year()); // Define "d" as date string. 52 Serial.println(d); 53 Serial.println(t); 54 delay(1000); 55 56 //Initial process in case of receiving triger from remote. 57 if (receiver.decode(&output)) 58 { 59 unsigned int value = output.value; 60 if (value == feed_command) 61 { 62 skipMeal = 1; // determine flag to cancel the next feeding. 63 for(int i=0; i<6; i++) // Loop rotate the motor 5 times. 64 { 65 Serial.print(skipMeal); 66 myStepper.step(Motor_steps); 67 delay(TimeFeed); 68 } 69 } 70 } 71 72 //first feeding at the morning 73 if((hour()== morning_hour) && (minute()== morning_minute) && (second() == absolute_second)) 74 { 75 if (skipMeal==0) // Checking if the fish already ate before 76 { 77 for(int i=0; i<6; i++) // Loop rotate the motor 5 times. 78 { 79 Serial.print(skipMeal); 80 myStepper.step(Motor_steps); 81 delay(TimeFeed); 82 } 83 } 84 else if(skipMeal == 1) // if the fish already ate 85 { 86 skipMeal=0; // reset the feeding flag to "0" for the next feed 87 Serial.println(skipMeal); 88 } 89 } 90 91 //Second feeding at the noon 92 if((hour()== noon_hour) && (minute()== noon_minute) && (second() == absolute_second)) 93 { 94 if (skipMeal==0) // Checking if the fish already ate before 95 { 96 for(int i=0; i<6; i++) // Loop rotate the motor 5 times. 97 { 98 Serial.print(skipMeal); 99 myStepper.step(Motor_steps); 100 delay(TimeFeed); 101 } 102 } 103 else if(skipMeal == 1) // if the fish already ate 104 { 105 skipMeal=0; // reset the feeding flag to "0" for the next feed 106 Serial.println(skipMeal); 107 } 108 } 109 //Third feeding at the afternoon 110 if((hour()== afternoon_hour) && (minute()== afternoon_minute) && (second() == absolute_second)) 111 { 112 if (skipMeal==0) // Checking if the fish already ate before 113 { 114 for(int i=0; i<6; i++) // Loop rotate the motor 5 times. 115 { 116 Serial.print(skipMeal); 117 myStepper.step(Motor_steps); 118 delay(TimeFeed); 119 } 120 } 121 else if(skipMeal == 1) // if the fish already ate 122 { 123 skipMeal=0; // reset the feeding flag to "0" for the next feed 124 Serial.println(skipMeal); 125 } 126 } 127 128 receiver.resume(); // Listening all the time for input from remote. 129 } 130
Downloadable files
IR receiver
IR receiver connect to gnd and 5v and the third pin to pin 2 in arduino nano board
IR receiver
RTC scheme
RTC scheme
stepper diagram
stepper diagram
IR receiver
IR receiver connect to gnd and 5v and the third pin to pin 2 in arduino nano board
IR receiver
RTC scheme
RTC scheme
Comments
Only logged in users can leave comments