Motor not running

i have some problem for my coding...
after i connect it with my circuit, the program was not function well..
the reverse motor1 and the motor2 is not running...
can anyone help me with my coding...

my program is about smart feeder. at 8.30am and 5.30 the food container will open (control by motor1 and limit switch) the the food from tank will fill the container when motor2 run about 30sec. the after a few min, the container will closed until the next feeding time...

this is my coding

//include lcd library
#include <LiquidCrystal.h>

int motor1a = 12;
int motor1b = 13;
int motor2a = 11;
int motor2b = 10;
int limit1 = A0;
int limit2 = A1;
//create object
//lcd(RS, E, D4,D5,D6,D7);
LiquidCrystal lcd(2,3,4,5,6,7);
const int backlight =13;
//const int buttonHr = 4; //digital pin used as hour adjustment input
//const int buttonMin = 4; //digital pin used as min adjustment input

int secs =0;
int secs2 = 0;
int mins = -1;
int hrs = 0;
boolean isAM = true;

int hrtimer1 = 8;
int mintimer1 = 30;

int hrtimer2 = 5;
int mintimer2 = 30;

int milliDivSecs = 1000;
int milliDivMins = 60000;
int milliDivHrs = 360000;

unsigned long prevmillis=0;

int interval = 1000;

void setup(){
pinMode(backlight, OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
pinMode(limit1,OUTPUT);
pinMode(limit2,OUTPUT);

// pinMode(buttonHr, INPUT);
// pinMode(buttonMin, INPUT);
digitalWrite(motor1a,LOW);
digitalWrite(motor1b,LOW);
digitalWrite(motor2a,LOW);
digitalWrite(motor2b,LOW);

digitalWrite(backlight, HIGH);
lcd.begin(16,2); //set number of cols and rows

//print out LCD clock duisplay
lcd.setCursor(5,0);
lcd.print("03:50:00 PM");

Serial.begin(9600);
}

void loop(){

unsigned long currmillis = millis();

if(currmillis-prevmillis > 999){
//lcd.clear();
prevmillis =currmillis;
if(secs<10){
lcd.setCursor(12,0);
lcd.print(secs);
lcd.setCursor(11,0);
lcd.print(0);
}
else{
lcd.setCursor(11,0);
lcd.print(secs);
}

//display minutes
if(secs == 0){
mins = mins+1;
updateMin();
}

//get new seconds from system time
secs = (millis()/milliDivSecs)%60; // divide by 1000 and mod by 60 gives seconds from milliseconds

if (hrs == hrtimer1 && mins == mintimer1)
{
digitalWrite(motor1a,1);
digitalWrite(motor1b,0);
while(digitalRead(limit1) == 0);
digitalWrite(motor1a,0);
digitalWrite(motor1b,0);
digitalWrite(motor2a,1);
digitalWrite(motor2b,0);
delay(30000);
digitalWrite(motor2a,0);
digitalWrite(motor2b,0);
digitalWrite(motor1a,0);
digitalWrite(motor1b,1);
while(digitalRead(limit2) == 0);
digitalWrite(motor1a,0);
digitalWrite(motor1b,0);

}
if (hrs == hrtimer2 && mins == mintimer2)
{
digitalWrite(motor1a,1);
digitalWrite(motor1b,0);
while(digitalRead(limit1) == 0);
digitalWrite(motor1a,0);
digitalWrite(motor1b,0);
digitalWrite(motor2a,1);
digitalWrite(motor2b,0);
delay(30000);
digitalWrite(motor2a,0);
digitalWrite(motor2b,0);
digitalWrite(motor1a,0);
digitalWrite(motor1b,1);
while(digitalRead(limit2) == 0);
digitalWrite(motor1a,0);
digitalWrite(motor1b,0);

}
/*
digitalWrite(motor1a,1);
digitalWrite(motor1b,0);
delay(3000);
digitalWrite(motor1a,0);
digitalWrite(motor1b,1);
delay(3000);
*/
}

}

//update min function
//calls the update am apm funciton and the update hours functions.
void updateMin(){
if(mins > 59){
hrs = hrs+1;
updateHrs(); //update hours then
if(hrs==11 && mins >59){
updateAMPM();
}
mins = 0; //reset mins

lcd.setCursor(8,0);
lcd.print("00");
}
if(mins < 10){
lcd.setCursor(9,0);
}
else{
lcd.setCursor(8,0);
}
lcd.print(mins);
}

//update hour function
void updateHrs(){
//display hours - needs fixing for am pm

if(hrs> 12){
//reset to 1
hrs = 1;
}
if(hrs< 10){
lcd.setCursor(5,0);
lcd.print(" ");
lcd.setCursor(6,0);
}
else{
lcd.setCursor(5,0);
}
lcd.print(hrs);

}

void updateAMPM(){
if(isAM){
isAM = false;
lcd.setCursor(14,0);
lcd.print("PM");
}
else{
isAM = true;
lcd.setCursor(14,0);
lcd.print("AM");
}
}

can anyone help me with my coding...

No, because you have far too much of it. Dump that improperly posted crap, and create a sketch that just makes one motor move one way. When that works, make that motor move the other way. When that works, make the other motor move each way.

Then, you can think about adding some of that stuff back in.

 if(secs<10){
      lcd.setCursor(12,0);
      lcd.print(secs);
      lcd.setCursor(11,0);
      lcd.print(0);
    }
    else{
      lcd.setCursor(11,0);
      lcd.print(secs);
    }

Much simpler:

  lcd.setCursor(11,0);
  int tens =secs/10;
  lcd.print(tens);  //print tens or a zero if none
  lcd.setCursor(12,0);
  lcd.print(secs %10);  //print units

Hi, look at http://forum.arduino.cc/index.php/topic,148850.0.html
before you do anything else. particularly about using # code and posting your sketch.

Have you got a sketch that just controls your motors and makes them do what you want..

The method to make such interactive sketches is to develop each function as separate sketches, to prove that each feature works.
Then you one by one combine the sketches to make your functioning sketch.

Trying to write it all at once only leads to problems finding errors and faults in he sketch code

Also a CAD or picture of a handdrawn circuit will help as well.

Tom......... :slight_smile:

You have to:

  • Tell us what you want to do
  • solve problems one by one (even the best programmer makes mistakes)
  • con't: isolate the code for just one task. Then test it. Should it not work, ask for help.
  • add a minimum of commets to the code