arduino uses rechargeable batteries quickly

//#include <LiquidCrystal_I2C.h>

#include <Wire.h>

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

/*
*Smart Plant Watering System main module
*SmartPlantWateringSystemUsingArduinouno.ino    create on: 28/10/2018
*Copyright (C) 2007 Free Software Foundation, Inc. <arduinounomagic@gmail.com>
*
*For more detail please visit:https://www.arduinounomagic.com/2018/10/smart-plant-watering-system-using.html
*
*for more projects please visit://www.arduinounomagic.com
*/

#define WATERPUMP 13 //pump connected to pin 13
#define SENSOR  8 //soil sensor digital pin connected to pin 8
#define LDR  A0//light dependent resistor is connected to A0
#define PORTNUMBER  9600 // opens serial port, sets data rate to 9600 bps

void setup()
{
   Serial.begin(PORTNUMBER); 
   pinMode(WATERPUMP,OUTPUT); //Set pin 13 as OUTPUT pin
   pinMode(SENSOR,INPUT); //Set pin 8 as input pin, to receive data from Soil moisture sensor.
   pinMode(LDR,INPUT);
   digitalWrite(WATERPUMP,LOW);//pump should be off initallyLOW
    pinMode(6, OUTPUT);//green
  pinMode(7, OUTPUT);//red
  // pinMode(9, OUTPUT);
 


    lcd.init();
  lcd.backlight();

}

void loop() 
{ 
  
  int val = digitalRead(SENSOR); //stores the value received from Soil moisture sensor in variable val 
  int LDRValue=analogRead(LDR);//stores the value received from LDR in variable LDRValue 
  
   if(LDRValue <= 300)//400
  {
    // if its dark then doesn't matter whether moisture is low or high, pump should not be off
     Serial.print("its dark, so pump will off. LDR value is: ");
     Serial.println(LDRValue);//Print LDR value
     digitalWrite(WATERPUMP,LOW);//pump will off
     return;
lcd.setCursor(0, 0); 
  lcd.print("PUMP OFF"); 
  lcd.setCursor(0, 1);
  lcd.print("NIGHT TIME");
  digitalWrite(6, LOW); //green
digitalWrite(7, HIGH); //red
 // digitalWrite(9, HIGH);       
  }

 

 if( val == LOW)
 {
      
     Serial.print("its not dark and moisture is high so pump should turn on, LDR value is: ");
     Serial.println(LDRValue);//print LDR value
     Serial.print("\n moisture value is: ");
     Serial.println(val);//print soil moisture sensor value
     digitalWrite(WATERPUMP,LOW); //pump goes on WAS HIGH

       lcd.init();
  lcd.backlight();  

lcd.setCursor(0, 0); 
  lcd.print("PUMP IS NOW OFF"); 
  lcd.setCursor(0, 1);
  lcd.print("ITS DAYLIGHT");

    digitalWrite(6, LOW); //green
digitalWrite(7, HIGH); //red
  //digitalWrite(9, LOW);
   digitalWrite(13, HIGH); //PUMP OFF WAS LOW

     
  }
   if( val == HIGH)//HIGH
  {
      Serial.print("its not dark and moisture is low so pump will off, LDR value is: ");
      Serial.println(LDRValue);//print LDR value
      digitalWrite(WATERPUMP,HIGH);//and pump goes on WAS LOW
  
        
    lcd.setCursor(0, 0); 
  lcd.print("PUMP IS NOW ON "); 
  lcd.setCursor(0, 1);
  lcd.print("ITS DAYLIGHT");


    digitalWrite(6, HIGH); //green
digitalWrite(7, LOW); //red
  digitalWrite(13, LOW); //PUMP ON
      
  } 
  delay(4000); //Wait for few second and then continue the loop.
 }

hi
i am using this code to run a plant watering system i have added code for a ldr to turn off at night all seems to work coding wise but the batteries i am using rechargeable batteries but these seem not to last for 2 hrs but normal ones last a lot more ,ive hooked 2 9v batteries to a xhm-600 controller which is fed by a 25v solar panel which charges both of these to 18v i have a in4007 diode between positive of solar panel and in on the xhm-600 as said this harges pretty quickly ,my idea was to link these 2 batteries pos to neg and solar panel onto other poss an neg terminals and charge as one ,one battery is to power arduino and the other a 6v solenoid valve, although chaging as 18v i was going to split them one for arduino and one for valve ,why do the batteries die so quick,on my system i have a 5v lcd screen which displays information and 2 leds that light if pump on or off and a 5v relay to work the solenoid,after about half an hr the writing on the screen goes off leaving the baclight only and the sensor stops working i put a normal battery on and it all came back ,i must be doing something wrong somewhere,only been doing this stuff for couple of weeks or so and are stumped
colin

Since there is no wiring diagram nor do you say what type and size of rechargeable batteries you are using or the same info for "regular" batteries - without that info the best someone can do is guess - a hand sketch is fine

Batteries have 2 main specifications. Rated voltage (Volts) and capacity (Amp hours). We need to know both values before we can help.

What batteries? Many PP3 style rechargeable 9V batteries are actually 8.4V and contain 7 tiny NiMH cells. They have VERY low capacity. But yours may be different, you haven't said.

Steve

hi
sorry have put 3 pics on its running 9v batteries varta 200mah 2 off
colin

hi
this is where i got the code from and have merged ldr and changed it to i2c display and added 2 leds
colin

200mah is pretty low capacity. Theoretically that will run a Uno with nothing connected to it for 4 about hours. Really it will last a lot less time. All any current draw (relays, solenoid valves, LCD backlight) and that will drastically reduce the time.

What you need to do is an analysis of the current that your circuit requires. Knowing that and the amount of time that the circuit needs to run between battery charge/replacement you can specify the battery capacity required.

It sounds like you’re going to be burning a lot in the linear regulator.
But without a schematic, that’s just a guess.

hi
many thanks will see what ah batteries are available and get the best ones do you think a better value battery would work 12 hrs prob from 2000hrs to maybe 0600-0700 hrs when light again to start charging
never even gave a thought to ah of battery
colin

There is no way to answer how big a battery you need for X hours until we know the current required.

And if I may add to what TheMemberFormerlyKnownAsAWOL said. Exercise care when you power the Arduino through the Vin or the power jack. Powering through Vin or the power jack means that the Arduino and all peripherals that are on the 5V rail are powered by the onboard 5V regulator. The on board 5V regulator is not heat sinked so will supply limited current before it overheats and shuts down. The recommend max power dissipation for the regulator is 1 Watt. With 12V into the regulator the max current is about 140 mA (1W / (12V - 5V)). The Arduino uses around 50ma of that leaving less than 90mA (max) for everything else. I would use a buck converter to drop the 12V to 5V and connect that to the 5V on the Arduino, bypassing the, weak, 5V regulator.

hi
thanks for that will look into it plus the battery needed have found a 9v 1000mah one lot of difference to mine but may change to aa or 18650 batteries and feed through 5v instead of the jack
colin

4 x rechargeable NiMH AA batteries might work (eneloops or similar). Around 2000mAh and being 4.8V nominal can go straight to the 5V pin.

Steve

9V into the 5V will fry things.
9V needs to go thru the barrel connecter so the regulator can make 5V.

Or, use a switching regulator for more efficient conversion to 5V and then connect to the Power header.

Keeping relays energized will also use up a lot of capacity.