Blynk app menu feature Self Watering Plant Pot

Hi, I am building a self watering plant project which requires the pump to automatically water the plant depending on moisture levels. We are now trying to add the Blynk app into our code which will allow us to view the values on the app. We have successfully got it to view the moisture and light levels as well as temperature.

We are now trying to add a menu feature to the app which should allow us to pick between 2 or 3 different plants (they all will have different moisture levels). We want it so that the user will pick which plant they will be using and then it will run the correct code suitable for each plant. Does anyone know what i would type in my code to successfully get this working? I have attached the code that i have so far below:

#define BLYNK_TEMPLATE_ID "TMPL5fmzE-Hpj"
#define BLYNK_TEMPLATE_NAME "Quickstart Template"
#define BLYNK_AUTH_TOKEN "xn54Yt1kZ8AX_7sozzQBeUZoEmolmOKR"
#define BLYNK_PRINT SerialUSB
#include <SPI.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>
#include <LiquidCrystal.h>

char ssid[] = "iPhone";
char pass[] = "password";

BlynkTimer timer;
BLYNK_WRITE(V0){
  digitalWrite(7, param.asInt());
}

LiquidCrystal LCD(0,1,2,3,4,5);
#define analogPin A2
#define beta 3950
#define resistance 10
int lightRead = 0;
int lightLevel;
int button=6;
int moistureSensor;
int moisturePercentage;
#define moisture A4

//const int buttonPin = 6;// Pushbutton pin;
const int redPin = 8;    // Red LED pin
const int greenPin = 10; // Green LED pin
const int bluePin = 9;   // Blue LED pin

int motorState = LOW;      // Motor state (OFF for default)

const int pump_pin = 11;

//Arrays needed for trhe unhappy face on LCD screen
byte a[8] = {B00001,B00011,B00111,B01110,B11110,B11111,B11111,B11111};
byte b[8] = {B11111,B11111,B11111,B01110,B01110,B11111,B11111,B11111};
byte c[8] = {B10000,B11000,B11100,B01110,B01111,B11111,B11111,B11111};
byte d[8] = {B11011,B11000,B11100,B11110,B01111,B00111,B00011,B00001};
byte e[8] = {B11111,B00000,B00000,B00000,B00000,B11111,B11111,B11111};
byte f[8] = {B11011,B00011,B00111,B01111,B11110,B11100,B11000,B10000};
//Arrays needed for trhe happy face on LCD screen
byte g[8] = {B00001,B00011,B00111,B01110,B11100,B11111,B11111,B11111};
byte h[8] = {B11111,B11111,B11111,B01110,B00100,B11111,B11111,B11111};
byte i[8] = {B10000,B11000,B11100,B01110,B00111,B11111,B11111,B11111};
byte j[8] = {B11111,B11111,B11110,B11100,B01101,B00111,B00011,B00001};
byte k[8] = {B11111,B00000,B00000,B11111,B11111,B11111,B11111,B11111};
byte l[8] = {B11111,B11111,B01111,B00111,B10110,B11100,B11000,B10000};
//Array for small waterdrop
byte m[8] = {B00000,B00001,B00011,B00111,B01111,B11111,B11111,B01110};

void setup()
{
  Serial.begin(9600);
  LCD.begin(16,2);
  SerialUSB.begin(115200);
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
 
  LCD.print("  Initializing  ");
  for(int b = 5; b <= 10; b++){
    LCD.setCursor(b, 1);
    LCD.print(".");
    delay(500);
  }
 
  pinMode(redPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  pinMode(bluePin, OUTPUT);
  pinMode(pump_pin, OUTPUT); //Motor  pinMode(1, INPUT); //on/off switch
  pinMode(button, INPUT);
  pinMode(A2, INPUT); //Temp
  pinMode(A3, INPUT); //light
  pinMode(A4, INPUT); //moisture
  pinMode(7, OUTPUT);
 
  //startTimeMotor = millis();  // Record the starting time
 
  //code for lcd smileyface
  LCD.createChar(0, a);
  LCD.createChar(1, b);
  LCD.createChar(2, c);
  LCD.createChar(3, d);
  LCD.createChar(4, e);
  LCD.createChar(5, f);
  //code for lcd unhappyface
  LCD.createChar(6, g);
  LCD.createChar(7, h);
  LCD.createChar(8, i);
  LCD.createChar(9, j);
  LCD.createChar(10,k);
  LCD.createChar(11,l);
  //code for lcd raindrop
  LCD.createChar(12, m);
 
}

void loop()
{
  Blynk.run();
  //tempDegrees = (((tempRead-20) * 0.488)-40);//calculates degrees
  //tempDegrees = ((tempRead*5.0/1024.0)-0.5)*100.00; 
  //read thermistor value
  long a = analogRead(analogPin);
  float tempC = beta / (log((1025.0 * 10 / a - 10) / 10) + beta / 298.0) - 300; //conversion for degrees in celsius
  Blynk.virtualWrite(V3, tempC);
  //LCD.setCursor(0, 0); // set the cursor to column 0, line 0
 // LCD.print("Temp: ");// Print a message of "Temp: "to the LCD.
  // Print a centigrade temperature to the LCD.
  //LCD.print(tempC);
  // Print the unit of the centigrade temperature to the LCD.
  //LCD.print(char(223));//print the unit" ℃ "
 // LCD.print("C");
  // (note: line 1 is the second row, since counting begins with 0):
  //delay(200); //wait for 100 milliseconds


  int moistureSensor = analogRead(moisture);
  moisturePercentage = map(moistureSensor,0,1023,100,0);
  Blynk.virtualWrite(V2, moisturePercentage);
  int lightRead = analogRead(A3);
  lightLevel = map(lightRead,1023,0,100,0);
 // lightLevel = (lightLevel - 100) * -1;
  Blynk.virtualWrite(V1, lightLevel);

  Serial.println("M =");
  Serial.println(moisturePercentage);
  Serial.println("L =");
  Serial.println(lightLevel);
  Serial.println("T =");
  Serial.println(tempC);
  delay(500);
 
  currentButtonState = digitalRead(button);
 if (currentButtonState == HIGH && lastButtonState == LOW) 
  {
    //runMotor();
    Watering();
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, HIGH);
    //motorState = !motorState;  // Toggle the motor state on button press
  }
  //controlMotor();  // Call the function to control the motor
  lastButtonState = currentButtonState;

 
//=======This initial push button if statement^^^^ is breaking the millis and loop below!====
 /*
 if (digitalRead(button) == HIGH)
  {
    runMotor();
    Watering();
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, HIGH);
  }
  */
  unsigned long currentMillisLCD = millis();
 //if both moisture and light are low (out of water)
  if (moisturePercentage >=0 && lightLevel <=45){
     
    lightandmoisturebad();
    showvaluesbad();
    //runMotor();
    Watering();
    digitalWrite(redPin, LOW);
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, HIGH);
     } 

//if just light is low
else if(lightLevel <=45){
    lightbad();
    showvaluesbad();
  }    
//if just moisture is too high (in water)
  else if(moisturePercentage <=80){
   digitalWrite(pump_pin, LOW);
   moisturebad();
   showvaluesbad();
   digitalWrite(redPin, HIGH);
   digitalWrite(greenPin, LOW);
   digitalWrite(bluePin, LOW);
   delay(1000);
  }  
  else if(moisturePercentage >=0){ //when moisture too low
   
    showvaluesbad();
    //runMotor();
    Watering();
    LCD.setCursor(0,0);
    LCD.clear();
    LCD.print("Warning,Moisture");
    LCD.setCursor(0,1);
    LCD.print("Level Too LOW");
    digitalWrite(redPin, HIGH);
    digitalWrite(greenPin, LOW);
    digitalWrite(bluePin, LOW);
    delay(1000);
    }

  else if(moisturePercentage >=0 && lightLevel >=45){
    showvaluesgood();
    lightandmoisturegood();
 }
   
}

void lightandmoisturebad()
{
  LCD.setCursor(0,0);
  LCD.clear();
  LCD.print("Warning, light &");
  LCD.setCursor(0,1);
  LCD.print("soil bad!");
  delay(1000);
 
}

void lightandmoisturegood()
{
  LCD.setCursor(0,0);
  LCD.clear();
  LCD.print("light &");
  LCD.setCursor(0,1);
  LCD.print("soil good!");
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10, HIGH);//Green RGB on
  delay(1000);
  LCD.clear();
}

void lightbad()
{
  digitalWrite(pump_pin, LOW);
  LCD.setCursor(0,0);
  LCD.clear();
  LCD.print("Warning, light");
  LCD.setCursor(0,1);
  LCD.print("level bad ");
  digitalWrite(8, HIGH); //Red RGB on
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  delay(1000);
}

void moisturebad()
{
  LCD.setCursor(0,0);
  LCD.clear();
  LCD.print("Warning, soil");
  LCD.setCursor(0,1);
  LCD.print("moisture bad ");
  digitalWrite(8, HIGH); //Red RGB on
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  delay(1000);
}

void showvaluesgood()
{
  int moistureSensor = analogRead(moisture);
  moisturePercentage = map(moistureSensor,0,1023,100,0);
  int lightRead = analogRead(A3);
  lightLevel = map(lightRead,1023,0,100,0);
  long a = analogRead(analogPin);
  float tempC = beta / (log((1025.0 * 10 / a - 10) / 10) + beta / 298.0) - 300; //conversion for degrees in celsius
  LCD.setCursor(0,0);
  LCD.clear();
  LCD.print("M=");
  LCD.print(moisturePercentage);
  LCD.setCursor(7,0);
  LCD.print("L=");
  LCD.print(lightLevel);
  LCD.setCursor(0,1);
  LCD.print("T=");
  LCD.print(tempC);
  LCD.print(char(223));
  LCD.print("C");
 
  //lcd smiley face for good values
  LCD.setCursor(13, 0);
  LCD.write(byte(0));
  LCD.setCursor(14, 0);
  LCD.write(byte(1));
  LCD.setCursor(15, 0);
  LCD.write(byte(2));
  LCD.setCursor(13, 1);
  LCD.write(byte(3));
  LCD.setCursor(14, 1);
  LCD.write(byte(4));
  LCD.setCursor(15, 1);
  LCD.write(byte(5));
  delay(1000);
  LCD.clear();
}

void showvaluesbad()
{
  int moistureSensor = analogRead(moisture);
  moisturePercentage = map(moistureSensor,0,1023,100,0);
  int lightRead = analogRead(A3);
  lightLevel = map(lightRead,1023,0,100,0);
  long a = analogRead(analogPin);
  float tempC = beta / (log((1025.0 * 10 / a - 10) / 10) + beta / 298.0) - 300; //conversion for degrees in celsius
  LCD.setCursor(0,0);
  LCD.clear();
  LCD.print("M=");
  LCD.print(moisturePercentage);
  LCD.setCursor(7,0);
  LCD.print("L=");
  LCD.print(lightLevel);
  LCD.setCursor(0,1);
  LCD.print("T=");
  LCD.print(tempC);
  LCD.print(char(223));
  LCD.print("C");
 
  //lcd unhappy face for badvalue/s
  LCD.setCursor(13, 0);
  LCD.write(byte(6));
  LCD.setCursor(14, 0);
  LCD.write(byte(7));
  LCD.setCursor(15, 0);
  LCD.write(byte(8));
  LCD.setCursor(13, 1);
  LCD.write(byte(9));
  LCD.setCursor(14, 1);
  LCD.write(byte(10));
  LCD.setCursor(15, 1);
  LCD.write(byte(11));
  delay(1500);
  //LCD.clear();
}


void Watering()
{
  LCD.setCursor(0,0);
  LCD.clear();
  LCD.print("Watering: ");
  digitalWrite(pump_pin, HIGH);
  LCD.setCursor(11, 0);
  LCD.write(byte(12));
  LCD.setCursor(10, 1);
  LCD.write(byte(12));
  LCD.setCursor(13, 0);
  LCD.write(byte(12));
  LCD.setCursor(12, 1);
  LCD.write(byte(12));
  LCD.setCursor(15, 0);
  LCD.write(byte(12));
  LCD.setCursor(14, 1);
  LCD.write(byte(12));
  digitalWrite(8, LOW); 
  digitalWrite(9, HIGH);
  digitalWrite(10, LOW);
  delay(5000);
  digitalWrite(pump_pin, LOW);

I moved your topic to an appropriate forum category @meganhamilton88.

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.