Hi Arduino-Community!
This is my first time posting so please dont mind little noob-mistakes.
I built a pet-feeder controlled by an Arduino Uno, working with 2 stepper motors, 1 rfid module, a clock, a switch, and a seperate psu-module.
The goal of this project is to provide meals for a specific cat two times a day.
The whole thing in itself seems to work as intended, while the automatic feeder is still connected to my pc via the onboard usb-port of the arduino. But as soon as i unplug the usb-connection, the system stops working.
My first thought was, that the stepper motors are drawing to much current so that the 12V/2A plug of the psu could not supply enough and needed the additional power from the usb connection, but switching to a 12V/3A power supply didn't make any difference.
So the question is: why does my project do not work, when not connected to the computer via usb?
Are there any reasons the serial communication between the rfid module and the arduino breaks when not connected to a computer?
Below you can find a list of my used parts, a drawn wiring diagram and the whole code of this project. Any help is appreciated!
Parts:
- Arduino Uno
- 12V PSU with 3x12V Out, 3x5V Out, 3x3,3V Out
- 2x 28byj-48-stepper (12V) + ULN2003 driver
- 1x RTC ds3231
- 1x WL-134 RFID Module + self built antenna
Wiring:
Code:
//includes for Scanner
#include <SoftwareSerial.h>
#include <Rfid134.h>
bool katzeda;
String katze = "276098001016530";
String gescannt;
class RfidNotify
{
public:
static void OnError(Rfid134_Error errorCode)
{
// see Rfid134_Error for code meaning
Serial.println();
Serial.print("Com Error ");
Serial.println(errorCode);
}
static void OnPacketRead(const Rfid134Reading& reading)
{
char temp1[8];
char temp2[8];
char temp3[8];
sprintf(temp1, "%03u", reading.country);
sprintf(temp2, "%06lu", static_cast<uint32_t>(reading.id / 1000000));
sprintf(temp3, "%06lu", static_cast<uint32_t>(reading.id % 1000000));
String temp1s((char*)temp1);
String temp2s((char*)temp2);
String temp3s((char*)temp3);
gescannt = temp1s+temp2s+temp3s;//string zusammenbauen
}
};
SoftwareSerial secondarySerial(0, 11); // RX, TX
Rfid134<SoftwareSerial, RfidNotify> rfid(secondarySerial);
//includes for Motors
#include <AccelStepper.h>
AccelStepper Motor2(8, 2,4,3,5); // Motor2 = Schale
long positionM2 = 0;
int rotations;
AccelStepper Motor1(8, A0,A2,A1,A3); // Motor1 = Klappe
long positionM1 = 0;
const byte switchPin = 13; //Switch in der Deckelklappe
//includes for Timer
#include <RTClib.h>
#include <Wire.h>
DS3231 rtc;
char t[32];
bool canRotate;
const long intervall = 60000;
unsigned long timeStamp1;
unsigned long timeStamp2;
bool klappeOffen;
//includes for manual open
int Button = 12;
int Button_State=0;
void setup() {
//Setup for Scanner
Serial.begin(9600); // Initialize serial communications with the PC
secondarySerial.begin(9600);
rfid.begin();
katzeda = false;
klappeOffen = false;
gescannt = "";
//Setup for Motor2 Schale
Motor2.setCurrentPosition(positionM2);
Motor2.setMaxSpeed(500.0);
Motor2.setAcceleration(200.0);
Motor2.setSpeed(500);
Motor2.disableOutputs();
//Setup for Motor1 Klappe
Motor1.setCurrentPosition(positionM1);
Motor1.setMaxSpeed(500.0);
Motor1.setAcceleration(200.0);
Motor1.setSpeed(-500);
Motor1.disableOutputs();
pinMode (switchPin, INPUT_PULLUP);
//setup for Timer
Wire.begin();
rtc.begin();
//rtc.adjust(DateTime(2019, 1, 21, 5, 0, 0));
//rtc.adjust(DateTime(F(__DATE__),F(__TIME__)));
canRotate = true;
rotations = 0;
//setup for resetwheel Button
pinMode(Button, INPUT);
}
void loop() {
//Überprüfe Ob Position Reset -----------------------------------------------------------------------
Button_State = digitalRead(Button);
if (Button_State != 0){
wheelReset();
}
//Überprüfe Bedingung IST UHRZEIT -----------------------------------------------------------------------------
DateTime now = rtc.now();
if(!canRotate){
if((now.hour()==5)||(now.hour()==17)){
canRotate = true;
}
}
if(canRotate){
if (((now.hour()==6)||(now.hour()==18))&&(now.minute()==30)&&((now.second() >= 0 ) && (now.second() < 30))){
switch (rotations){
Motor2.enableOutputs();
case 0:
Motor2.moveTo(819);
Motor2.runToPosition();
rotations = 1;
break;
case 1:
Motor2.moveTo(1638);
Motor2.runToPosition();
rotations = 2;
break;
case 2:
Motor2.moveTo(2457);
Motor2.runToPosition();
rotations = 3;
break;
case 3:
Motor2.moveTo(3476);
Motor2.runToPosition();
rotations = 4;
break;
case 4:
Motor2.moveTo(0);
Motor2.runToPosition();
rotations = 0;
break;
Motor2.disableOutputs();
}
canRotate = false;
}
}
//Überprüfe Bedingung IST KATZE DA ----------------------------------------------------------------------------
rfid.loop();
//Serial.println("Spot1");
//Serial.println(gescannt);
//Serial.println(gescannt == katze);
//delay(1000);
if(gescannt == katze){
gescannt = "";
timeStamp1 = millis();
if(!klappeOffen){
klappeOffen = true;
Motor1.enableOutputs();
Motor2.enableOutputs();
Motor1.setSpeed(500);
Motor1.moveTo(1600);
Motor1.runToPosition();
Motor1.disableOutputs();
}
}
else{
if(klappeOffen){
timeStamp2 = millis();
if(timeStamp2-timeStamp1>=10000){
klappeOffen = false;
Motor1.enableOutputs();
Motor1.setSpeed(-300);
while(digitalRead (switchPin) == HIGH){
Motor1.runSpeed();
}
Motor1.setCurrentPosition(0);
Motor1.disableOutputs();
Motor2.disableOutputs();
}
}
}
}
// Resettet Position Futterrad ----------------------------------------------------------------
void wheelReset(){
Motor2.enableOutputs();
Motor2.moveTo(0);
Motor2.runToPosition();
Motor2.disableOutputs();
rotations = 0;
}