Water pump device help needed

Hi,

I’m new to Arduino and I need some help with my school project. My project consists of 2 pumps that are connected to the Arduino. 3 Buttons control an LCD display (the first button is left, the second is enter and the third is right). If you enter “on” for water on the LCD display, then the pump will turn on. I used a code I got off online that was originally meant for an led and edited it to accommodate for my pump. Pin 9 was originally connected to an led but I switched it out with a pump. The first pump works, however, now I need to get my second pump to work, which on the LCD and code is displayed as “mist”. The second pump is connected to pin 13. Any ideas on how to do this? I also would like to have another option for both pumps where if you enter “1min” or “5min” the device would turn on every 1 min or 5 min.

Below is the code and I also attached a schematic of my project so far.

Any help and advice are appreciated. Thank you.

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2); // ARDUINO UNO
byte buttons[] = {6,7,8}; //10 for additional pin
const byte nrButtons = 3; // change to 4 if additional button added
int menusize = 11;
String menu[] = {
  "Menu",                   //0
  "Menu>WATER",               //1
  "Menu>WATER>Off",           //2
  "Menu>WATER>On",            //3
  "Menu>WATER>1 min",          //4
  "Menu>WATER>5 min",         //5
  "Menu>Mist",          //6
  "Menu>Mister>Off",          //7  
  "Menu>Mister>On",          //8
  "Menu>Mister>1 min"           //9
  "Menu>Mister>5 min"        //10
};

int t;
byte pressedButton, currentPos,currentPosParent, possiblePos[20], possiblePosCount, possiblePosScroll = 0;
String parent = "";

int LCDtoggle = 0;
unsigned long timer = (millis() / 10);
int ledMode = 0;

void updateMenu () {
  possiblePosCount = 0;
  while (possiblePosCount == 0) {
    
    for (t = 1; t < menusize;t++) {
      if (mid(menu[t],1,inStrRev(menu[t],">")-1).equals(menu[currentPos])) {
        possiblePos[possiblePosCount]  =  t;
        possiblePosCount = possiblePosCount + 1;
      }
    }
    
    //find the current parent for the current menu
    parent = mid(menu[currentPos],1,inStrRev(menu[currentPos],">")-1);
    currentPosParent = 0;
    for (t = 0; t < menusize; t++) {
       if (parent == menu[t]) {currentPosParent = t;}
    }

    // reached the end of the Menu line
    if (possiblePosCount == 0) {
      //Menu Option Items
      switch (currentPos) {
        case 2:
        case 3:
        case 6: //Toggle
          if (mid(menu[currentPos],len(menu[currentPos]),1) == "*") {
            menu[currentPos] = mid(menu[currentPos],1,len(menu[currentPos])-1);
          } else {
            menu[currentPos] = menu[currentPos] + "*";    
          }
          
        break;
      }

      //Set Variables
      switch (currentPos) {
        case 2:
          ledMode = 0;
        break;
        case 3:
          ledMode = 1;
        break;
        case 6:
          LCDtoggle = abs(LCDtoggle - 1);
          digitalWrite(13,LCDtoggle);
        break;
      }


      // go to the parent
      currentPos = currentPosParent;
    }
  }
    lcd.clear();
    lcd.setCursor(0,0); lcd.print(mid(menu[currentPos],inStrRev(menu[currentPos],">")+1,len(menu[currentPos])-inStrRev(menu[currentPos],">")));
    lcd.setCursor(0,1); lcd.print(mid(menu[possiblePos[possiblePosScroll]],inStrRev(menu[possiblePos[possiblePosScroll]],">")+1,len(menu[possiblePos[possiblePosScroll]])-inStrRev(menu[possiblePos[possiblePosScroll]],">")));

}

// Look for a button press
byte checkButtonPress() {
  byte bP = 0;
  byte rBp = 0;
  for (t = 0; t<nrButtons;t++) {
    if (digitalRead(buttons[t]) == 0) {bP = (t + 1);}
  }
  rBp = bP;
  while (bP != 0) { // wait while the button is still down
    bP = 0;
    for (t = 0; t<nrButtons;t++) {
      if (digitalRead(buttons[t]) == 0) {bP = (t + 1);}
    }
  }
  return rBp;
}



void setup() {
  
  lcd.begin(16,2); 
  lcd.clear();
  
  for (t=0;t<nrButtons;t++) {
    pinMode(buttons[t],INPUT_PULLUP); 
  }
   
  pinMode(9,OUTPUT);

  lcd.setCursor(0,0); lcd.print("HELLO");
  delay(1000);
  updateMenu();

}

void loop() {

  
  switch (ledMode) {
    case 0:
      analogWrite(9, 0);
    break;
    case 1:
      analogWrite(9, 255);
    break;
        }

  pressedButton = checkButtonPress();
  if (pressedButton !=0) {
    switch (pressedButton) {
      case 1:
          possiblePosScroll = (possiblePosScroll + 1) % possiblePosCount; // Scroll
      break;
      // If I wanted a 4 button controll of the menu
      //case 4:
        //  possiblePosScroll = (possiblePosScroll + possiblePosCount - 1) % possiblePosCount; // Scroll
      //break;
      case 2:
        currentPos = possiblePos[possiblePosScroll]; //Okay
      break;
      case 3:
        currentPos = currentPosParent; //Back
        possiblePosScroll = 0;
      break;
    }
    updateMenu();
  }
}

String mid(String str, int start, int len) {
   int t = 0;
   String u = ""; 
   for (t = 0; t < len;t++) {
    u = u + str.charAt(t+start-1);
   }
   return u;
}

int inStrRev(String str,String chr) {
  int t = str.length()-1;
  int u = 0;
   while (t>-1) {
    if (str.charAt(t)==chr.charAt(0)) {
      u = t+1;t = -1;
    }
    t = t - 1;
   }
  return u;
}

int len(String str) {
  return str.length();
}

Thanks for posting your code properly!

Sorry, but there is hardly anything uglier or more useless than a Fritzing diagram. They are always confusing and usually wrong or at least misleading.

I can't make much sense of yours, and wonder if you really are trying to use 9V smoke alarm batteries to power the pumps. What are the black things with three legs? There are at least 10,000 components (MOSFET, NPN, PNP transistors, voltage regulators, triacs, etc.) that have that basic shape.

Please take the time to sketch out a readable schematic (pencil and paper with block components is fine), and post a picture or scan of that instead. It is absolutely critical that you properly represent ALL the components, by type, orientation and connections, associated with pump control.

https://learn.sparkfun.com/tutorials/how-to-read-a-schematic

alannie39:
The first pump works, however, now I need to get my second pump to work, which on the LCD and code is displayed as "mist". The second pump is connected to pin 13. Any ideas on how to do this?

I'd say: the same way as the first pump is connected and controlled.

So how far have you got with that second pump? Can you control it at all? Is it the display part that is the issue? Or something else?

The second pump does not work yet and I'm not too sure where to start with it.

If I'm guessing correctly from your Fritzy, the basic wiring for both pumps should follow this general schematic. See if you can produce a similar drawing for your setup, and we can move forward.

Make sure that your motor power supply can handle both pumps, that the Arduino is powered separately, and all the grounds are connected together.