Beam break sensor while stepper is in use

Hey! New to Arduino and the Forums so hear me out and ask for any more information you require...

I have made an automatic fish feeder for my partners marine/reef tank however there's been some speculation floating around the house that it hasn't been working :relieved_face:.

Currently it's running from Arduino mega, ChronoPi 1.0 RTC, 28BYJ-48 Stepper motor and driver.

At 7AM every morning the stepper powers an auger, which augers fish food from the hopper into the tank. I wanted to install a break sensor or distance sensor to the piped elbow into the tank to display a timestamp and duration of the break/distance change on a e-paper screen. However, when the motor is spinning everything else stops/is blocked. How do I go about this?

#include <Arduino.h>
#include <DS3231.h>
#include <Stepper.h>

//Definitions
const int feedAmount = 2000;
const String feedTime = "07:00";
String lastFedDate = "";
String lastFedTime = "";

Stepper augerMotor = Stepper(feedAmount, 8, 10, 9, 11);
DS3231 rtc(SDA, SCL);

void setup();
void loop();
void stopMotor();
void setup()
{
  // Setup Serial connection
  Serial.begin(9600);
  rtc.begin();

  // Uncommented to set the date and time
  //rtc.setDOW(MONDAY);     // Set Day-of-Week to SUNDAY
  //rtc.setTime(13, 22, 0);     // Set the time to 12:00:00 (24hr format)
  //rtc.setDate(24, 2, 2025);   // Set the date to January 1st, 2014
}

void loop()
{
  String currentTime = rtc.getTimeStr(FORMAT_SHORT);

  if (currentTime == feedTime) {
    if (lastFedDate != rtc.getDateStr(FORMAT_SHORT, FORMAT_LITTLEENDIAN, '/')) {
      augerMotor.setSpeed(10);
      augerMotor.step(feedAmount);
      lastFedDate = rtc.getDateStr(FORMAT_SHORT, FORMAT_LITTLEENDIAN, '/');
      lastFedTime = rtc.getTimeStr(FORMAT_SHORT);
      Serial.println("Feeding fish...");
      stopMotor();
    } else {
      Serial.println("Fish have already been fed.");
    }
  }

  // Send time
  Serial.println(rtc.getDateStr(FORMAT_SHORT, FORMAT_LITTLEENDIAN, '/'));
  Serial.println(rtc.getTimeStr());
  Serial.println("---------------");
  
  // Wait one second before repeating
  delay (1000);
}

void stopMotor(){
  digitalWrite(8,LOW);
  digitalWrite(9,LOW);
  digitalWrite(10,LOW);
  digitalWrite(11,LOW);
}





Cheers!

bad luck, it’s time to start again from memory.

Found it in AppData/Local/arduino/sketches/ :+1:

That's a problem with that simple stepper.h library. Use a more powerful library like my MobaTools or Accelstepper. That allows doing other tasks while the stepper is moving. MobaTools does all step creation by timer interrupts in the background. So you can do what you like while the stepper is moving ( as long as you don't disable interrupts :wink: ).