Trying to get motor to turn on at specific time

The Arduino IDE is packed with programming examples.
Work through a few, see how it goes

mbasile:
does anyone have anylinks??

Did you try looking at what I posted?

You would implement it something like this (untested) bit of code:

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

RTC_DS1307 RTC;
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
int motorPin = 9;
int lastHour = 24;
bool feedPet = false;
unsigned long feedTime = 0;
unsigned long lastPrintTime = 0;

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

  if (! RTC.isrunning()) {
    lcd.println("RTC is NOT running!");
    RTC.adjust(DateTime((__DATE__), (__TIME__)));
  }
}

void loop ()
{
  DateTime now = RTC.now();
  int currentHour = now.hour();
  if (lastHour != currentHour && (currentHour == 6 || currentHour == 18)) // if the hour just changed to 6 or 18
  {
    feedTime = millis();
    feedPet = true;
    lastHour = currentHour;
  }
  if (feedPet)
  {
    turnFeeder();
  }
  if (millis() - lastPrintTime > 1000UL)
  {
    lcd.setCursor(0, 0);
    lcd.print("DATE: ");
    lcd.print(now.month(), DEC);
    lcd.print("/");
    lcd.print(now.day(), DEC);
    lcd.print("/");
    lcd.print(now.year(), DEC);
    lastPrintTime = millis();
  }
}
void turnFeeder(void)
{
  static byte pinState = HIGH;
  if (millis() = feedTime < 6000UL) // 60 seconds
  {
    if (pinState = HIGH)
    {
      digitalWrite(motorPin, pinState);
      pinState = LOW;
    }
  }
  else
  {
    digitalWrite(motorPin, pinState);
    pinState = HIGH;
    feedPet = false;
  }
}

it may feed on startup, I'll leave it to you to figure out how to prevent that.

BullDogLowell, i looked at the code you posted and implemented it into my code almost like that last one you posted. however i got some errors that i could not figure out,

when i run your code i get this error

error: lvalue required as left operand of assignment

do you know what that means? i am currently googling to figure out how to overcome this.

mbasile:
BullDogLowell, i looked at the code you posted and implemented it into my code almost like that last one you posted. however i got some errors that i could not figure out,

when i run your code i get this error

error: lvalue required as left operand of assignment

do you know what that means? i am currently googling to figure out how to overcome this.

Maybe if you posted that code where we could see it we could tell you why you got that error.

do you know what that means?

Some things, like variables, are lvalues. That means that they can appear on the left of an assignment statement. Some things are rvalues, like function calls. That means that they can appear on the right side of an assignment statement.

Some things can be either lvalues or rvalues. A variable can appear on either side. A constant can not. A function call can not.

The line number in the error message gave you a clue as to where in the code the problem is.

if (millis() = feedTime < 6000UL) // 60 seconds

Is it this line? He did say untested didn't he?

How can you assign a value to a function like that? You can't. Maybe that was supposed to be a minus sign like in every other use of the blink without delay technique?

the error is in the void turnFeeder section

void turnFeeder(void)
{
static byte pinState = HIGH;
if (millis() = feedTime < 6000UL) // 60 seconds
{
if (pinState = HIGH)
{
digitalWrite(motorPin, pinState);
pinState = LOW;
}
}
else
{
digitalWrite(motorPin, pinState);
pinState = HIGH;
feedPet = false;
}
}

the error message points to what Delta said, its somewhere in the line

if (millis() = feedTime < 6000UL) // 60 seconds

uploaded.ino: In function 'void turnFeeder()':

uploaded.ino:56:16: error: lvalue required as left operand of assignment

Error compiling.

Ok, in my last post I told you how to fix that. It was a typo.

if (millis() = feedTime < 6000UL) // 60 seconds

changing to this

if (millis() = - feedTime < 6000UL) // 60 seconds

still has the same error

SMDH!

Do you not get that you can't assign something to a function call? Trying to assign something negative isn't going to work any better than trying to assign something positive.

You have to be willing to think a little or this is going to get real old real quick.

Go look at the Blink Without Delay example and see how that line should be written.

Or hell, look a few lines up in the code @BulldogLowell gave you and see the other place where he used that technique.

You can't assign anything to a function call. You can subtract something from the value it returns. Does that clue you in?

i figured it out as soon as i posted but it wouldnt let me edit my post since i had already posted to much in 10 minutes or whatever.

code is currently

however i set the time to 626 and 1826 to get the the motor to turn, but it did not do so at the specified time...

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

RTC_DS1307 RTC;
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
int motorPin = 9;
int lastHour = 24;
bool feedPet = false;
unsigned long feedTime = 0;
unsigned long lastPrintTime = 0;

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

if (! RTC.isrunning()) {
lcd.println("RTC NOT Running!");
RTC.adjust(DateTime((DATE), (TIME)));
}
}

void loop ()
{
DateTime now = RTC.now();
int currentHour = now.hour();
if (lastHour != currentHour && (currentHour == 626 || currentHour == 1826)) // if the hour just changed to 6 or 18
{
feedTime = millis();
feedPet = true;
lastHour = currentHour;
}
if (feedPet)
{
turnFeeder();
}
lcd.setCursor(0, 1);
lcd.print("Time: ");
lcd.print(now.hour(), DEC);
lcd.print(":");
lcd.print(now.minute(), DEC);
lcd.print(":");
lcd.print(now.second(), DEC);
lcd.print(" ");

if (millis() - lastPrintTime > 1000UL)
{
lcd.setCursor(0, 0);
lcd.print("DATE: ");
lcd.print(now.month(), DEC);
lcd.print("/");
lcd.print(now.day(), DEC);
lcd.print("/");
lcd.print(now.year(), DEC);
lastPrintTime = millis();
}
}
void turnFeeder(void)
{
static byte pinState = HIGH;
if (millis() - feedTime < 6000UL) // 60 seconds
{
if (pinState = HIGH)
{
digitalWrite(motorPin, pinState);
pinState = LOW;
}
}
else
{
digitalWrite(motorPin, pinState);
pinState = HIGH;
feedPet = false;
}
}

 if (lastHour != currentHour && (currentHour == 626 || currentHour == 1826)) // if the hour just changed to 6 or 18

OK, so on my planet there are only 24 hours in a day. Where do you live that there are more than 1826 hours in one day?

what should i enter then for the time if it was say 6:38pm? thats 1838hrs military time, thats why i put that, obviously i was wrong.

Delta_G:
OK, so on my planet there are only 24 hours in a day. Where do you live that there are more than 1826 hours in one day?

Damn, you beat me to it.That was the exact question I was going to ask.

what should i enter then for the time if it was say 6:38pm? thats 1838hrs military time, thats why i put that, obviously i was wrong.

No, it is not one thousand, eight hundred thirty eight hours.

The value from now.hour() will be between 0 and 23. The value from now.minute() will be between 0 and 59. You have to use a compound if statement.

mbasile:
what should i enter then for the time if it was say 6:38pm? thats 1838hrs military time, thats why i put that, obviously i was wrong.

Well, if the DateTime library is where you are getting the hour from, maybe you could go look at that and THINK about it. Or I guess you could just ask and make us tell you that there is also a minutes function.

@BulldogLowell's code was for your original specification that it should happen at 6 oclock. Now you want it between 6 and 7, so you're going to have to do some more thinking. His code isn't going to work if you're not looking for the point where the hour just changed. You're going to have to think about how to write this differently to look at hours and minutes.

mbasile:
what should i enter then for the time if it was say 6:38pm? thats 1838hrs military time, thats why i put that, obviously i was wrong.

So, looking at @BulldogLowell's code where he just used 6 and 18, do either of those look like he was talking about military time? Or just the hour part of it? If it were military time don't you think he would have used 600 and 1800?

Again, this is going to require some thought on your part.

should this be the format for getting the motor to turn with the time at 630pm?

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

RTC_DS1307 RTC;
LiquidCrystal lcd(8, 13, 9, 4, 5, 6, 7);
int motorPin = 9;
int lastHour = 24;
int lastMinute = 59;
bool feedPet = false;
unsigned long feedTime = 0;
unsigned long lastPrintTime = 0;

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

if (! RTC.isrunning()) {
lcd.println("RTC NOT Running!");
RTC.adjust(DateTime((DATE), (TIME)));
}
}

void loop ()
{
DateTime now = RTC.now();
int currentHour = now.hour();
int currentMinute = now.minute();
if (lastHour != currentHour && (currentHour == 6 || currentHour == 18)) // if the hour just changed to 6 or 18
if (lastMinute != currentMinute && (currentMinute == 30 || currentMinute == 30)) //if the minute is 30
{
feedTime = millis();
feedPet = true;
lastHour = currentHour;
lastMinute = currentMinute;
}
if (feedPet)
{
turnFeeder();
}
lcd.setCursor(0, 1);
lcd.print("Time: ");
lcd.print(now.hour(), DEC);
lcd.print(":");
lcd.print(now.minute(), DEC);
lcd.print(":");
lcd.print(now.second(), DEC);
lcd.print(" ");

if (millis() - lastPrintTime > 1000UL)
{
lcd.setCursor(0, 0);
lcd.print("DATE: ");
lcd.print(now.month(), DEC);
lcd.print("/");
lcd.print(now.day(), DEC);
lcd.print("/");
lcd.print(now.year(), DEC);
lastPrintTime = millis();
}
}
void turnFeeder(void)
{
static byte pinState = HIGH;
if (millis() - feedTime < 3000UL) // 30 seconds
{
if (pinState = HIGH)
{
digitalWrite(motorPin, pinState);
pinState = LOW;
}
}
else
{
digitalWrite(motorPin, pinState);
pinState = HIGH;
feedPet = false;
}
}

Yeah but I don't see any reason to test that currentMinute is 30 twice in the same if statement.

just tried to implement the code with the motor.. the only thing that happened was the seconds dissapeared from the lcd and it said "time" but no motor spin