Hello everyone
for my project, I have to craft an automatic pet feeder. The basic idea is that, on a specified time, a stepper motor turns to drop the food for the cats to the bowl.
I am using Arduino Uno R3, DS1307 for the RTC clock and 28BYJ-48 as my stepper motor. Stepper is controlled by ULN2003A.
Connections:
8,9,10,11 to IN1,2,3,4 of the controller;
A4 to SDA on DS1307, A5 to SCL on DS1307.
Code used:
#include <Wire.h>
#include "RTClib.h"
#include <Stepper.h>
#define STEPS 2038 // aantal stappen per één rondje
Stepper stepper(STEPS, 8,10,9,11);
RTC_DS1307 RTC; // SCL naar A5, SDA naar A4
String uur;
String uurAangepast;
String minuut;
String minuutAangepast;
String tijd;
bool roundDone = false;
void setup () {
Serial.begin(9600);
Wire.begin();
RTC.begin();
// Check to see if the RTC is keeping time. If it is, load the time from your computer.
if (! RTC.isrunning()) {
Serial.println("RTC is NOT running!");
// This will reflect the time that your sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
}
}
void loop () {
printTime();
motorControl();
}
void printTime(){
DateTime now = RTC.now();
String minuut = String(now.minute());
if(now.hour() < 10){
uur = String(now.hour());
uurAangepast = '0' + uur;
}
else{
uurAangepast = now.hour();
}
Serial.print(uurAangepast);
Serial.print(':');
if(now.minute() < 10){
minuut = String(now.minute());
minuutAangepast = '0' + minuut;
}
else{
minuutAangepast = now.minute();
}
Serial.print(minuutAangepast);
Serial.println();
tijd = uurAangepast + minuutAangepast;
Serial.println(tijd);
delay(1000);
}
void motorControl(){
stepper.setSpeed(6);
stepper.step(339.6);
delay(3000); // wait for three second
stepper.setSpeed(6);
stepper.step(-339.6);
delay(3000);
}
Power is delivered using a breadboard.
What I do not understand is why, as soon as I plug in the RTC on pins A4 and A5, motor stops working.
Could somebody help me out please?