Hey everyone I could desperately use some help with this issue I am having. It only happens with some code and I am certain this is because of the system somewhere. The strange part is it only happens to the certain pump that is connected to a block of code, not even the pin. so I am certain it is because of something that is happening in the code but not the code itself. However, I can not find the issue.
The watering system has been running for almost a year with no issues until one day the nano went. Now I am unable to get it to run all the way through again, with the code. The code I am using has most things commented out just trying to debug to see if anything was causing it.
so this is what is weird. I run the code and it runs as normal and the Pump1 starts and runs. it gets to pump2 and the transistor slowly gets hot(current draw?) so I switch pins to the circuit that just worked, and it too slowly gets hot. I then unplug the arduino and swap pins and the Pump2 the did not work originally now works and Pump1 does not. One time I had something real strange happen and the pump ran during the initial soil moisture test during boot. (It blinks twice, pump started twice) but maybe this is unrelated?.. I have swapped everything except one of the pumps and have tried both of the used motors on the side that is not new. but same result. If I upload a simple sketch that turns one of the pumps, or both of the pumps on everything works fine.
#define pump1 2
#define pump2 3
void setup(){
pinMode(pump1, OUTPUT);
pinMode(pump2, OUTPUT);
}
void loop(){
digitalWrite(pump1, HIGH);
digitalWrite(pump2, HIGH);
}
with the above code, everything works fine.
Pump amp rating = 12v, 80 ma, I didnt measure it stalled as I am unsure if I have to apply 25% power or if I can apply full power and do it. but, the system has worked for so long.
Transistor - 2n2222a
Transistor Base resistor = 220 (Forget the exact math but What I got was 150 Ohm)
Led resistors = 560 Ohm, I have a bunch of these things from an LED tutorial kit
any help is greatly appreciated. Embarrassingly I have spent way way to long trying to figure this out because I cannot spend to long all at once, I have to take breaks for reasons beyond my control.
//#include <Adafruit_GFX.h>
//#include <Adafruit_SSD1306.h>//commented out for debugging
#define pumpPin 2 // Pump 1
#define pumpPin2 3 // Pump 2
#define soilPower 4 //Power for soil moisture sensor Pin 4
#define soilPower2 5 //Power for soil moisture sensor 2 Pin 5
#define ledB 6
#define ledG 7
#define soilSignal 0 //Analog soil moisture sensor pin
#define soilSignal2 1 //Analog soil moisture sensor pin
//#define OLED 9 //Power pin for the OLED screen
long val = 0, val2 = 0; //Declare values to hold soil moisture readings
byte pumpSwitch = 0, c = 0; //Values for pump and soil moisture sensor intervals
int32_t delayP = 0, timerP = 0, timerP2 = 0;//delay value, Timer 1 and 2 length
unsigned long currentMillis = millis(), previousMillis = 0,
previousMillis2 = 0; //blink without delay values
//#define OLED_RESET 8
//Adafruit_SSD1306 display(OLED_RESET);
void setup() {
Serial.begin(9600);
pinMode(soilPower, OUTPUT);
pinMode(soilPower2, OUTPUT);
pinMode(pumpPin, OUTPUT);
pinMode(pumpPin, OUTPUT);
pinMode(ledB, OUTPUT);
pinMode(ledG, OUTPUT);
pinMode(OLED, OUTPUT);
//digitalWrite(OLED, HIGH);
//display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
//display.clearDisplay();
}
void loop() {
if (c == 0) {
val = soilTest(soilPower, soilSignal, ledB);
val2 = soilTest(soilPower2, soilSignal2, ledG);
delay(50);
val = percent(val);
val2 = percent(val2);
c++;
}
//dispMoistureOLED();
//Plant 1
if (currentMillis - previousMillis >= timerP) {
previousMillis = currentMillis;
val = soilTest(soilPower, soilSignal, ledB);
delay(500);
val = percent(val);
Serial.println(val);
if (val < 50)
{
for (byte x = 0; x < 12;) {
if (pumpSwitch == 1) {
Serial.println("Turning pump 1 Off");
digitalWrite(pumpPin, LOW);
// digitalWrite(ledB, LOW);
pumpSwitch = 0;
delayP = 50000;
x++;
} else {
Serial.println("Turning pump 1 On");
digitalWrite(pumpPin, HIGH);
// digitalWrite(ledB, HIGH);
pumpSwitch = 1;
delayP = 350000;
x++;
}
delay(delayP);
}
timerP = 64800000;
pumpSwitch = 0;
delayP = 0;
Serial.println("Exiting for loop");
c = 0;
} else {
timerP = 21600000;
Serial.println("Plant moisture is fine, Will check again in 6 hours");
}
}
//Plant2
if (currentMillis - previousMillis2 >= timerP2) {
previousMillis2 = currentMillis;
val2 = soilTest(soilPower2, soilSignal2, ledG);
delay(500);
val2 = percent(val2);
Serial.println(val2);
if (val2 < 50)
{
for (byte y = 0; y < 12;) {
if (pumpSwitch == 1) {
Serial.println("Turning pump 2 Off");
digitalWrite(pumpPin2, LOW);
// digitalWrite(ledG, LOW);
pumpSwitch = 0;
delayP = 50000;
y++;
} else {
Serial.println("Turning pump 2 On");
digitalWrite(pumpPin2, HIGH);
// digitalWrite(ledG, HIGH);
pumpSwitch = 1;
delayP = 350000;
y++;
}
delay(delayP);
}
pumpSwitch = 0;
delayP = 0;
timerP2 = 64800000;
Serial.println("Exiting for loop");
c = 0;
} else {
timerP2 = 21600000;
Serial.println("Plant moisture is fine, Will check again in 6 hours");
}
}
}
//Test the soil and return the current moirsture value(Still needs to be run through percent)
int16_t soilTest(byte soilP, byte soilSig, byte led)
{
digitalWrite(soilP, HIGH);
// digitalWrite(led, HIGH);
delay(500);
int soil = analogRead(soilSig);
delay(50);
digitalWrite(soilP, LOW);
// digitalWrite(led, LOW);
return soil;
}
//Take the moisture value and turn it into a percentage
int16_t percent (int value) {
//change analog reading to percentage number
value = map(value, 0, 1025, 0, 100);
value = map(value, 0, 100, 100, 0);
return value;
}
/*
void dispMoistureOLED()
{
//Display Moisture percentages OLED
display.clearDisplay();
// display.drawBitmap(0, 10, plantBMP, 64, 20, 1);
//display.display();
delay(500);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 1);
display.println("Moisture is -");
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(44, 15);
display.println("Liz - ");
display.setCursor(92, 15);
display.println(val + String("%"));
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(44, 25);
display.println("Tes - ");
display.setCursor(82, 25);
display.println(val2 + String("%"));
display.display();
delay(2000);
}
*/