Fish Feeder President
Published

Fish Feeder - Arduino UNO rev3 - HC-06 - RTC DS1307

A Simple design for building an automatic fish feeder for small ponds.

BeginnerFull instructions provided51
Fish Feeder - Arduino UNO rev3 - HC-06 - RTC DS1307

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
HC-06 Bluetooth Module
×1
Real Time Clock (RTC)
Real Time Clock (RTC)
×1
SparkFun Logic Level Converter - Bi-Directional
SparkFun Logic Level Converter - Bi-Directional
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×4
LED (generic)
LED (generic)
×2
Slide Switch
Slide Switch
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

Schematic diagram

Code

ServoEvery6hBTSliders.ino

C#
#include <Wire.h> 
#include <Servo.h> 
#include <DS1307.h> 

#define led_1 5 
#define led_2 6

int open_time = 3000; 
int open_position = 0; 
int servo_off = 150;
int close_position = 180; 
int last_servo = 0; 

Servo servo_1; 
Servo servo_2;
Servo servo_3;
Servo servo_4;

/* RTC */
DS1307 clock;
RTCDateTime dt; 
RTCDateTime aktualny_czas; 

char cmd[100];
byte cmdIndex;
int a = 0;

void setup () {
  Serial.begin(9600);
  
  clock.begin();
  clock.setDateTime(__DATE__, __TIME__); 
  aktualny_czas = clock.getDateTime(); 
  servo_1.attach(9); 
  servo_2.attach(10);
  servo_3.attach(11);
  servo_4.attach(3);

  pinMode (led_1, OUTPUT); 
  pinMode (led_2, OUTPUT);

  digitalWrite (led_1, LOW); 
  digitalWrite (led_2, HIGH); 
}

void loop () {
  dt = clock.getDateTime(); 
  
//**************************************************Servos movement every 6h**************************************** 

  if ((dt.hour == 6) && last_servo == 0){
    servo_1.write(open_position); 
    digitalWrite (led_1, HIGH); 
    delay (open_time);
    
    servo_1.write(close_position);
    digitalWrite (led_1, LOW);
    delay (servo_off);
    servo_1.detach(); 
    
    last_servo = 1; 
  }
  if ((dt.hour == 12) && ostatnie_serwo == 1){
    servo_2.write(open_position); 
    digitalWrite (led_1, HIGH); 
    delay (open_time);
    
    servo_2.write(close_position);
    digitalWrite (led_1, LOW);
    delay (servo_off);
    servo_2.detach(); 
    
    last_servo = 2;
  }
  if ((dt.hour == 18) && ostatnie_serwo == 2){ 
    servo_3.write(open_position); 
    digitalWrite (led_1, HIGH); 
    delay (open_time);
    
    servo_3.write(close_position);
    digitalWrite (led_1, LOW);
    delay (servo_off);
    servo_3.detach(); 
    
    last_servo = 3;
  }
  if ((dt.hour == 0 || dt.hour == 24) && ostatnie_serwo == 3){ 
    servo_4.write(open_position); 
    digitalWrite (led_1, HIGH); 
    delay (open_time);
    
    servo_4.write(close_position);
    digitalWrite (led_1, LOW);
    delay (servo_off);
    servo_4.detach(); 
    
    last_servo = 4;
  }
  if (last_servo == 4) {
    aktualny_czas = clock.getDateTime(); 
    last_servp = 0; 
  } 
  
//*************************************************************Bluetooth********************************************** 

  if (Serial.available() > 0)
  {
    char c = (char)Serial.read();
    if (c == '\n') {
      cmd[cmdIndex] = 0;
      a = c;
      exeCmd(a);
      cmdIndex = 0;
    } else {
      cmd[cmdIndex] = c;
      a = c;
      if (cmdIndex < 99) cmdIndex++;
    }
  }
}


void exeCmd(char a) {
 
  if (cmd[0] == '1') {
    unsigned int val = atof(cmd + 2);
    servo_1.write(val);
  }
  if (cmd[0] == '2') {
    unsigned int val = atof(cmd + 2);
    servo_2.write(val);
  }
  if (cmd[0] == '3') {
    unsigned int val = atof(cmd + 2);
    servo_3.write(val);
  }
  if (cmd[0] == '4') {
    unsigned int val = atof(cmd + 2);
    servo_4.write(val);
  }
}
 

Credits

Fish Feeder President

Fish Feeder President

0 projects • 0 followers

Comments

Add projectSign up / Login