Problems Controlling DC Motor with Pushbutton


my project marine aquarium dosing pump.
i have put code below control 2 dc motors using arduino uno, df robot motor shield 16x2 lcd rct1307 using i2c , 2 6 volt dosing pumps.
the code works ok , can control motors setting appropriate time, duration , speed.
what incorporate push button each motor turns motor on/off in between times if necessary can manually dose tank.
i have struggled problem while , totally flummoxed. can out there please assist.


code: [select]
// arduino doser using dfrobot motor shield, 16x2 lcd i2c , rtc1307

#include <wire.h>
#include "rtclib.h"
#include <liquidcrystal_i2c.h>


liquidcrystal_i2c lcd(0x27,16,2);

rtc_ds1307 rtc;
//arduino pwm speed control?
int e1 = 6;   
int m1 = 7;
int e2 = 5;                         
int m2 = 4;

void setup () {
    wire.begin();
    rtc.begin();
    lcd.init(); // initialize lcd
    lcd.backlight();
//rtc.adjust(datetime(__date__, __time__)); //include line set clock
  }

void loop () {
  byte second, minute, hour, dayofweek, dayofmonth, month, year;
    datetime = rtc.now();
lcd.clear();

lcd.setcursor(0, 0);
        lcd.print("time ");
    lcd.print(now.hour(), dec);
    lcd.print(':');
    lcd.print(now.minute(), dec);
    lcd.print(':');
    lcd.print(now.second(), dec);
    lcd.setcursor(0, 1);
        lcd.print("date ");
    lcd.print(now.day(), dec);
    lcd.print('/');
    lcd.print(now.month(), dec);
    lcd.print('/');
    lcd.print(now.year(), dec);
    delay(100);

//motor loop

if(now.hour() == 15 && now.minute() == 39 && now.second()==00){ // set time want motor1 kick in
    lcd.clear();
    lcd.setcursor(0, 0);
        lcd.print("motor 1 running");
    digitalwrite(m1,high); 
    analogwrite(e1, 175); //speed of motor
        delay(15000); //duration motor run 15000 = 15 secs
    analogwrite(e1, 0);
    digitalwrite(m1,low);
    lcd.clear();
    lcd.print("motor 1 stopped");
        delay(1000);}
    lcd.clear(); 
   
if(now.hour() == 15 && now.minute() == 39 && now.second()==30){ // set time want motor2 kick in
    lcd.setcursor(0, 1);
    lcd.print("motor 2 running");
    digitalwrite(m2,high); 
    analogwrite(e2, 175);
        delay(15000);
    analogwrite(e2, 0);
    digitalwrite(m2,low);
    lcd.clear();
    lcd.setcursor(0, 1);
    lcd.print("motor 2 stopped");
    delay(1000);
    lcd.clear();
}
}


for diehard programmers out there may see many errors coding have pulled different routines various places , combined them, whilst intended may not written in effective way.
i new hobby.
cheers
gastel

quote
i have struggled problem while , totally flummoxed.

the first step admit have problem. you've done that.
the second step admit problem is. haven't said problem is.

how switch wired?

code: [select]
  byte second, minute, hour, dayofweek, dayofmonth, month, year;
why? never use these.

the use of delay() stupid. know, second, time is. turn pump of @ right time. turn pump off @ first time.

you never read state of pin switch might attached to, can't possibly expect respect state of anything.


Arduino Forum > Using Arduino > Programming Questions > Problems Controlling DC Motor with Pushbutton


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support