My Water Pump Doesnt Work

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

int lastButtonState = HIGH;
int lastButtonStateLess = HIGH;
int lastButtonStateTarget = HIGH;
int buttonState = HIGH;
int buttonStateLess = HIGH;
int buttonStateTarget = HIGH;
unsigned long lastDebounceTime;
unsigned long lastDebounceTimeLess;
unsigned long lastDebounceTimeTarget;
int debounceDelay = 50;
int count = 0;
int AA = 10; 
int AB = 6;

int moisture;
int sensorinput;
int sunlight;
float temp;

float moistLimit = 463.5; // Add by 51.5
unsigned int tempLimitMin = 18;
unsigned int tempLimitmax = 29;
float lightOneLimit = 150.0;
float lightTwoLimit = 100.0;

int changetarget = 0; // Target: 1 = Moisture 2 = Temperature Min 3 = Temperature Max

unsigned long updateTime;

LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  Serial.begin(9600);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
  pinMode(7, INPUT_PULLUP);
  pinMode(2, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(AA, OUTPUT);
  pinMode(AB, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(A2, INPUT);

  lcd.init();
  lcd.backlight();
  lcd.clear();
}

// the loop function runs over and over again forever
void loop() {
  // Moisture Code
  moisture = analogRead(A0);
  if (moisture >= moistLimit) {
    digitalWrite(2, HIGH);
    digitalWrite(AA, HIGH);
    digitalWrite(AB, LOW);
  }
  else {
    digitalWrite(2, LOW);
    digitalWrite(AA, LOW);
    digitalWrite(AB, LOW);
  }
  
  // Temperature Code (TMP36)
  sensorinput = analogRead(A1);
  float voltage = sensorinput * (5.0 / 1024.0);
  temp = (voltage - 0.5) * 100;

  if (temp > tempLimitmax || temp < tempLimitMin)
  {
    digitalWrite(12, HIGH);
  }
  else
  {
    digitalWrite(12, LOW);
  }

  //Sunlight Code
  sunlight = analogRead(A2);
  
  //DEBUGGING USE
  
  if (sunlight <= lightOneLimit) {
    digitalWrite(4, HIGH);
    
    
    if (sunlight <= lightTwoLimit) {
      digitalWrite(5, HIGH);
    }
  }
  else {
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
  } 

  // Button Code
  // Increase Button
  int pinValue = digitalRead(9);

  if (pinValue != lastButtonState)
  {
    lastDebounceTime = millis();
  }

  if ((millis() - lastDebounceTime) > debounceDelay)
  {
    if (pinValue != buttonState)
    {
      buttonState = pinValue;
      
      if (buttonState == LOW)
      {
        digitalWrite(13, HIGH);

        switch (changetarget)
        {
          case 1:
            {
              moistLimit += 51.5;
            }
            break;
          case 2:
            {
              tempLimitMin += 1;
            }
            break;
          case 3:
            {
              tempLimitmax += 1;
            }
            break;
          case 4:
            {
              lightOneLimit += 50.0;
            }
            break;
          
          case 5:
            {
              lightTwoLimit += 50.0;
            }
            break;
        }
      }

      else
      {
        digitalWrite(13, LOW);
      }
    }
  }

  lastButtonState = pinValue;

  // Decrease Button
  int pinValueLess = digitalRead(8);

  if (pinValueLess != lastButtonStateLess)
  {
    lastDebounceTimeLess = millis();
  }

  if ((millis() - lastDebounceTimeLess) > debounceDelay)
  {
    if (pinValueLess != buttonStateLess)
    {
      buttonStateLess = pinValueLess;
      
      if (buttonStateLess == LOW)
      {
        digitalWrite(13, HIGH);

        switch (changetarget)
        {
          case 1:
            {
              moistLimit -= 51.5;
            }
            break;

          case 2:
            {
              tempLimitMin -= 1;
            }
            break;

          case 3:
            {
              tempLimitmax -= 1;
            }
            break;
          
          case 4:
            {
              lightOneLimit -= 50.0;
            }
            break;
          
          case 5:
            {
              lightTwoLimit -= 50.0;
            }
            break;
        }
      }
      else
      {
        digitalWrite(13, LOW);
      }
    }
  }

  lastButtonStateLess = pinValueLess;
  
  // Change Target Button
  int pinValueTarget = digitalRead(7);

  if (pinValueTarget != lastButtonStateTarget)
  {
    lastDebounceTimeTarget = millis();
  }

  if ((millis() - lastDebounceTimeTarget) > debounceDelay)
  {
    if (pinValueTarget != buttonStateTarget)
    {
      buttonStateTarget = pinValueTarget;
      if (buttonStateTarget == LOW)
      {
        digitalWrite(13, HIGH);
        changetarget += 1;
        if (changetarget > 5)
        {
          changetarget = 0;
        }
      }
      else
      {
        digitalWrite(13, LOW);
      }
    }
  }

  lastButtonStateTarget = pinValueTarget;
  
  if (millis() - updateTime >= 500ul)
  {
    updateTime = millis();
    updateLCD();
  }
}

void updateLCD()
{
  switch (changetarget)
  {
    case 0:
    {
        lcd.setCursor(0, 0);
        lcd.print("Moist Temp Sun");
        lcd.setCursor(0, 1);
        lcd.print("                ");
        lcd.setCursor(0, 1);
        lcd.print(moisture);
        lcd.setCursor(6, 1);
        lcd.print(round(temp));
        lcd.setCursor(11, 1);
        lcd.print(sunlight);
      }
      break;
    case 1:
      {
        Serial.println(moistLimit);
        lcd.setCursor(0, 0);
        lcd.print("Mode 1          ");
        lcd.setCursor(0, 1);
        lcd.print("                ");
        lcd.setCursor(0, 1);
        lcd.print(moistLimit);
      }
      break;

    case 2:
      {
        Serial.println(tempLimitMin);
        lcd.setCursor(0, 0);
        lcd.print("Mode 2          ");
        lcd.setCursor(0, 1);
        lcd.print("                ");
        lcd.setCursor(0, 1);
        lcd.print("                ");
        lcd.setCursor(0, 1);
        lcd.print(tempLimitMin);
      }
      break;

    case 3:
      {
        Serial.println(tempLimitmax);
        lcd.setCursor(0, 0);
        lcd.print("Mode 3          ");
        lcd.setCursor(0, 1);
        lcd.print("                ");
        lcd.setCursor(0, 1);
        lcd.print(tempLimitmax);
      }
      break;
    
    case 4:
      {
        Serial.println(lightOneLimit);
        lcd.setCursor(0, 0);
        lcd.print("Mode 4          ");
        lcd.setCursor(0, 1);
        lcd.print("                ");
        lcd.setCursor(0, 1);
        lcd.print(lightOneLimit);
      }
      break;
    
    case 5:
      {
        Serial.println(lightTwoLimit);
        lcd.setCursor(0, 0);
        lcd.print("Mode 5          ");
        lcd.setCursor(0, 1);
        lcd.print("                ");
        lcd.setCursor(0, 1);
        lcd.print(lightTwoLimit);
      }
  break;
  }
}


Whenever I have pinModes for the water pump pins (aka. AA, AB) my water pump doesn't run. However, when I remove the pinModes, the pump starts working, but pin 12 led starts blinking slightly.

Describe the functions of your project.

Post a schematic, hand drawn is fast and easy.

Show all parts and how you've connected them, with attention to sources of power and how that is wired to the parts that need power.

What is pin 12 used for?

a7

You do know that you can ‘name’ the pins rather than referring to them by number.

It makes your code a lot easier to read.

@joemamaandarduino
Which Arduino are you using?

Post the complete sketch of both code-versions:

You should post the complete sketch of the code-version that makes the pump run
and
post the complete sketch of the code-version where the pump does not work

and post a schematic. It is very very very that a pump starts working if you remove

  pinMode(AA, OUTPUT);
  pinMode(AB, OUTPUT);

It is very likely that there is something wrong with the wiring.

best regards Stefan

Get the pump working with some simple code first and build from there.

Yep got the simple code. However, it still doesnt work. Im making a diagram for my project rn

const int waterPumpA = 6;
const int waterPumpB = 10;

void setup() {
  Serial.begin(9600);
  pinMode(waterPumpA, OUTPUT);
  pinMode(waterPumpB, OUTPUT);

}

void loop() {
  digitalWrite(waterPumpA, HIGH);
  digitalWrite(waterPumpB, LOW);
  delay(5000);
  digitalWrite(waterPumpA, LOW);
  digitalWrite(waterPumpB, LOW);
  delay(5000);

}

Are you driving pumpA backwards?

Circuit diagram and photos of all your setup please.

Hi, @joemamaandarduino

What model Arduino are you using?

Tom.. :grinning: :+1: :coffee: :australia:

uno r3


got what you people always wanted

For the pump and motor driver, I used a L298N and a normal pump

can you please use such a schematic

or at least add to your existing graphic which pin is what on the L298
You are loading extra work on the shoulders of other users without giving that information.
other users will have to lookup the datasheet of the L298N to find out what pin is what.

It is unlikely that you get helpful answers if you put such extraworks onto the shoulders of other users

The answers will typically be
"check if you wired the L298N to the correct pins"
"check if you connect all nescessary pins of the L1298N"

What do you think do these two hints really help?

Does the simulation work?

The L298N does not come in a 16 pin DIP.
Did you mean L293D?


is this better?

Please reverse engineer your project.
Can you please post a copy of your circuit a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Thanks.. Tom.. :grinning: :+1: :coffee: :australia:

Sorry... This is my second question in the forum...