Impossible bug!!

Hello don`t know how this sh.. is even possible... I am trying to figure out for almost 2 hours where is the problem. I am making pet feeder and I use to control stepper motor with RTC module and Arduino Uno. Yesterday the code worked just fine, today I only edited time when it turns the stepper and suddenly there is no "feeding on" serial message and stepper isn't moving.. I edited it back and still nothing.. Like what the f...?! There are NO ERRORS in the code, same code as yesterday.. Every component is fine nothing is shorting / broken.

#include <DS3231.h>

#include <Stepper.h>

const int stepsPerRevolution = 2050;

Stepper myStepper (stepsPerRevolution, 2, 5, 3, 4);

DS3231  rtc(SDA, SCL);
Time t;
// 1. feeding
const int OnHour = 12;
const int OnMin = 23;
const int OffHour = 12;
const int OffMin = 24;
// 2. feeding
const int OnHourr = 18;
const int OnMinn = 31;
const int OffHourr = 18;
const int OffMinn = 35;
// 3. feeding
//const int OnHour3 = X;
//const int OnMin3 = X;
//const int OffHour3 = X;
//const int OffMin3 = X;

void setup() {
 Serial.begin(115200);
 rtc.begin();
myStepper.setSpeed(14);
}

void loop() {
 
 t = rtc.getTime();
 Serial.print(t.hour);
 Serial.print(" hour ,");
 Serial.print(t.min);
 Serial.print(" minute ,");
 Serial.println("");
 delay (1000);


 if(t.hour == OnHour && t.min == OnMin){
   myStepper.step(500);
   delay(200);
   myStepper.step(-300);
   delay(200);
   myStepper.step(1000);
   delay(200);
   myStepper.step(-300);
   delay(200);
   myStepper.step(1200);
   delay(1000);
   Serial.println("Feeding on");
 
   }

   else if(t.hour == OffHour && t.min == OffMin){
     Serial.println("Feeding off");
  
   }
 
  if(t.hour == OnHourr && t.min == OnMinn){
  Serial.println("Feeding on");
   myStepper.step(500);
   delay(200);
   myStepper.step(-300);
   delay(200);
   myStepper.step(1000);
   delay(200);
   myStepper.step(-300);
   delay(200);
   myStepper.step(1200);
   delay(1000);
   }
   
   else if(t.hour == OffHourr && t.min == OffMinn){
   Serial.println("Feeding off");
     
   }
 
   
 //if(t.hour == OnHour3 && t.min == OnMin3){
   //Serial.println("Feeding on");
   //Feed (3);
  // }

   //else if(t.hour == OffHour3 && t.min == OffMin3){
     //Serial.println("Feeding off");
    
}

void Feed (int times){
for (int i; i<times; i++) {
   myStepper.step(500);
   delay(200);
   myStepper.step(-300);
   delay(200);
   myStepper.step(1000);
   delay(200);
   myStepper.step(-300);
   delay(200);
   myStepper.step(1200);
   delay(1000);
}
}

Read "How To Use This Forum"

in particular, 7. If you are posting code or error messages, use "code" tags

This is what happens when you do not

if you have a module that is not working, do not say "A GPS" or "the fingerprint sensor". Show us a link to the particular sensor, and a link to the datasheet if available

(deleted)

497489916:
There are NO ERRORS in the code, same code as yesterday.. Every component is fine nothing is shorting / broken.

That can't all be true if it's not working.

And you can have logical errors in your code that the compiler cannot detect.

...R

Is it displaying the hour and minute about every second? If that's not happening then your sketch is not running.

Yesterday the code worked just fine, today I only edited time when it turns the stepper and suddenly there is no "feeding on" serial message and stepper isn't moving.. I edited it back and still nothing.. Like what the f...?! There are NO ERRORS in the code, same code as yesterday..

how can you be sure after two edits?

this is why you make a copy of your latest code, go back to a backup and start adding your changes again.

you will be surprised by what you missed (damn those stray semi-colons)

Something has changed

Does the project use a breadboard ? If so then are all the connections sound and in the right place ? Do the wires actually connect to the pins/sockets ? Have you confused Onminn/Onmin or Offmin/Offminn variables somewhere in the program when you edited it ?

Please edit your post to add code tags ("</>" editor button).

for (int i; i<timesOops

  1. I didn´t need backup (at least I thought so) because code worked fine yesterday, ONLY thing I changed today was I edited OnHour/OnMin and OffHour/OffMin times for stepper to run.. Didn´t change anything else, used the same port, same cable everything.. literally there was no chance of something not working right. That´s why I didn´t create any backup.
  2. Time is normally displayed in serial monitor, BUT I noticed when OnHour/OnMin time should trigger if(t.hour == OnHour && t.min == OnMin) this part of the code, nothing happens and it should display "Feeding on" + turn the stepper but nothing happens..
  3. Maybe there was some kind of update at night that changed properties of Arduino IDE and now it´s not running ? I don´t know I am beginner in this..

The type of error pointed out in reply #8 can lead to random unexpected behavior. Fix that first.

It is much easier to program daily events if you use "minutes since midnight" as the time, rather than hours and minutes. Set the RTC to use 24 hour time, and use something like

minutes_past_midnight = hour*60 + minute;
if (minutes_past_midnight == 480 && dog_fed == 0) //at 8 AM
{
   feed_the_dog();
   dog_fed = 1; 
}

And you gave up after only two hours?

I remember spending 8 hours a day for 5 days straight looking for a bug in a program and discovered one BIT was not being set properly.

Please don't give up so soon.

Paul

jremington:
The type of error pointed out in reply #8 can lead to random unexpected behavior. Fix that first.

It is much easier to program daily events if you use "minutes since midnight" as the time, rather than hours and minutes.

What´s the error there please ? I am not a programmer sorry, only know this code worked for me and suddenly it doesn´t

i is uninitialised.