Coding Arduino motorsheild

Im switching my setup for my pet feeder to an arduino motorsheild so that my 12v dc motor will work properly (currently my motor doesnt have enough voltage to start sometimes, the torque is to high for just 5v) What all needs to be changed in my code in order to power the motor with the motorsheild?

#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
#include <TimeAlarms.h>
#include <Time.h>

RTC_DS1307 RTC;
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
int motorPin = 2;
int lastHour = 23;
int lastMinute = 59;

bool feedPet = false;
unsigned long feedTime = 0;
unsigned long lastPrintTime = 0;

struct FeedTime{
  int hour, minute;
};

FeedTime amFeed = {9, 30};  // i.e. 9:30am
FeedTime pmFeed = {17, 8};  // i.e. 5:30pm

void setup ()
{
  pinMode(motorPin, OUTPUT);
  Serial.begin(9600);
  lcd.begin(16, 2);
  Wire.begin();
  RTC.begin();
  /*{
    lcd.println("RTC NOT Running!");
    RTC.adjust(DateTime((__DATE__), (__TIME__)));
  }*/
}

void loop ()
{
  DateTime now = RTC.now();
  FeedTime currentTime;
  currentTime.hour = now.hour();
  currentTime.minute = now.minute();
  if((currentTime.minute != lastMinute) && (((currentTime.hour == amFeed.hour) && (currentTime.minute == amFeed.minute)) || ((currentTime.hour == pmFeed.hour) && (currentTime.minute == pmFeed.minute))))
  {
    feedTime = millis();
    feedPet = true;
    
  }
  lastMinute = currentTime.minute;
  if (feedPet)
  {
    turnFeeder();
  }
  if (millis() - lastPrintTime > 1000UL)
  {
    lcd.setCursor(0, 0);
    char nowDate[24] = "";
    sprintf(nowDate, "DATE: %02d/%02d/%d", now.month(), now.day(), now.year());
    lcd.print(nowDate);
    // display the time
    lcd.setCursor(0, 1);
    char nowTime[24] = "";
    sprintf(nowTime, "Time: %02d:%02d:%02d", now.hour(), now.minute(), now.second());
    lcd.print(nowTime);
    lastPrintTime = millis();
  }
}

void turnFeeder(void)
{
  static bool pinState = true;
  if (millis() - feedTime < 38000UL) // 38 second(s)
  {
    if (pinState)
    {
      digitalWrite(motorPin, HIGH);
      pinState = false;
    }
  }
  else
  {
    digitalWrite(motorPin, LOW);
    pinState = true;
    feedPet = false;
  }
}

What all needs to be changed in my code in order to power the motor with the motorsheild?

Nothing. Powering the motor is a hardware issue. The motor shield came with instructions. Time to read them.

actually my motorshield came with no instructions except whats written on the back explaining what it does. i have been reading online but i cant figure anything out, my code obviously does not work with the motorshield like it is. i need to power my motor at the full 12v

Then, a link to the motor shield is in order. Why would you buy something that didn't come with basic instructions?

ive already found the links online and im learing but i still dont know how to implement the functions into my own code which is what i am having trouble with

mbasile:
ive already found the links online and im learing but i still dont know how to implement the functions into my own code which is what i am having trouble with

You can share the links and get help, or you can study them yourself. Your choice.

Found this code, it seems to turn the motor forward and reverse, im currently trying to implement my rtc and my times for feeding (9:30am and 5:30pm) with this code. However, i want the motor to just turn one way (forward) and not alternate.

int lm1 = 8 ;

int lm2 = 11;

int lms = 9;

int rm1 = 12;

int rm2 = 13;

int rms = 10;

void setup()

{

pinMode(lm1,OUTPUT);

pinMode(lm2,OUTPUT);

pinMode(lms,OUTPUT);

pinMode(rm1,OUTPUT);

pinMode(rm2,OUTPUT);

pinMode(rms,OUTPUT);

}

void loop()

{

analogWrite(lms,255);

analogWrite(rms,255);

digitalWrite(lm2,LOW);

digitalWrite(rm2,LOW);

digitalWrite(lm1,HIGH);

digitalWrite(rm1,HIGH);

delay(5000);

digitalWrite(lms,LOW);

digitalWrite(rms,LOW);

delay(2000);

analogWrite(lms,200);

analogWrite(rms,200);

digitalWrite(lm1,LOW);

digitalWrite(rm1,LOW);

digitalWrite(lm2,HIGH);

digitalWrite(rm2,HIGH);

delay(5000);

}

well all my attempts and coding the rtc into the code did not work, along with getting the motor to turn at the specified time

I had to take the lcd off my setup since the motorshield uses the same pins as the lcd, the motor now spins at the correct time however, it will not turn off after the specified 10 seconds......

#include <Wire.h>
#include "RTClib.h"
#include <LiquidCrystal.h>
#include <TimeAlarms.h>
#include <Time.h>

RTC_DS1307 RTC;
//LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
//int motorPin = 2;
int lastHour = 24;
int lastMinute = 60;

bool feedPet = false;
unsigned long feedTime = 0;
unsigned long lastPrintTime = 0;

struct FeedTime {
  int hour, minute;
};

FeedTime amFeed = {9, 30};  // i.e. 9:30am
FeedTime pmFeed = {21, 31};  // i.e. 5:30pm

//sets up motor 1
int pinI1 = 8;
int pinI2 = 11;
int speedpin1 = 9;

//sets speed of motors
int speed = 255;

void setup ()
{
  //pinMode(motorPin, OUTPUT);
  Serial.begin(9600);
  //lcd.begin(16, 2);
  Wire.begin();
  RTC.begin();
  pinMode (pinI1, OUTPUT);
  pinMode (pinI2, OUTPUT);
  pinMode (speedpin1, OUTPUT);

  /*{
    lcd.println("RTC NOT Running!");
    RTC.adjust(DateTime((__DATE__), (__TIME__)));
  }*/
}

void loop ()
{
  DateTime now = RTC.now();
  FeedTime currentTime;
  currentTime.hour = now.hour();
  currentTime.minute = now.minute();
  if ((currentTime.minute != lastMinute) && (((currentTime.hour == amFeed.hour) && (currentTime.minute == amFeed.minute)) || ((currentTime.hour == pmFeed.hour) && (currentTime.minute == pmFeed.minute))))
  {
    feedTime = millis();
    feedPet = true;
  }
  lastMinute = currentTime.minute;
  if (feedPet)
  {
    turnFeeder();
  }
  if (millis() - lastPrintTime > 1000UL)
  {
    /*lcd.setCursor(0, 0);
    char nowDate[24] = "";
    sprintf(nowDate, "DATE: %02d/%02d/%d", now.month(), now.day(), now.year());
    lcd.print(nowDate);
    // display the time
    lcd.setCursor(0, 1);
    char nowTime[24] = "";
    sprintf(nowTime, "Time: %02d:%02d:%02d", now.hour(), now.minute(), now.second());
    lcd.print(nowTime);
    lastPrintTime = millis();*/
  }

  analogWrite(speedpin1, speed);
}

void turnFeeder(void)
{
  static bool pinState = true;
  if (millis() - feedTime < 1000UL) // 10 second(s)
  {
    if (pinState)
    {
      //digitalWrite(motorPin, HIGH);
      digitalWrite(pinI2, HIGH);
      pinState = false;
    }
  }
  else
  {
    //digitalWrite(motorPin, LOW);
    digitalWrite(pinI1, LOW);
    pinState = true;
    feedPet = false;
  }
}

any help?

mbasile:
any help?

Did you not see this?

PaulS:
You can share the links and get help, or you can study them yourself. Your choice.

I don't see any links.

yhese are some of the links ive been studying from a little bit today, ill try to get some more later once class is over, if it means anything my motorshield is a seeedstudio.

http://playground.arduino.cc/MotorControlShieldV3/0

  if (millis() - feedTime < 1000UL) // 10 second(s)

No, that is NOT 10 seconds.

the motor now spins at the correct time however, it will not turn off after the specified 10 seconds......

      //digitalWrite(motorPin, HIGH);
    //digitalWrite(motorPin, LOW);

I wonder why the motor doesn't do anything...

those are commented out on purpose if you look directly under them you will see the code that is actually being used.

i found the problem and have since got it all working correctly

void turnFeeder(void)
{
  static bool pinState = true;
  if (millis() - feedTime < 1000UL) // 10 second(s)
  {
    if (pinState)
    {
      //digitalWrite(motorPin, HIGH);
      digitalWrite(pinI2, HIGH);
      pinState = false;
    }
  }
  else
  {
    //digitalWrite(motorPin, LOW);
    digitalWrite(pinI1, LOW);
    pinState = true;
    feedPet = false;
  }
}