weird pump problems

i have a circuit that is supposed to:
wait 30s
turn on pump for 7s
wait 30s
and so on
but instead it turns on the pump for 1 second. these problems don't exist while i have me the arduino plugged into my computer via usb cable. It's currently being supplied by a 9V powe supply (max 800mA)

images,schematic and transistor datasheet are in the attachments

NOTE that i had popped the D2 diode because i was dumba**.


//Version 2.0

int potV       = 0;
int PWM        = 155;
int thedelay   = 7000;

const unsigned long offInterval = 1;  //1 minute
const unsigned long onInterval  = 7;  //7 seconds

//if 'true' we are watering
bool waterFlag = false;

unsigned long curtime  = 0;
unsigned long pastime  = 0;
unsigned long pastime2 = 0;
unsigned long printMillis;

//*********************************************************************************
void setup()
{
  Serial.begin(9600);
  //attachInterrupt(digitalPinToInterrupt(2), Interrupt, FALLING);
  analogWrite(3, 0);

} //END of setup()



//*********************************************************************************
void loop()
{
  //potV = analogRead(0);
  curtime = millis();

  //******************************************
  if (waterFlag == false && curtime - pastime >= offInterval*60*1000ul)
  {
    Serial.println("WATER COMMENCE!");
    Serial.println("Watering...");
    
    analogWrite(3, PWM);

    waterFlag = true;
    pastime2 = curtime;

  }

  //******************************************
  else
  {
    //every 5 seconds
    if (millis() - printMillis >= 5001)
    {
      printMillis = millis();

      Serial.println(curtime / 1000);
    }
    
  }

  //******************************************
  water();


} //END of loop()



//*********************************************************************************
void water()
{
  //******************************************
  if (waterFlag == false)
  {
    return;
  }

  //******************************************
  if (curtime - pastime2 >= onInterval*1000ul)
  {
    digitalWrite(3, LOW);
    Serial.println("Done!");

    waterFlag = false;
    pastime = curtime;

  }
  
} //END of water()



//*********************************************************************************
void Interrupt()
{
  //potV = analogRead(0);
  //timer = map(potV,0,1023,0,600);
  //Serial.print(timer);
  //Serial.println(" minutes");
  
} //END of Interrupt()



//*********************************************************************************

my theory is that i reached the transistor breakdown voltage, but i don't know how to fix it.

SS8050.pdf (60 KB)

Schematic.pdf (27.2 KB)

Or do i need to add a pulldown resistor?

another image

We are unable to check your wiring from the top of the proto board.

You need a base resistor for the transistor, try 220 Ω

That transistor is not designed to drive a motor, a logic level MOSFET is recommended.

What is the resistance of the pumps motor, use a DMM to check.

If you are using a PP3 9volt battery, these do not provide enough current for heavy motor loads.

Use a proper external 9v power supply with sufficient current output.

You need a reversed biased kickback diode across the pump motor. 1N4007 would work.

Keep your sketches clean of unused crap!
Version 3.0

//Version 3.0

const byte PWM = 155;

const unsigned long offInterval = 1 * 60 * 1000ul; //1 minute
const unsigned long onInterval  = 7 * 1000ul;      //7 seconds

//if 'true' pump is ON 
bool waterFlag = false;

unsigned long curtime  = 0;
unsigned long pastime  = 0;
unsigned long pastime2 = 0;

unsigned long printMillis;

//*********************************************************************************
void setup()
{
  Serial.begin(9600);
  Serial.println("Water Pump Sketch");
  
  //pump OFF
  analogWrite(3, 0);

} //END of setup()


//*********************************************************************************
void loop()
{
  curtime = millis();

  //******************************************
  //pump OFF timer
  if (waterFlag == false && curtime - pastime >= offInterval)
  {
    Serial.println("WATER COMMENCE!");
    Serial.println("Watering...");

    //pump ON
    analogWrite(3, PWM);

    //enable water pump ON timer, disable pump OFF timer
    waterFlag = true;
    //time the pump was turned ON
    pastime2 = curtime;

  }

  //******************************************
  //every 1 second
  if (millis() - printMillis >= 1001)
  {
    //re-initialize timer
    printMillis = millis();

    Serial.println(curtime / 1000);
  }

  //******************************************
  //handle water pump stuff
  water();


} //END of loop()


//*********************************************************************************
void water()
{
  //******************************************
  //pump ON timer
  if (waterFlag == true && curtime - pastime2 >= onInterval)
  {
    //pump OFF
    analogWrite(3, 0);
    Serial.println("Done!");

    //disable water pump ON timer, enable pump OFF timer
    waterFlag = false;
    //time the pump was turned OFF
    pastime = curtime;

  }

} //END of water()

//*********************************************************************************

hey again larryd! thanks for the advice! my circuit works as expected now :slight_smile: