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)