DISPLAY CHANGING LCD

hi everyone i am making a small project,, to present in the science exhibition :)

the project is plant watcher. in this i want to use a lcd display to display the voltage of the battery and then it should display weather the plant is been watered or not or weather is the plant watcher running or not.

I successfully did the first part which had only a simple moisture sensor and it used to display the status on the lcd that is, if the plat is been watered the lcd shows "plant watcher job done" and if the plant watcher is running it shows "plant watcher Running"

but now i even added a voltage sensor and now i even need to display the voltage level first and then the status of the work done by the plant watcher. but i am not able to do that , i am not getting the proper code and to work with this.

please help me with this :)

thanks in advance

You need to post your code, otherwise we can't help.

hi ,
the below code is the actual plant watcher code without the modification of the voltage sensor

/*
  Plant Watcher
  by Parth Yatin Temkar
  
  Reads a soil moisture sensor and turns on a relay that controls a water pump.
  and even gives the information on the lcd
  
  The soil moisture sensor involves a 10K resistor between pins A1 and ground,
  and a probe connected to pin A1 and another connected to +5V. These probes 
  are embedded and inch apart in the plant's soil.
  
  
 */


// Analog input pin that the soil moisture sensor is attached to
const int analogInPin = A1;  
  

// value read from the soil moisture sensor
int sensorValue = 0; 


 // if the readings from the soil sensor drop below this number, then turn on the pump
int dryValue = 760;  

#include <LiquidCrystal595.h>

LiquidCrystal595 lcd(7,8,9);


void setup() {
  
  pinMode(12, OUTPUT);
   lcd.begin(16, 2);
   //sets the lcd 
  
}
// the below code of void alertLcd is just to reduce space below in void loop
void alertLcd() {
 lcd.setCursor(0, 0);
 lcd.print("PLANT WATCHER");
 lcd.setCursor(0,1);
  lcd.print("  RUNNING  ");
} 

void alertLcd2() {
 lcd.setCursor(0, 0);
 lcd.print("PLANT WATCHER");
 lcd.setCursor(0,1);
  lcd.print("  JOB DONE ");
} 

 
 


void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogInPin);                   

  //Turns on the water pump if the soil is too dry
  //And displayes the message on lcd running
  //Increasing the delay will increase the amount of water pumped
  if(sensorValue < dryValue){
    alertLcd();
    
    digitalWrite(12, HIGH);
    delay(10000);
    digitalWrite(12, LOW);
    

  }
    else
    {
      //sends the message to lcd job done 
          alertLcd2();
          
    }
 
  //slow your roll - I mean... slow down the code a little
         delay(100);              
}

and this is the voltage sensor code

/*
* Voltmètre Arduino
*/
#include <ShiftLCD.h>
ShiftLCD lcd(2, 4, 3);
// variables for input pin
int analogInput = 1;
int ledOutput = 7;
float vout = 0.0;
float vin = 0.0;
float R1 = 50000.0; // !! resistance of R1 !!
float R2 = 4400.0; // !! resistance of R2 !!
// variable to store the value
int value = 0;
void setup() {
// declaration of pin modes
pinMode(analogInput, INPUT);
pinMode(ledOutput, OUTPUT);
lcd.begin(16, 2);
lcd.print("Vin=");
}
void loop() {
// read the value on analog input
value = analogRead(analogInput);
vout = (value * 5.0) / 1024.0;
vin = vout / (R2/(R1+R2));
if (vin < 0.13) {
vin=0.0;
}
// print result to lcd display
lcd.setCursor(4, 0);
lcd.print(vin);
lcd.print("V");
//highlight LED si inférieur a 4 volts
if (vin < 4){
digitalWrite(ledOutput, HIGH);
}
else { digitalWrite(ledOutput, LOW); }
// sleep...
delay(500);
}

and ill be combining both codes
hope u ppl understood what am going to do.

thanks in advance :slight_smile:

I suggest you copy the contents of loop() from the battery sketch into your plant sketch loop(). Delete the delay(500) from the battery code.

Copy the contents of setup() from the battery sketch into your plant sketch setup(). Delete the redundant lcd.begin.

Also copy the stuff above setup() from the battery sketch to the top of your plant sketch. Make sure different pins are assigned to the different functions: for example, your the battery code appears to define analogInput as an integer 1, but I think you probably want it to be something like

const int analogInput = A2;

Now, you need to decide how to share the LCD display between the two functions so they don't overwrite each other. I suggest using only the top row (lcd.setCursor(0, 0)) for all plant functions, and only the bottom row (lcd.setCursor(0, 1))for all battery functions.

If you try all that, and still have problems, let us know what happens and show us the new combined code.

hi, actually tylernt sir, what u have suggested ive already done that means ive already combined the code but only 80% work is been done, and am not a good programmer so am not getting the proper code to change the text on the lcd.

atleast on startup my lcd should show that " PYT'S PLANT WATCHER" then go to the next step ,, that is it should show the voltage and then status of plant watcher. but am not able to find the proper code to do so.

and thanks a lott tylernt sir. but still needs ur help

thanks in advance :)

Please post all the code of your new combined sketch?

this is the code but still its incomplete as i said!!

// variables for input pin
const int analogInPin = A1;
int sensorValue = 0; 
int dryValue = 760;  
int analogbatteryInPin = A2;
int ledOutput = 7;
int batteryvalue = 0;
int batterylowvalue = 7;
float vout = 0.0;
float vin = 0.0;
float R1 = 50000.0; // !! resistance of R1 !!
float R2 = 4400.0; // !! resistance of R2 !!

#include <LiquidCrystal595.h>

LiquidCrystal595 lcd(7,8,9);

void setup() {
// declaration of pin modes
pinMode(analogbatteryInPin, INPUT);
pinMode(ledOutput, OUTPUT);
pinMode(12, OUTPUT);
lcd.begin(16, 2);

}
void loop() {
// read the value on analog input
batteryvalue = analogRead(analogbatteryInPin);
vout = (batteryvalue * 5.0) / 1024.0;
vin = vout / (R2/(R1+R2));
if (vin < 0.13) {
vin=0.0;
}
sensorValue = analogRead(analogInPin);                   
  if(sensorValue < dryValue){
 
    digitalWrite(12, HIGH);
    delay(10000);
    digitalWrite(12, LOW);
   
  }
  
 delay(100);   
}

in this code please please please suggest me where i could add the lcd commands.

thanks in advance :slight_smile: :slight_smile: :slight_smile:

I don't see where the problem is. Add lcd.setCursor and lcd.print in the relevant places. Change the strings so that each one fits in one line rather than using both of them.

hi ppl, the below youtube link shows the exact demo of the lcd display like what i want. but not getting the exact code for that ..,.,, and in this video it shows the temp and all the other information on the display with a specific interval of time.

http://www.youtube.com/watch?v=V2GL3DIOttg

pls pls pls pls hope u all understood what i want on my lcd.

thanks in advance

Hi PYT,

Your combined code looks pretty good. TheCoolest gave you the right advice, namely to add the lcd.setCursor and lcd.print commands where needed.

Actually, I would suggest making a function:

void updateDisplay(char* message)
{
lcd.clear();
lcd.print(message);
lcd.setCursor(1,0);
lcd.print("Vin=");
lcd.print(vin);
lcd.print("V");
}

Then you could do something like

if(sensorValue < dryValue)
    {
    updateDisplay("Watering");
    digitalWrite(12, HIGH);
    delay(10000);
    digitalWrite(12, LOW);
    }
else
    {
    updateDisplay("Monitoring");
    }

…or whatever suits your fancy.

hello tylernt sir,, thanks a lottt and thanku very very much for the help :) :) :) :) :) :) :) :)

but,, can you pls explain how will the code work ????

which you have provided,,, is that in the same way which is in the video ???

thanks in advance :)

  1. Punctuation in posts is great, but multiple commas and question marks are unnecessary.
  2. In short, no, it's not the same as in the video. The video shows temperature, I don't see how that has anything to do with battery voltage and a moisture sensor?

If you want to understand how that code works, you can read the documentation of the LiquidCrystal library. You will see that lcd.clear clears the display and sets the cursor at the (0,0) position, lcd.setCursor sets the cursor at the position you need it to be at, and lcd.print prints the string\value on the screen. What is there to explain?

If you have a specific question about something, then great, but from your posts it really seems like you're asking for most of the work to be done for you. There is a lot of information on the forum and on the internet, use the search feature, try using Google as well. I'm sure you can find code samples and tutorials for almost anything you ever wanted to add to your project.

I'm guessing that you're a beginner and you may not know C or C++ well. My suggestion is to learn the basics of the C language, it's a must if you want to be able to actually do something on your own and understand code others post.

Well thanks for the replies and sorry if anyone felt bad of my posts But as beginner I think I am atleast doing average.

And again thanku very much for the replies.

I'll upload the final code and even the video of the project. After doing more modifications on it and making it better

Hi PYT, there is no problem, we're good. Sometimes it is difficult to communicate through written forums with language and cultural differences though. Please do not feel discouraged and if you have a specific problem, post your new code and we will try to help.

We look forward to seeing your project succeed. :)

thank you tylernt for ur support
soon ill post my new code.
but i think after 4 weeks delay i would be able to post the code and the project. due to examinations. :slight_smile:

once again thanks a lot tylernt.

hello everyone :slight_smile: :slight_smile: :slight_smile:
as promised i have finished with my code. but as ive added a battery sensor so i even need to charge the battery when voltage drops down
i made the code but i have some error in my code the lcd display keeps on changing showing “battery charged/charging” and even the relay keeps on switching on and off.i want it to work like whenever the battery is low it should say as charging and even turn on the relay and whenever the battery is charged it should show battery charged and turn off the relay and then change the display to “pump off and battery ok”
but it is not doing that

pls pls help me to check errors in my code i think all is good but still its not working

here is my code

const int moisturePin = A0;
int batteryPin = A1;
// Analog input pins for plant sensor and battery sensor 

int moistureValue = 0;
// value read from moisture sensor 

int batteryValue = 0;
// value read from battery sensor

int dryValue = 760;
//if the readings from soil sensor drops below this no.,then trigger pump

int lowvoltageValue = 814;
//if the readings from battery sensor drops below this no. then trigger charger 


#include <LiquidCrystal595.h> //  Add library

LiquidCrystal595 lcd (2,3,4); //Declare pins for lcd



void setup() {
  // put your setup code here, to run once:
  
  pinMode(5, OUTPUT); // relay pin to trigger pump
  pinMode(6,OUTPUT); // relay pin to trigger battery charger 
  lcd.begin(16,2); // sets the lcd 
  //Below code is to run the display at  startup
  lcd.setCursor(2,0);
  lcd.print("PYT'S PLANT");
  lcd.setCursor(0,1);
  lcd.print("MONETERINGSYSTEM");
  delay(4000);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("--Initializing--");
  lcd.setCursor(3,1);
  lcd.print("Please Wait");
  delay(5000);
 lcd.clear();
  lcd.setCursor(3,0);
  lcd.print("* SYSTEM *");
  lcd.setCursor(3,1);
  lcd.print("* ACTIVE *");
  delay(2000);

}


void battery_charging()
{
  lcd.clear();
  lcd.setCursor(2,0);
  lcd.print("--Battery--");
  lcd.setCursor(2,1);
  lcd.print("--Charging--");
  
}

void plant_watering()
{
  lcd.clear();
  lcd.setCursor(2,0);
  lcd.print("PUMP ONN");
  lcd.setCursor(2,1);
  lcd.print("BATTERY OK");
}

void battery_charged()
{
  lcd.clear();
  lcd.setCursor(2,0);
  lcd.print("--Battery--");
  lcd.setCursor(2,1);
  lcd.print("--Charged--");
}

void system_ok()
{
  lcd.clear();
  lcd.setCursor(2,0);
  lcd.print("PUMP OFF");
  lcd.setCursor(2,1);
  lcd.print("BATTERY OK");
}

void loop() {
  // read the analog values 
 moistureValue = analogRead(moisturePin);
 batteryValue = analogRead(batteryValue);

if (moistureValue < dryValue && batteryValue >= lowvoltageValue)
{
 plant_watering();
 
 digitalWrite(5,HIGH);
 delay(10000);
 digitalWrite(5,LOW);
 digitalWrite(6,LOW);
 
}

else if (batteryValue < lowvoltageValue)
{
  battery_charging();
  digitalWrite(6,HIGH);
   digitalWrite(5,LOW);
  
}

else if (batteryValue >= lowvoltageValue)
{
battery_charged();
digitalWrite(6,LOW);
digitalWrite(5,LOW);

}
 
 else 
 { 
   system_ok();
   
 }
 
 delay(150);
 
 }

thanks in advance :slight_smile:

Hi PYT your code is looking good, I like your use of functions. Well done. :slight_smile:

I think you’re going to need a bit of hysteresis in your system:

That means you need to have a “zone” between the point you start charging and the point you stop charging. For example:

int lowvoltageValue = 814;
//if the readings from battery sensor drops below this no. then enable charger 

int highvoltageValue = 864;
//if the readings from battery sensor rises above this no. then disable charger 

if (batteryValue < lowvoltageValue)
{
  battery_charging();
  digitalWrite(6,HIGH);
   digitalWrite(5,LOW);
}

else if (batteryValue > highvoltageValue)
{
battery_charged();
digitalWrite(6,LOW);
digitalWrite(5,LOW);
}

Also, depending on your battery and your charger, you may not be able accurately read the battery voltage while the battery is charging. So even with hysteresis, you may still experience trouble. If that’s the case, you will need to periodically stop charging and then wait a few seconds before checking the voltage and deciding to continue charging or not.

hello everyone
again am there with my code updated and am sure this time u all people will kill me. this time ive added automatic and manual moce in my program but its isnt working in the manner i want it to work. i reallyyy request u all people to help me with this. its really a last request from my side pls pls help me

const int moisturePin = A0;
const int batteryPin = A1;
// Analog input pins for plant sensor and battery sensor 

int moistureValue = 0;
// value read from moisture sensor 

int batteryValue = 0;
// value read from battery sensor

int dryValue = 760;
//if the readings from soil sensor drops below this no.,then trigger pump

int lowvoltageValue = 100;
//if the readings from battery sensor drops below this no. then trigger charger 

const int mannualSwitchPin = 7;
// mannual input switch pin
int mannualSwitch = 0;
// variable to store the state of the mannual switch

const int autoSwitchPin = 8;
// auto input switch pin
int autoSwitch = 0;
// variable to store the state of the auto switch

const int mannualPumpPin = 9;
int mannualPump = 0;

#include <LiquidCrystal595.h> //  Add library

LiquidCrystal595 lcd (2,3,4); //Declare pins for lcd



void setup() {
  // put your setup code here, to run once:
  
  pinMode(5, OUTPUT); // relay pin to trigger pump
  pinMode(6,OUTPUT); // relay pin to trigger battery charger 
  pinMode(mannualSwitchPin,INPUT);// mannual switchpin
  pinMode(autoSwitchPin,INPUT);// auto switchpin
  pinMode(mannualPumpPin,INPUT);
  
  lcd.begin(16,2); // sets the lcd 
  //Below code is to run the display at  startup
  lcd.setCursor(5,0);
  lcd.print("PLANT  ");
  lcd.setCursor(3,1);
  lcd.print("MONETERING");
  delay(2000);
  lcd.clear();
  lcd.setCursor(5,0);
  lcd.print("SYSTEM");
  lcd.setCursor(4,1);
  lcd.print(":) :) :)");
  delay(2000);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print(" PROJECT MADE ");
  lcd.setCursor(0,1);
  lcd.print(" BY :-");
  delay(2000);
   lcd.clear();
  lcd.setCursor(5,0);
  lcd.print(" PYT ");
  lcd.setCursor(0,1);
  lcd.print(" PARTH Y.TEMKAR ");
  delay(2000);
   lcd.clear();
  lcd.setCursor(3,0);
  lcd.print(" SWARAJ ");
  lcd.setCursor(4,1);
  lcd.print(" SONAR ");
  delay(2000);
   lcd.clear();
  lcd.setCursor(4,0);
  lcd.print(" RAHUL ");
  lcd.setCursor(5,1);
  lcd.print(" LAD ");
  delay(2000);
   lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("--Initializing--");
  lcd.setCursor(0,1);
  lcd.print("Please wait....");
  delay(5000);
 lcd.clear();
  lcd.setCursor(3,0);
  lcd.print("* SYSTEM *");
  lcd.setCursor(3,1);
  lcd.print("* ACTIVE *");
  delay(2000);
// give the system some time to calibrate and even do some advertisment of ur name :)
}


void battery_charging()
{
  lcd.clear();
  lcd.setCursor(2,0);
  lcd.print("--Battery--");
  lcd.setCursor(2,1);
  lcd.print("--Charging--");
  
}

void plant_watering()
{
  lcd.clear();
  lcd.setCursor(2,0);
  lcd.print("PUMP ONN");
  lcd.setCursor(2,1);
  lcd.print("BATTERY OK");
}

void battery_charged()
{
  lcd.clear();
  lcd.setCursor(2,0);
  lcd.print("--Battery--");
  lcd.setCursor(2,1);
  lcd.print("--Charged--");
}

void system_ok()
{
  lcd.clear();
  lcd.setCursor(2,0);
  lcd.print("PUMP OFF");
  lcd.setCursor(2,1);
  lcd.print("BATTERY OK");
}

void auto_switch()
{
  lcd.clear();
  lcd.setCursor(2,0);
  lcd.print("AUTONOMUS");
  lcd.setCursor(0,1);
  lcd.print("MODE ACTIVE");
  delay(1000);
}

void mannual_switch()
{
  lcd.clear();
  lcd.setCursor(2,0);
  lcd.print(" MANNUAL");
  lcd.setCursor(0,1);
  lcd.print("MODE ACTIVE");
  delay(1000);
}

void loop() {
  // read the analog values 
 moistureValue = analogRead(moisturePin);
 batteryValue = analogRead(batteryValue);
 mannualSwitch = digitalRead(mannualSwitchPin);
 autoSwitch = digitalRead(autoSwitchPin);
 mannualPump = digitalRead(mannualPumpPin);
 if (autoSwitch == HIGH)
 {
   auto_switch();
   

if (moistureValue < dryValue && batteryValue >= lowvoltageValue)
{
 plant_watering();
 
 digitalWrite(5,HIGH);
 digitalWrite(6,LOW);
 delay(10000);
 digitalWrite(5,LOW);
 digitalWrite(6,LOW);
 
}

else if (batteryValue < lowvoltageValue)
{
  battery_charging();
  digitalWrite(6,HIGH);
   digitalWrite(5,LOW);
   delay(10000);
   digitalWrite(6,LOW);
   digitalWrite(5,LOW);
   
   
  
}


 else 
 { 
   system_ok();
   
 }
 }
 
 if (mannualSwitch == HIGH)
 
 {
   mannual_switch();
   if (mannualPumpPin == HIGH)
   {
     digitalWrite(5,HIGH);
     delay(500);
     digitalWrite(5,LOW);
   }
   
   else
   {
     lcd.clear();
  lcd.setCursor(2,0);
  lcd.print(" MANNUAL");
  lcd.setCursor(0,1);
  lcd.print("MODE");
   }
   
 }
 
 
 delay(150);
 
 }

pls help me out
regards
and thanks in advanced

its isnt working in the manner i want it to work.

Try offering a pension scheme

i didnt understood what u want to say awol :~ :~ :~